Skip to main content

System Design - Data Model Architecture

TEMP

Core Models​

Customer & Organization Management​

  1. Customer Model

    • Primary tenant/organization model
    • Supports multi-tenant architecture
    • Industry-specific configuration (trucking/serviceRepair)
    • Payment status tracking
    • Contact management
  2. Client Model

    • Represents individual business clients
    • Links to Customer (parent company)
    • Contact information and rates
    • Location management
    • Text search capabilities
  3. Organization Model

    • Internal organization structure
    • Employee management
    • Meta information storage

User Management​

  1. User Model

    • Core user authentication
    • Role-based access control
    • Profile information
  2. Employee Model

    • Extended user information
    • Department and position tracking
    • Status management
    • Parent company association
  3. Driver Model

    • Specialized user type
    • Client association
    • Organization assignment

Location Management​

  1. Address Model

    • Standardized address storage
    • Geocoding support (lat/lng)
    • Client association
    • Full address formatting
  2. Location Model

    • Business location details
    • Receiving hours
    • Client association
    • Address reference

Job Management​

  1. Job Model

    • Core job/work order entity
    • Industry-agnostic base structure
    • Status tracking
    • Approval workflow
    • Timeline tracking
    • Client association
  2. Leg Model (Trucking)

    • Route segments
    • Payout calculations
    • Wait time tracking
    • Custom rate handling
    • Approval workflow
  3. Maintenance Model (Service/Repair)

    • Service details
    • Parts tracking
    • Time tracking
    • Quote management
    • Approval workflow

Financial Management​

  1. Invoice Model

    • Job aggregation
    • Total calculations
    • Status tracking
    • Terms and due dates
  2. Payout Model

    • Driver/employee compensation
    • Multiple rate types
    • Shift and leg aggregation
    • Total calculations
  3. Manifest Model

    • Driver route planning
    • Leg aggregation
    • Rate management
    • Status tracking

Inventory Management​

  1. InventoryItem Model

    • Part tracking
    • Stock management
    • Supplier association
    • Status tracking
  2. Accessory Model

    • Additional items
    • Job association
    • Pricing

Equipment Management​

  1. Equipment Model
    • Asset tracking
    • Maintenance history
    • Status management
    • Client association

Communication & Documentation​

  1. Message Model

    • Internal communication
    • Reference tracking
    • Author association
  2. Media Model

    • File management
    • URL generation
    • Reference tracking
  3. PDFTemplate Model

    • Document templates
    • Configuration storage
    • Type-specific settings

Support & Feedback​

  1. Feedback Model

    • Issue tracking
    • Message association
    • Status management
    • Priority handling
  2. Notification Model

    • System notifications
    • Priority levels
    • Expiration handling
    • Read status tracking

Common Features Across Models​

Timestamps​

  • Consistent dateCreated and dateUpdated fields
  • Mongoose timestamp configuration

Parent Company Association​

  • Multi-tenant support through parentCompany field
  • Indexed for performance

Status Management​

  • Standardized status tracking
  • Status transition history
  • Approval workflows where applicable

Virtual Fields​

  • Computed properties
  • Aggregated calculations
  • Formatted data

Indexing Strategy​

  • Parent company indexing
  • Text search capabilities
  • Reference field indexing

Plugins​

  • Mongoose Paginate
  • Mongoose Aggregate Paginate
  • Mongoose Lean Virtuals
  • Mongoose Autopopulate

Industry-Specific Features​

Trucking Industry​

  • Route management
  • Mileage tracking
  • Driver assignments
  • Payout calculations
  • Manifest generation

Service/Repair Industry​

  • Maintenance scheduling
  • Parts management
  • Time tracking
  • Quote generation
  • Service history

Data Relationships​

One-to-Many​

  • Customer β†’ Clients
  • Client β†’ Locations
  • Job β†’ Legs/Maintenance
  • Invoice β†’ Jobs

Many-to-Many​

  • Job ↔ Employees
  • Maintenance ↔ Parts
  • Client ↔ Contacts

One-to-One​

  • Location ↔ Address
  • Job ↔ Invoice

Security Considerations​

Multi-tenant Isolation​

  • Parent company scoping
  • Cross-tenant data protection
  • Access control enforcement

Data Validation​

  • Schema-level validation
  • Required fields
  • Enum restrictions
  • Custom validators

Audit Trail​

  • History tracking
  • Change logging
  • User attribution