# abhishek21lift-oss/619-erp-backend architecture

> Architecture diagram of the GitHub repository abhishek21lift-oss/619-erp-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhishek21lift-oss/619-erp-backend
- Repository: https://github.com/abhishek21lift-oss/619-erp-backend

## Overview

619 Fitness ERP is a multi-studio fitness operations backend. Staff manage personal-training clients and their plans; members access their own profile, payments, workouts, diet, consent forms, and messages. Progress and business metrics support operational decisions, while automation queues client communications. Platform administrators have separate oversight and storage-accounting capabilities. The graph emphasizes source-supported runtime links; several broader subsystems are visible in the tree, but their wiring was not sampled.

Main entry points: [`src/db/pool.js`](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/db/pool.js) (PostgreSQL), [`src/modules/client-portal/client-portal.routes.js`](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/client-portal/client-portal.routes.js) (Member portal), [`src/modules/pt-os/pt-os.routes.js`](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/pt-os/pt-os.routes.js) (PT operations), [`src/modules/progress/progress.routes.js`](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/progress/progress.routes.js) (Progress tracking)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pt["PT Operations"]
  node_pt_routes["PT operations<br/>[pt-os.routes.js]"]
  node_pt_service["PT services<br/>[pt-os.service.js]"]
  node_progress["Progress tracking<br/>[progress.routes.js]"]
  node_fitness["Fitness scoring<br/>[fitness-scoring.js]"]
  node_payment_routes["Payments API<br/>[payments.js]"]
end

subgraph group_member["Member Experience"]
  node_portal_routes["Member portal"]
  node_portal_service["Portal services"]
end

subgraph group_insights["Insights Automation"]
  node_insights_routes["Insights API<br/>[insights.routes.js]"]
  node_metrics["Metric engine<br/>[metric-engine.js]"]
  node_insight_engine["Insights engine<br/>[insights-engine.js]"]
  node_automation["Automation engine"]
  node_automation_repo["Automation repository"]
  node_whatsapp_queue["WhatsApp service"]
end

subgraph group_platform["Platform Operations"]
  node_admin_routes["Super-admin API"]
  node_storage_admin["Storage reporting<br/>[storage.js]"]
end

subgraph group_storage["File Storage"]
  node_storage["File storage<br/>[fileStorage.js]"]
  node_ledger["Storage ledger<br/>[storageLedger.js]"]
end

node_staff(("Studio staff"))
node_portal_actor(("Studio member"))
node_billing{{"Payment provider"}}
node_db[("PostgreSQL<br/>[pool.js]")]
node_insights_actor(("Studio decision-maker"))
node_admin(("Platform administrator"))
node_object_store[("R2 object storage")]

node_staff -->|"manages clients"| node_pt_routes
node_pt_routes -->|"calls services"| node_pt_service
node_pt_routes -->|"reads and writes"| node_db
node_staff -->|"records progress"| node_progress
node_progress -->|"scores fitness"| node_fitness
node_progress -->|"reads and writes"| node_db
node_portal_actor -->|"accesses account"| node_portal_routes
node_portal_routes -->|"requests portal data"| node_portal_service
node_portal_routes -->|"reads and writes"| node_db
node_portal_routes -->|"serves consent PDF"| node_storage
node_staff -->|"records payments"| node_payment_routes
node_payment_routes -->|"reads and writes"| node_db
node_payment_routes -.->|"payment integration"| node_billing
node_insights_actor -->|"requests insights"| node_insights_routes
node_insights_routes -->|"requests metrics"| node_metrics
node_metrics -->|"queries canonical data"| node_db
node_metrics -->|"provides metrics"| node_insight_engine
node_automation -->|"loads rules and records outcomes"| node_automation_repo
node_automation -->|"enqueues messages"| node_whatsapp_queue
node_admin -->|"administers platform"| node_admin_routes
node_admin_routes -->|"mounts storage API"| node_storage_admin
node_storage_admin -->|"queries storage records"| node_db
node_storage -.->|"stores and serves files"| node_object_store
node_storage -->|"records file changes"| node_ledger
node_ledger -->|"records attribution"| node_db

