USWAG logo

U•S•W•A•G

Unified System for Work and Growth

IM1 logo
2 · Modeling
2

Modeling

Conceptual model: ERD with 1:1, 1:M, and M:N cardinalities in Crow’s Foot notation.

Entities and Cardinality
  • The main task is to model the domain with explicit 1:1, 1:M, and M:N cardinalities.
  • Result: 12 entities and 16 relationships, based from USWAG database.
  • Strong entities: Accounts, Sellers, Categories, Products and Sales.
  • Weak entities: Sale_Details (identified by Sales) and Capital_Ledger (identified by Sellers).
  • Sale_Details acts as an associative entity resolving the M:N relationship between Sales and Products.
  • Optional links (0..1): the buyer on a sale and the verifier on an inventory entry.
2 · Modeling
ERD Entity Schemas
2 · Modeling
Business Rules
  • Role-based access control manages user roles, auto-provisions profiles, secures logins, and handles session tokens.
  • Strict domain integrity prevents duplicate user credentials, categories, product names, or seller profiles.
  • Stock values are non-negative and only change through admin-verified inventory logs or sale deductions.
  • Sales auto-assign historical item prices, reject empty orders, and lock completely once paid.
  • Offline sales utilize unique client identifiers to guarantee duplicate-free synchronizations.
  • Paid sales generate immutable JSON receipts using structured, unique reference numbers.
  • Seller capital is maintained in a single record and updated exclusively through thread-safe procedures.
  • Expenses automatically adjust seller balances, log ledger entries, and enforce category rules.
  • The financial ledger operates strictly as append-only, preventing manual edits or deletions.
  • Visitor contact forms enforce hourly rate limits and hash IP addresses to ensure system security.
2 · Modeling
Entity-Relationship Diagram
erDiagram
    Accounts {
        int account_id PK
        enum role
        varchar(50) username UK
        varchar(100) email UK
        varchar(15) contact_number UK
        varchar(150) address
        varchar(255) password_hash
        char(64) api_token_hash UK
        datetime api_token_expires_at
        tinyint failed_login_attempts
        datetime locked_until
        datetime last_login_at
        tinyint is_active
        datetime created_at
    }
            
    Capital_Ledger {
        bigint ledger_id PK
        int seller_id FK
        varchar(30) entry_type
        decimal amount
        decimal balance_after
        int reference_id
        varchar(150) note
        datetime created_at
    }
            
    Capital_Management {
        int capital_id PK
        int seller_id FK
        decimal initial_capital
        decimal current_balance
        datetime last_updated
    }
            
    Categories {
        int category_id PK
        varchar(50) category_name UK
    }
            
    Contact_Messages {
        int message_id PK
        varchar(100) sender_name
        varchar(100) sender_email
        varchar(15) contact_number
        varchar(50) subject
        text message_body
        enum status
        char(32) public_token
        char(64) ip_hash
        tinyint sms_sent
        tinyint email_sent
        int reviewed_by_account_id FK
        datetime reviewed_at
        datetime created_at
    }
            
    Expenses {
        int expense_id PK
        int seller_id FK
        enum expense_category
        decimal amount
        datetime expense_date
        varchar(150) description
    }
            
    Inventory_Transactions {
        int transaction_id PK
        int product_id FK
        int sale_detail_id FK
        enum transaction_type
        enum verification_status
        decimal quantity
        datetime transaction_date
        varchar(150) remarks
        int verified_by_account_id FK
        datetime verified_at
    }
            
    Products {
        int product_id PK
        int seller_id FK
        int category_id FK
        varchar(100) product_name
        varchar(20) unit_of_measure
        decimal unit_price
        decimal current_stock
        decimal reorder_level
        tinyint is_active
    }
            
    Receipts {
        bigint receipt_id PK
        int sale_id FK
        int account_id FK
        varchar(50) receipt_number UK
        enum receipt_type
        longtext receipt_data
        datetime issued_at
        tinyint is_downloaded
        enum sync_status
    }
            
    Sales {
        int sale_id PK
        int seller_id FK
        int buyer_account_id FK
        datetime sale_date
        enum status
        enum sync_status
        char(36) client_id
    }
            
    Sale_Details {
        int sale_detail_id PK
        int sale_id FK
        int product_id FK
        decimal quantity_sold
        decimal unit_price_at_sale
        decimal line_total
    }
            
    Sellers {
        int seller_id PK
        int account_id FK
        varchar(50) first_name
        varchar(50) last_name
        varchar(15) contact_number UK
        varchar(50) barangay_zone
        varchar(100) slp_association
        date join_date
        tinyint is_active
    }
            
    Accounts |o..o{ Contact_Messages : "1:M reviews"
    Accounts |o..o{ Inventory_Transactions : "1:M verifies"
    Accounts |o..o{ Receipts : "1:M issued to"
    Accounts |o..o{ Sales : "1:M buys"
    Accounts |o..o| Sellers : "1:1 is profile of"
    Categories ||..o{ Products : "1:M groups"
    Products ||..o{ Inventory_Transactions : "1:M stock moves"
    Products }o..o{ Sales : "M:N sold as (via Sale_Details)"
    Sales ||..o| Receipts : "1:1 proves"
    Sales ||--o{ Sale_Details : "1:M lists"
    Sale_Details |o..o{ Inventory_Transactions : "1:M caused by"
    Sellers ||--o{ Capital_Ledger : "1:M logs"
    Sellers ||..o| Capital_Management : "1:1 holds"
    Sellers ||..o{ Expenses : "1:M spends"
    Sellers ||..o{ Products : "1:M sells"
    Sellers ||..o{ Sales : "1:M makes"
          

Drawn live by Mermaid from the database with 1:1, 1:M, and M:N cardinalities. Click the diagram to enlarge it.

‹ Proposal Normalization ›