docs(project): establish project specification and domain model
- Add initial Software Requirements Specification - Redesign API around customers, sales and payments - Update database domain model - Refine project architecture documentation - Rewrite README to reflect product goals - Add documentation index - Mark project initialization tasks as completed
This commit is contained in:
1 parent
85d2b00c3d
commit
f9144064f0
6 files changed
+501
-68
No files matched your search
+77
-22
@@ -1,35 +1,90 @@
|
|||||||
# BiteTrack Backend v2
|
# BiteTrack Backend v2
|
||||||
|
|
||||||
A production-ready, high-performance REST API built with FastAPI and PostgreSQL, serving as the modernized, rebooted backend for the BiteTrack inventory and order system.
|
BiteTrack Backend v2 is a REST API designed for small food businesses that manage perishable inventory.
|
||||||
|
|
||||||
## Features
|
The system centralizes customer management, inventory, sales, outstanding payments, inventory losses, and operational reporting into a unified platform, replacing fragmented spreadsheet-based workflows.
|
||||||
- **User Authentication & RBAC:** Secure user registration, password hashing (bcrypt), token-based login (OAuth2 + JWT), refresh token rotation via HttpOnly cookies, and strict Role-Based Access Control (Admin, Staff, Customer).
|
|
||||||
- **Relational Inventory Schema:** Modular schemas handling Categories, Products, and Orders with ACID transactional safety during stock decrements.
|
Its goal is to simplify daily operations while preserving historical business data that helps owners make better production and purchasing decisions.
|
||||||
- **Search, Filtering, and Pagination:** Limit-offset list query parameters, category filtering, and text-based SKU/name search.
|
|
||||||
- **Robust Integration Testing:** Over 80% test coverage using pytest with a containerized test database.
|
---
|
||||||
- **Deployment-Ready:** Multi-stage production Docker image configuration and automated CI actions via GitHub Actions.
|
|
||||||
|
## Project Docs Index
|
||||||
|
|
||||||
|
[README](./README.md) \[this documment\] → What is BiteTrack?
|
||||||
|
|
||||||
|
[SRS](./SRS.md) → Software Requirement Specification: What must BiteTrack do?
|
||||||
|
|
||||||
|
[Database](./database.md) → How is the business represented?
|
||||||
|
|
||||||
|
[API Design](./api-design.md) → How is the functionality exposed?
|
||||||
|
|
||||||
|
[Architecture](architecture.md) → How is the software organized internally?
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Core Features
|
||||||
|
|
||||||
|
### Authentication & Authorization
|
||||||
|
- Secure user registration and authentication
|
||||||
|
- Role-Based Access Control (Administrator, Staff)
|
||||||
|
|
||||||
|
### Customer Management
|
||||||
|
- Customer directory
|
||||||
|
- Outstanding balance tracking
|
||||||
|
- Payment history
|
||||||
|
|
||||||
|
### Inventory Management
|
||||||
|
- Product catalog
|
||||||
|
- Categories
|
||||||
|
- Stock level management
|
||||||
|
- Inventory adjustments
|
||||||
|
- Inventory loss registration
|
||||||
|
|
||||||
|
### Sales
|
||||||
|
- Sales registration
|
||||||
|
- Payment status
|
||||||
|
- Customer association
|
||||||
|
- Automatic inventory updates
|
||||||
|
|
||||||
|
### Reporting
|
||||||
|
- Sales history
|
||||||
|
- Inventory loss history
|
||||||
|
- Customer balances
|
||||||
|
- Product performance
|
||||||
|
- Operational analytics
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Tech Stack
|
## Tech Stack
|
||||||
- **Language:** Python
|
|
||||||
- **Framework:** FastAPI
|
- Python
|
||||||
- **Database:** PostgreSQL
|
- FastAPI
|
||||||
- **ORM:** SQLAlchemy (Async)
|
- SQLAlchemy (Async)
|
||||||
- **Migrations:** Alembic
|
- PostgreSQL
|
||||||
- **Testing:** pytest
|
- Alembic
|
||||||
- **Containerization:** Docker & Docker Compose
|
- pytest
|
||||||
- **Linting & Formatting:** Ruff
|
- Docker
|
||||||
|
- Ruff
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
- Docker & Docker Compose
|
|
||||||
- Python 3.12+ (if running locally without Docker)
|
|
||||||
- `uv` (Fast Python package installer and resolver)
|
|
||||||
|
|
||||||
### Installation
|
- Docker
|
||||||
1. Clone the repository.
|
- Docker Compose
|
||||||
2. Spin up the application stack:
|
|
||||||
|
### Run
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker compose up --build
|
docker compose up --build
|
||||||
```
|
```
|
||||||
3. Access the interactive OpenAPI docs at `http://localhost:8000/docs`.
|
|
||||||
|
Interactive documentation:
|
||||||
|
|
||||||
|
```
|
||||||
|
http://localhost:8000/docs
|
||||||
|
```
|
||||||
|
|
||||||
+253
@@ -0,0 +1,253 @@
|
|||||||
|
# BiteTrack v2 — Software Requirements Specification (SRS)
|
||||||
|
|
||||||
|
Version: 0.1 (Draft)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 1. Purpose
|
||||||
|
|
||||||
|
BiteTrack is an operational management system designed for small food businesses producing and selling perishable products.
|
||||||
|
|
||||||
|
The system centralizes inventory management, customer management, sales, payment tracking, inventory loss registration, and operational reporting into a unified workflow.
|
||||||
|
|
||||||
|
Its objective is to reduce operational overhead while preserving historical business information that supports better production and inventory decisions.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 2. Scope
|
||||||
|
|
||||||
|
The system shall provide functionality for:
|
||||||
|
|
||||||
|
- User authentication
|
||||||
|
- User authorization
|
||||||
|
- Customer management
|
||||||
|
- Product catalog management
|
||||||
|
- Category management
|
||||||
|
- Inventory management
|
||||||
|
- Sales registration
|
||||||
|
- Payment tracking
|
||||||
|
- Inventory loss registration
|
||||||
|
- Business reporting
|
||||||
|
|
||||||
|
The current version does not attempt to replace accounting or ERP software.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 3. Stakeholders
|
||||||
|
|
||||||
|
- Business Owner
|
||||||
|
- Administrator
|
||||||
|
- Staff Member
|
||||||
|
|
||||||
|
Future versions may include customer-facing functionality.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 4. Business Problem
|
||||||
|
|
||||||
|
Small food businesses frequently rely on multiple spreadsheets to independently manage:
|
||||||
|
|
||||||
|
- Customers
|
||||||
|
- Inventory
|
||||||
|
- Sales
|
||||||
|
- Outstanding payments
|
||||||
|
- Inventory waste
|
||||||
|
- Business reports
|
||||||
|
|
||||||
|
This fragmentation makes it difficult to answer questions such as:
|
||||||
|
|
||||||
|
- Which customers still owe money?
|
||||||
|
- Which products generate the most waste?
|
||||||
|
- How much inventory expires every week?
|
||||||
|
- Which products are most profitable?
|
||||||
|
- How much inventory should be produced tomorrow?
|
||||||
|
|
||||||
|
BiteTrack consolidates these operational workflows into a single system.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 5. Functional Requirements
|
||||||
|
|
||||||
|
## 5.1 Identity & Access
|
||||||
|
|
||||||
|
FR-001
|
||||||
|
The system shall allow administrators to register users.
|
||||||
|
|
||||||
|
FR-002
|
||||||
|
The system shall authenticate registered users.
|
||||||
|
|
||||||
|
FR-003
|
||||||
|
The system shall enforce role-based authorization.
|
||||||
|
|
||||||
|
FR-004
|
||||||
|
The system shall allow administrators to activate or deactivate user accounts.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5.2 Customer Management
|
||||||
|
|
||||||
|
FR-010
|
||||||
|
The system shall maintain a customer directory.
|
||||||
|
|
||||||
|
FR-011
|
||||||
|
A customer record shall contain:
|
||||||
|
|
||||||
|
- Full name
|
||||||
|
- Phone number
|
||||||
|
- Optional email address
|
||||||
|
|
||||||
|
FR-012
|
||||||
|
The system shall associate sales with customers.
|
||||||
|
|
||||||
|
FR-013
|
||||||
|
The system shall determine each customer's outstanding balance from recorded sales and payments.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5.3 Product Management
|
||||||
|
|
||||||
|
FR-020
|
||||||
|
The system shall manage product categories.
|
||||||
|
|
||||||
|
FR-021
|
||||||
|
The system shall create, update and archive products.
|
||||||
|
|
||||||
|
FR-022
|
||||||
|
Products shall define a default shelf life.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5.4 Inventory
|
||||||
|
|
||||||
|
FR-030
|
||||||
|
The system shall maintain current inventory levels.
|
||||||
|
|
||||||
|
FR-031
|
||||||
|
The system shall automatically decrease inventory when sales are recorded.
|
||||||
|
|
||||||
|
FR-032
|
||||||
|
The system shall allow manual registration of inventory losses.
|
||||||
|
|
||||||
|
FR-033
|
||||||
|
Inventory losses shall record a reason.
|
||||||
|
|
||||||
|
Examples include:
|
||||||
|
|
||||||
|
- Expired
|
||||||
|
- Damaged
|
||||||
|
- Quality issue
|
||||||
|
- Manual adjustment
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5.5 Sales
|
||||||
|
|
||||||
|
FR-040
|
||||||
|
The system shall register product sales.
|
||||||
|
|
||||||
|
FR-041
|
||||||
|
A sale shall contain one or more sale items.
|
||||||
|
|
||||||
|
FR-042
|
||||||
|
The system shall calculate sale totals automatically.
|
||||||
|
|
||||||
|
FR-043
|
||||||
|
The system shall associate every sale with the staff member who created it.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5.6 Payments
|
||||||
|
|
||||||
|
FR-050
|
||||||
|
The system shall record payments associated with a sale.
|
||||||
|
|
||||||
|
FR-051
|
||||||
|
A sale may receive multiple payments.
|
||||||
|
|
||||||
|
FR-052
|
||||||
|
The system shall calculate outstanding balances from recorded payments.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5.7 Reporting
|
||||||
|
|
||||||
|
FR-060
|
||||||
|
Display current inventory.
|
||||||
|
|
||||||
|
FR-061
|
||||||
|
Display inventory loss history.
|
||||||
|
|
||||||
|
FR-062
|
||||||
|
Display customer balances.
|
||||||
|
|
||||||
|
FR-063
|
||||||
|
Display sales history.
|
||||||
|
|
||||||
|
FR-064
|
||||||
|
Display product performance.
|
||||||
|
|
||||||
|
FR-065
|
||||||
|
Provide historical operational reports.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 6. Non-functional Requirements
|
||||||
|
|
||||||
|
## Performance
|
||||||
|
|
||||||
|
The system shall provide responsive interaction during normal business operations.
|
||||||
|
|
||||||
|
## Security
|
||||||
|
|
||||||
|
Passwords shall be stored using an adaptive cryptographic password hashing algorithm.
|
||||||
|
|
||||||
|
The system shall authenticate users before granting access to protected resources.
|
||||||
|
|
||||||
|
Role-based authorization shall restrict access to administrative functionality.
|
||||||
|
|
||||||
|
## Reliability
|
||||||
|
|
||||||
|
Operational data shall remain persistent and recoverable after unexpected failures.
|
||||||
|
|
||||||
|
## Maintainability
|
||||||
|
|
||||||
|
The software architecture shall support incremental feature additions with minimal impact on existing functionality.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 7. Constraints
|
||||||
|
|
||||||
|
- Backend-first development.
|
||||||
|
- Single business deployment.
|
||||||
|
- Lightweight deployment on commodity hardware.
|
||||||
|
- Designed primarily for small food businesses.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 8. Assumptions
|
||||||
|
|
||||||
|
- One deployment corresponds to one business.
|
||||||
|
- Inventory quantities are entered manually.
|
||||||
|
- Products belong to one category.
|
||||||
|
- Staff members authenticate before using the system.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 9. Out of Scope
|
||||||
|
|
||||||
|
The current version does not include:
|
||||||
|
|
||||||
|
- Accounting
|
||||||
|
- Supplier management
|
||||||
|
- Payment gateway integration
|
||||||
|
- Online ordering
|
||||||
|
- Multi-tenant deployments
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 10. Planned Future Features
|
||||||
|
|
||||||
|
- Bootstrap initialization using a one-time deployment key.
|
||||||
|
- QR-based administrator recovery.
|
||||||
|
- Automatic inventory expiration.
|
||||||
|
- Production recommendations based on historical sales and inventory losses.
|
||||||
+2
-2
@@ -3,8 +3,8 @@
|
|||||||
This is the operational TODO list for your flagship backend project.
|
This is the operational TODO list for your flagship backend project.
|
||||||
|
|
||||||
## Currently Doing
|
## Currently Doing
|
||||||
- [ ] Initialize repository with `uv`
|
- [x] Initialize repository with `uv`
|
||||||
- [ ] Set up Docker Compose for local development (PostgreSQL & FastAPI)
|
- [x] Set up Docker Compose for local development (PostgreSQL & FastAPI)
|
||||||
|
|
||||||
## To Do (Backlog)
|
## To Do (Backlog)
|
||||||
- [ ] Implement Users CRUD
|
- [ ] Implement Users CRUD
|
||||||
|
|||||||
+65
-20
@@ -1,33 +1,78 @@
|
|||||||
# BiteTrack API Design
|
# BiteTrack API Design
|
||||||
|
|
||||||
## Endpoints Specification
|
## Endpoint Specification
|
||||||
|
|
||||||
### Authentication
|
---
|
||||||
- `POST /auth/register` - Create user.
|
|
||||||
- `POST /auth/token` - Authenticate user & issue JWT Access & Refresh Tokens.
|
|
||||||
- `POST /auth/refresh` - Rotate access tokens using HttpOnly Refresh Cookie.
|
|
||||||
|
|
||||||
### Users & Profiles
|
## Authentication
|
||||||
- `GET /users/me` - Fetch own profile.
|
|
||||||
- `PATCH /users/me` - Update own profile.
|
- `POST /auth/register` - Register a new user.
|
||||||
- `GET /users` - List all users (Admin only).
|
- `POST /auth/token` - Authenticate a user and issue access & refresh tokens.
|
||||||
|
- `POST /auth/refresh` - Rotate an access token using a refresh token.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Users
|
||||||
|
|
||||||
|
- `GET /users/me` - Retrieve the authenticated user's profile.
|
||||||
|
- `PATCH /users/me` - Update the authenticated user's profile.
|
||||||
|
- `GET /users` - List users (Administrator only).
|
||||||
|
- `POST /users` - Create a new staff or administrator account (Administrator only).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Customers
|
||||||
|
|
||||||
|
- `POST /customers` - Create customer.
|
||||||
|
- `GET /customers` - List customers.
|
||||||
|
- `GET /customers/{id}` - Retrieve customer information.
|
||||||
|
- `PATCH /customers/{id}` - Update customer information.
|
||||||
|
- `DELETE /customers/{id}` - Archive customer.
|
||||||
|
- `GET /customers/{id}/balance` - Retrieve current outstanding balance.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Categories
|
||||||
|
|
||||||
### Categories
|
|
||||||
- `POST /categories` - Create category.
|
- `POST /categories` - Create category.
|
||||||
- `GET /categories` - List categories (with pagination).
|
- `GET /categories` - List categories.
|
||||||
- `GET /categories/{id}` - Retrieve category detail.
|
- `GET /categories/{id}` - Retrieve category details.
|
||||||
- `PUT /categories/{id}` - Update category.
|
- `PUT /categories/{id}` - Update category.
|
||||||
- `DELETE /categories/{id}` - Delete category.
|
- `DELETE /categories/{id}` - Delete category.
|
||||||
|
|
||||||
### Products
|
---
|
||||||
|
|
||||||
|
## Products
|
||||||
|
|
||||||
- `POST /products` - Create product.
|
- `POST /products` - Create product.
|
||||||
- `GET /products` - List products (with text search, category filters, and pagination).
|
- `GET /products` - List products.
|
||||||
- `GET /products/{id}` - Retrieve product details.
|
- `GET /products/{id}` - Retrieve product details.
|
||||||
- `PUT /products/{id}` - Update product attributes.
|
- `PUT /products/{id}` - Update product.
|
||||||
- `DELETE /products/{id}` - Delete product.
|
- `DELETE /products/{id}` - Delete product.
|
||||||
|
|
||||||
### Orders
|
---
|
||||||
- `POST /orders` - Place order (adjusts stock level inside database transaction).
|
|
||||||
- `GET /orders` - List orders.
|
## Sales
|
||||||
- `GET /orders/{id}` - Retrieve order details.
|
|
||||||
- `PATCH /orders/{id}/status` - Cancel or process order (Admin/Worker only).
|
- `POST /sales` - Register a sale and update inventory.
|
||||||
|
- `GET /sales` - List sales.
|
||||||
|
- `GET /sales/{id}` - Retrieve sale details.
|
||||||
|
- `POST /sales/{id}/payments` - Register a payment for an existing sale.
|
||||||
|
- `GET /sales/{id}/payments` - List payments associated with a sale.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Inventory
|
||||||
|
|
||||||
|
- `POST /inventory/losses` - Register inventory loss.
|
||||||
|
- `GET /inventory/losses` - List inventory losses.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Reports
|
||||||
|
|
||||||
|
- `GET /reports/sales`
|
||||||
|
- `GET /reports/customer-balances`
|
||||||
|
- `GET /reports/inventory`
|
||||||
|
- `GET /reports/product-performance`
|
||||||
|
- `GET /reports/waste`
|
||||||
+42
-8
@@ -1,7 +1,6 @@
|
|||||||
# Flagship Project Architecture
|
# BiteTrack Backend v2 Architecture
|
||||||
|
|
||||||
## Name: BiteTrack Backend v2
|
BiteTrack follows a layered architecture that separates HTTP concerns, data validation, business rules, and persistence.
|
||||||
A production-grade reboot of the BiteTrack system focusing on inventory, order management, and core transactional processes using FastAPI.
|
|
||||||
|
|
||||||
## Core Architectural Layout
|
## Core Architectural Layout
|
||||||
The system follows a layered architecture to decouple routing, validation, business rules, and database access.
|
The system follows a layered architecture to decouple routing, validation, business rules, and database access.
|
||||||
@@ -15,8 +14,43 @@ graph TD
|
|||||||
DB -->|Read/Write| Postgres[(PostgreSQL Database)]
|
DB -->|Read/Write| Postgres[(PostgreSQL Database)]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Layers:
|
## Layers
|
||||||
1. **Routers (`routers/`)**: Handles HTTP routing, status codes, and security dependency injections.
|
|
||||||
2. **Schemas (`schemas/`)**: JSON serialization, deserialization, and strict input/output verification.
|
### Routers (`routers/`)
|
||||||
3. **Services (`services/`)**: Orchestrates business actions, processes transactions, and wraps DB actions.
|
|
||||||
4. **Models (`models/`)**: Represents relational tables mapped to PostgreSQL.
|
Responsible for:
|
||||||
|
|
||||||
|
- HTTP routing
|
||||||
|
- Status codes
|
||||||
|
- Dependency injection
|
||||||
|
- Authentication
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Schemas (`schemas/`)
|
||||||
|
|
||||||
|
Responsible for:
|
||||||
|
|
||||||
|
- Request validation
|
||||||
|
- Response serialization
|
||||||
|
- API contracts
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Services (`services/`)
|
||||||
|
|
||||||
|
Responsible for:
|
||||||
|
|
||||||
|
- Business rules
|
||||||
|
- Workflow orchestration
|
||||||
|
- Database transactions
|
||||||
|
- Coordination between repositories and domain models
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Models (`models/`)
|
||||||
|
|
||||||
|
Responsible for:
|
||||||
|
|
||||||
|
- Relational database mapping
|
||||||
|
- Persistence
|
||||||
+62
-16
@@ -1,48 +1,94 @@
|
|||||||
# Database Schema Design
|
# Database Design
|
||||||
|
|
||||||
## ERD Layout (Entity-Relationship)
|
## Planned Domain Model
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
erDiagram
|
erDiagram
|
||||||
|
|
||||||
USER {
|
USER {
|
||||||
uuid id PK
|
uuid id PK
|
||||||
string email UK
|
string email UK
|
||||||
string hashed_password
|
string password_hash
|
||||||
string role "Admin | Staff | Customer"
|
string role
|
||||||
boolean is_active
|
boolean is_active
|
||||||
datetime created_at
|
datetime created_at
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CUSTOMER {
|
||||||
|
uuid id PK
|
||||||
|
string name
|
||||||
|
string phone
|
||||||
|
string email
|
||||||
|
datetime created_at
|
||||||
|
}
|
||||||
|
|
||||||
CATEGORY {
|
CATEGORY {
|
||||||
int id PK
|
uuid id PK
|
||||||
string name UK
|
string name
|
||||||
string description
|
string description
|
||||||
}
|
}
|
||||||
|
|
||||||
PRODUCT {
|
PRODUCT {
|
||||||
uuid id PK
|
uuid id PK
|
||||||
string name
|
string name
|
||||||
string sku UK
|
string sku UK
|
||||||
string description
|
string description
|
||||||
decimal price
|
decimal unit_price
|
||||||
int stock_level
|
int stock_level
|
||||||
int category_id FK
|
int shelf_life_days
|
||||||
}
|
}
|
||||||
ORDER {
|
|
||||||
|
SALE {
|
||||||
uuid id PK
|
uuid id PK
|
||||||
uuid user_id FK
|
uuid customer_id FK
|
||||||
string status "Pending | Completed | Cancelled"
|
uuid created_by FK
|
||||||
decimal total_amount
|
decimal total_amount
|
||||||
datetime created_at
|
datetime created_at
|
||||||
}
|
}
|
||||||
ORDER_ITEM {
|
|
||||||
|
SALE_ITEM {
|
||||||
uuid id PK
|
uuid id PK
|
||||||
uuid order_id FK
|
uuid sale_id FK
|
||||||
uuid product_id FK
|
uuid product_id FK
|
||||||
int quantity
|
int quantity
|
||||||
decimal unit_price
|
decimal unit_price
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PAYMENT {
|
||||||
|
uuid id PK
|
||||||
|
uuid sale_id FK
|
||||||
|
decimal amount
|
||||||
|
string payment_method
|
||||||
|
datetime paid_at
|
||||||
|
}
|
||||||
|
|
||||||
|
INVENTORY_LOSS {
|
||||||
|
uuid id PK
|
||||||
|
uuid product_id FK
|
||||||
|
int quantity
|
||||||
|
string reason
|
||||||
|
datetime created_at
|
||||||
|
}
|
||||||
|
|
||||||
CATEGORY ||--o{ PRODUCT : contains
|
CATEGORY ||--o{ PRODUCT : contains
|
||||||
USER ||--o{ ORDER : places
|
|
||||||
ORDER ||--|{ ORDER_ITEM : has
|
CUSTOMER ||--o{ SALE : places
|
||||||
PRODUCT ||--o{ ORDER_ITEM : referenced_by
|
|
||||||
|
USER ||--o{ SALE : records
|
||||||
|
|
||||||
|
SALE ||--|{ SALE_ITEM : contains
|
||||||
|
|
||||||
|
SALE ||--o{ PAYMENT : receives
|
||||||
|
|
||||||
|
PRODUCT ||--o{ SALE_ITEM : sold_as
|
||||||
|
|
||||||
|
PRODUCT ||--o{ INVENTORY_LOSS : discarded
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
- Outstanding customer balances are **derived** from sales and payments rather than stored directly.
|
||||||
|
- A sale may receive multiple payments.
|
||||||
|
- Product stock is maintained as a `stock_level` field during the initial project milestones.
|
||||||
|
- Inventory losses represent products removed from inventory without completing a sale.
|
||||||
|
- Payment status is derived (calculated field) from recorded payments rather than stored explicitly.
|
||||||
Reference in new issue
Block a user