Overview
The Juadah API uses PostgreSQL as its database with Prisma ORM for type-safe database access. The schema defines the core entities for the e-commerce platform including users, products, orders, addresses, and ratings.Database Configuration
The database connection is configured inprisma/schema.prisma:
The schema uses both
DATABASE_URL for connection pooling and DIRECT_URL for direct database connections (useful for migrations).Models
Users
Stores user account information including authentication details and email verification.Primary key, auto-incremented user identifier
User’s full name
Unique email address for authentication
Hashed password (using bcrypt)
JWT refresh token for session management
Email verification status
6-character verification code sent to user’s email
User role (ADMIN or USER)
- One-to-many with
ratings- users can rate multiple products - One-to-many with
orders- users can place multiple orders - One-to-many with
adresses- users can have multiple delivery addresses
Products
Stores product catalog information.Primary key, auto-incremented product identifier
Product name
Product description
Product price
JSON array of product image URLs (stored in Cloudinary)
- One-to-many with
ratings- products can have multiple ratings - One-to-many with
orders- products can be in multiple orders
Ratings
Stores product ratings and reviews from users.Foreign key to users table
Foreign key to products table
Star rating (typically 1-5)
Review message from the user
This model uses a composite primary key of
[id_user, id_product], meaning a user can only rate a specific product once.- Many-to-one with
products- each rating belongs to one product - Many-to-one with
users- each rating belongs to one user
Addresses
Stores delivery addresses for users.Primary key, auto-incremented address identifier
Province name
City name
Subdistrict name
Village name
6-character postal code
Complete address details
Foreign key to users table
- Many-to-one with
users- each address belongs to one user - One-to-many with
orders- address can be used for multiple orders
Orders
Stores order transactions and payment information.Primary key, unique order identifier
Payment gateway transaction ID (from Midtrans)
Foreign key to users table
Foreign key to products table
Quantity of products purchased
Total price (amount × product price)
Current status of the payment transaction
Order creation timestamp (Unix timestamp)
Order completion timestamp (Unix timestamp)
Payment method used
Foreign key to adresses table for delivery location
- Many-to-one with
users- each order belongs to one user - Many-to-one with
products- each order is for one product - Many-to-one with
adresses- each order has one delivery address
Enums
Role
Defines user permission levels.Administrator with full access
Regular user with standard permissions
Transaction_Status
Defines payment transaction states (from Midtrans payment gateway).| Status | Description |
|---|---|
capture | Payment captured but not yet settled |
settlement | Payment successfully completed |
pending | Payment awaiting completion |
deny | Payment denied by payment gateway |
cancel | Payment cancelled by user or system |
expire | Payment expired before completion |
failure | Payment failed |
refund | Full refund issued |
partial_refund | Partial refund issued |
authorize | Payment authorized but not captured |
These statuses correspond to Midtrans payment gateway transaction states. See the Midtrans documentation for more details.
Entity Relationship Diagram
The schema follows this relationship structure:Key Relationships
-
Users can have multiple:
- Ratings
- Orders
- Addresses
-
Products can have multiple:
- Ratings
- Orders
-
Orders reference:
- One user
- One product
- One delivery address
-
Ratings have a composite key:
- One user can rate one product only once
- Combination of
id_userandid_productis unique
Database Provider
The schema uses PostgreSQL with specific configuration:This enum suggests the database may be deployed on CockroachDB (PostgreSQL-compatible) in the GCP Asia Southeast 1 region.
Next Steps
Migrations
Learn how to run and manage database migrations
API Endpoints
Explore the API endpoints that interact with these models