click node_pt_routes "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/pt-os/pt-os.routes.js"
click node_pt_service "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/pt-os/pt-os.service.js"
click node_progress "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/progress/progress.routes.js"
click node_fitness "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/progress/fitness-scoring.js"
click node_portal_routes "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/client-portal/client-portal.routes.js"
click node_portal_service "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/client-portal/client-portal.service.js"
click node_payment_routes "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/routes/payments.js"
click node_db "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/db/pool.js"
click node_insights_routes "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/insights/insights.routes.js"
click node_metrics "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/insights/metric-engine.js"
click node_insight_engine "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/insights/insights-engine.js"
click node_automation "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/automation/automation.engine.js"
click node_automation_repo "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/automation/automation.repository.js"
click node_whatsapp_queue "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/services/whatsapp.service.js"
click node_admin_routes "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/platform/super-admin.routes.js"
click node_storage_admin "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/platform/super-admin/storage.js"
click node_storage "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/lib/fileStorage.js"
click node_ledger "https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/lib/storageLedger.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pt_routes,node_pt_service,node_progress,node_fitness,node_payment_routes toneBlue
class node_portal_routes,node_portal_service,node_db,node_object_store toneAmber
class node_insights_routes,node_metrics,node_insight_engine,node_automation,node_automation_repo,node_whatsapp_queue toneMint
class node_admin_routes,node_storage_admin toneRose
class node_storage,node_ledger,node_staff,node_portal_actor,node_billing,node_insights_actor,node_admin toneIndigo
```

## Components

### PT Operations

- [PT operations](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/pt-os/pt-os.routes.js): `src/modules/pt-os/pt-os.routes.js`
- [PT services](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/pt-os/pt-os.service.js): `src/modules/pt-os/pt-os.service.js`
- [Progress tracking](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/progress/progress.routes.js): `src/modules/progress/progress.routes.js`
- [Fitness scoring](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/progress/fitness-scoring.js): `src/modules/progress/fitness-scoring.js`
- [Payments API](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/routes/payments.js): `src/routes/payments.js`

### Member Experience

- [Member portal](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/client-portal/client-portal.routes.js): `src/modules/client-portal/client-portal.routes.js`
- [Portal services](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/client-portal/client-portal.service.js): `src/modules/client-portal/client-portal.service.js`

### Insights Automation

- [Insights API](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/insights/insights.routes.js): `src/modules/insights/insights.routes.js`
- [Metric engine](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/insights/metric-engine.js): `src/modules/insights/metric-engine.js`
- [Insights engine](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/insights/insights-engine.js): `src/modules/insights/insights-engine.js`
- [Automation engine](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/automation/automation.engine.js): `src/modules/automation/automation.engine.js`
- [Automation repository](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/automation/automation.repository.js): `src/modules/automation/automation.repository.js`
- [WhatsApp service](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/services/whatsapp.service.js): `src/services/whatsapp.service.js`

### Platform Operations

- [Super-admin API](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/platform/super-admin.routes.js): `src/modules/platform/super-admin.routes.js`
- [Storage reporting](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/modules/platform/super-admin/storage.js): `src/modules/platform/super-admin/storage.js`

### File Storage

- [File storage](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/lib/fileStorage.js): `src/lib/fileStorage.js`
- [Storage ledger](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/lib/storageLedger.js): `src/lib/storageLedger.js`

### Other components

- **Studio staff**
- **Studio member**
- **Payment provider**
- [PostgreSQL](https://github.com/abhishek21lift-oss/619-erp-backend/blob/main/src/db/pool.js): `src/db/pool.js`
- **Studio decision-maker**
- **Platform administrator**
- **R2 object storage**

## Connections

- Studio staff → PT operations: manages clients
- PT operations → PT services: calls services
- PT operations → PostgreSQL: reads and writes
- Studio staff → Progress tracking: records progress
- Progress tracking → Fitness scoring: scores fitness
- Progress tracking → PostgreSQL: reads and writes
- Studio member → Member portal: accesses account
- Member portal → Portal services: requests portal data
- Member portal → PostgreSQL: reads and writes
- Member portal → File storage: serves consent PDF
- Studio staff → Payments API: records payments
- Payments API → PostgreSQL: reads and writes
- Payments API → Payment provider: payment integration
- Studio decision-maker → Insights API: requests insights
- Insights API → Metric engine: requests metrics
- Metric engine → PostgreSQL: queries canonical data
- Metric engine → Insights engine: provides metrics
- Automation engine → Automation repository: loads rules and records outcomes
- Automation engine → WhatsApp service: enqueues messages
- Platform administrator → Super-admin API: administers platform
- Super-admin API → Storage reporting: mounts storage API
- Storage reporting → PostgreSQL: queries storage records
- File storage → R2 object storage: stores and serves files
- File storage → Storage ledger: records file changes
- Storage ledger → PostgreSQL: records attribution
