Prerequisites
- PostgreSQL running locally or on a hosted provider
- Node.js 18+ and npm installed
- Backend dependencies installed (
npm installinside thebackend/directory)
Setup steps
Set DATABASE_URL in backend/.env
Create a Replace
.env file in the backend/ directory with your connection string:backend/.env
user, password, and localhost:5432 with your actual PostgreSQL credentials and host.Generate the Prisma client
Run this command from the
backend/ directory to generate the type-safe Prisma client:Run migrations
Apply the schema to your database:This creates all tables defined in
schema.prisma and tracks migration history.Prisma schema
The full schema is located atbackend/prisma/schema.prisma:
backend/prisma/schema.prisma
Data models
Tenant
Tenant
Represents a business or organization using Inventory Pro. Every other model belongs to a tenant via a
tenantId foreign key. Tenants are created automatically when a user registers. Has one-to-many relations to User, Product, Service, Customer, Inventory, and StockMovement.User
User
An individual who can log in to Inventory Pro. Each user belongs to exactly one tenant. Stores a hashed password, display name, email (unique globally), and a
role field (defaults to "user"). Used for authentication and authorization.Product
Product
A physical item tracked in inventory. Stores a name, SKU, and price. Each product belongs to one tenant and has an optional one-to-one
Inventory record and zero or more StockMovement records.Service
Service
A non-physical offering (e.g., installation, maintenance). Stores a name, optional description, and price. Belongs to one tenant but has no inventory tracking — services are not stocked.
Customer
Customer
A customer record associated with a tenant. Stores name, email, and optional phone and address fields. Used for associating sales and stock movements with customers.
Inventory
Inventory
Tracks the current stock level for a single product. Has a one-to-one relationship with
Product. Stores quantity (current stock), minStock (reorder threshold, default 10), and maxStock (capacity ceiling, default 1000).StockMovement
StockMovement
An immutable log entry recording a quantity change for a product. The
type field is either IN (stock received) or OUT (stock dispatched). Includes an optional reason for audit purposes. Belongs to both a product and a tenant.All models use
onDelete: Cascade on the tenant relation. Deleting a tenant permanently removes all associated users, products, services, customers, inventory records, and stock movements.Available Prisma scripts
| Script | Command | Description |
|---|---|---|
prisma:generate | prisma generate | Generates the Prisma client from the schema |
prisma:migrate | prisma migrate dev | Applies pending migrations and creates new ones if the schema has changed |
prisma:seed | ts-node src/prisma/seed.ts | Populates the database with sample data |
backend/ directory.