Files
second-brain/project/database.md
T
kiskaadee f9144064f0 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
2026-07-15 12:28:16 -05:00

1.6 KiB

Database Design

Planned Domain Model

erDiagram

USER {
    uuid id PK
    string email UK
    string password_hash
    string role
    boolean is_active
    datetime created_at
}

CUSTOMER {
    uuid id PK
    string name
    string phone
    string email
    datetime created_at
}

CATEGORY {
    uuid id PK
    string name
    string description
}

PRODUCT {
    uuid id PK
    string name
    string sku UK
    string description
    decimal unit_price
    int stock_level
    int shelf_life_days
}

SALE {
    uuid id PK
    uuid customer_id FK
    uuid created_by FK
    decimal total_amount
    datetime created_at
}

SALE_ITEM {
    uuid id PK
    uuid sale_id FK
    uuid product_id FK
    int quantity
    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

CUSTOMER ||--o{ SALE : places

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.