# sandipan0611/gym-management-system architecture

> Architecture diagram of the GitHub repository sandipan0611/gym-management-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sandipan0611/gym-management-system
- Repository: https://github.com/sandipan0611/gym-management-system

## Overview

1. **Overall shape**
   - This is a two-tier monorepo: a **Node.js/Express backend** at the repo root and a separate **React + Vite frontend** under `frontend/`.
   - The backend exposes HTTP APIs; the frontend consumes them and renders role-specific screens for **admins, trainers, and members**.

2. **Backend entry and request pipeline**
   - `index.js` is the backend bootstrap point: it likely creates the Express app, wires middleware, mounts route modules, and starts the server using the `.env` configuration.
   - Requests flow from routes into controllers, then into the database layer via `config/db.js`.

3. **API boundary and routing**
   - The `routes/` directory is the HTTP contract surface, split by business area:
     - `authRoutes`, `userRoutes`, `adminRoutes`
     - `dashboardRoutes`
     - `planRoutes`, `subscriptionRoutes`, `paymentRoutes`
     - `workoutRoutes`, `attendanceRoutes`
   - This separation suggests the API is organized around domain capabilities rather than generic CRUD only.

4. **Business logic layer**
   - `controllers/` contains the main application logic:
     - `authController` for signup/signin and token issuance
     - `adminController` for admin operations and role management
     - `userController` for member/trainer/user lifecycle
     - `planController`, `subscriptionController`, `paymentController` for membership commerce flows
     - `workoutController` for workout assignment/tracking
     - `attendanceController` for daily check-ins
     - `dashboardController` for aggregated metrics
   - Controllers are the key place where business rules live, including the RBAC and gym-specific workflows.

5. **Authentication and authorization**
   - `middleware/auth.js` is the main security boundary.
   - The README and file structure indicate **JWT-based authentication** with role-based access control.
   - This middleware likely protects admin/trainer/member endpoints and gates dashboard data by role.

6. **Core domain workflows**
   - The repository centers on gym operations:
     - **Member onboarding** through auth and plan selection
     - **Subscription lifecycle** through plan/subscription/payment modules
     - **Workout assignment** from trainers to members
     - **Attendance enforcement** with once-per-day check-ins
     - **Trainer succession/reassignment** logic when a trainer is replaced
   - These workflows span multiple controllers/routes rather than being isolated features.

7. **Data layer and schema**
   - PostgreSQL is the backing store, defined in `db/schema.sql` and mirrored in `db/schema_dump.sql`.
   - `config/db.js` is the connection/configuration point for database access.
   - The presence of both schema and dump files suggests the repo includes both canonical table definitions and a saved sample state.

8. **Migrations and seed data**
   - `scripts/migrations/` contains incremental schema evolution:
     - `001_add_user_status.js`
     - `002_add_previous_trainer.js`
   - `scripts/migrations/seed.js` populates initial/demo data.
   - This indicates the project supports evolving schema changes beyond the base SQL file.

9. **Frontend application boundary**
   - `frontend/` is an independent Vite app with its own dependencies and build tooling.
   - `frontend/src/App.jsx` and `main.jsx` are the client entry points; `components/` contains the UI surfaces for:
     - `Authentication`
     - `PricingTiers`
     - `AccountSettings`
     - `AdminDashboard`
     - `TrainerDashboard`
     - `MemberDashboard`
   - The frontend is organized by user role and account flow, mirroring the backend domain split.

10. **Frontend-to-backend data flow**
   - The UI likely follows this path:
     - authentication screen → JWT received from backend
     - token stored client-side and attached to API calls
     - role-specific dashboard requests fetched from protected endpoints
   - This means the dashboards are not just static views; they depend on server-side authorization and aggregated data APIs.

11. **Analytics and dashboarding**
   - `dashboardController` plus `frontend/src/components/*Dashboard.jsx` imply the system computes and displays operational metrics such as revenue, population, and visits.
   - These are likely read-heavy endpoints that aggregate across subscriptions, attendance, and user records.

12. **Operational/runtime boundaries**
   - Root `.env.example` defines backend runtime configuration: server port, PostgreSQL connection fields, and JWT secret.
   - The frontend has its own Vite config and separate package manifest, so backend and frontend can be developed and deployed independently even though they form one product.

13. **What to show in an architecture diagram**
   - Draw two main boxes: **React/Vite client** and **Express API server**.
   - Between them, show authenticated HTTP/API calls with JWT.
   - Behind the API, show **PostgreSQL** plus schema/migration/seed artifacts.
   - Inside the API, show the route-to-controller-to-database flow, with domain modules for auth, users, plans, subscriptions, payments, workouts, attendance, and dashboards.

Main entry points: [`index.js`](https://github.com/sandipan0611/gym-management-system/blob/main/index.js) (API server), [`frontend/src/App.jsx`](https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/App.jsx) (App shell), [`routes/dashboardRoutes.js`](https://github.com/sandipan0611/gym-management-system/blob/main/routes/dashboardRoutes.js) (Dashboard routes), [`config/db.js`](https://github.com/sandipan0611/gym-management-system/blob/main/config/db.js) (DB config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_app["App shell<br/>react entry<br/>[App.jsx]"]
  node_main["Client entry<br/>react mount<br/>[main.jsx]"]
  node_authui["Auth screen<br/>react component<br/>[Authentication.jsx]"]
  node_priceui["Pricing tiers<br/>react component<br/>[PricingTiers.jsx]"]
  node_settingsui["Account settings<br/>react component"]
  node_admindash["Admin dashboard<br/>react view<br/>[AdminDashboard.jsx]"]
  node_traindash["Trainer dashboard<br/>react view"]
  node_memberdash["Member dashboard<br/>react view"]
end

subgraph group_backend["Backend"]
  node_server["API server<br/>express bootstrap<br/>[index.js]"]
  node_authmw{{"Auth guard<br/>jwt rbac<br/>[auth.js]"}}
  node_dbconn[("DB config<br/>postgres connector<br/>[db.js]")]
  node_authroutes["Auth routes<br/>http routes<br/>[authRoutes.js]"]
  node_userroutes["User routes<br/>http routes<br/>[userRoutes.js]"]
  node_adminroutes["Admin routes<br/>http routes<br/>[adminRoutes.js]"]
  node_dashroutes["Dashboard routes<br/>http routes<br/>[dashboardRoutes.js]"]
  node_planroutes["Plan routes<br/>http routes<br/>[planRoutes.js]"]
  node_subroutes["Subscription routes<br/>http routes"]
  node_payroutes["Payment routes<br/>http routes<br/>[paymentRoutes.js]"]
  node_workroutes["Workout routes<br/>http routes<br/>[workoutRoutes.js]"]
  node_attroutes["Attendance routes<br/>http routes"]
  node_authctl["Auth controller<br/>session logic<br/>[authController.js]"]
  node_userctl["User controller<br/>member admin<br/>[userController.js]"]
  node_adminctl["Admin controller<br/>rbac admin<br/>[adminController.js]"]
  node_dashctl["Dashboard controller<br/>metrics api"]
  node_business{{"Business flows<br/>gym workflows"}}
end

subgraph group_data["Data"]
  node_schema["Schema SQL<br/>postgres schema<br/>[schema.sql]"]
  node_dump["Schema dump<br/>postgres snapshot<br/>[schema_dump.sql]"]
  node_migrations["Migrations<br/>schema evolution"]
end

node_main -->|"mounts"| node_app
node_app -->|"renders"| node_authui
node_app -->|"renders"| node_priceui
node_app -->|"renders"| node_settingsui
node_app -->|"renders"| node_admindash
node_app -->|"renders"| node_traindash
node_app -->|"renders"| node_memberdash
node_authui -->|"calls"| node_authroutes
node_admindash -->|"fetches"| node_dashroutes
node_traindash -->|"fetches"| node_dashroutes
node_memberdash -->|"fetches"| node_dashroutes
node_server -->|"mounts"| node_authroutes
node_server -->|"mounts"| node_userroutes
node_server -->|"mounts"| node_adminroutes
node_server -->|"mounts"| node_dashroutes
node_server -->|"mounts"| node_planroutes
node_server -->|"mounts"| node_subroutes
node_server -->|"mounts"| node_payroutes
node_server -->|"mounts"| node_workroutes
node_server -->|"mounts"| node_attroutes
node_authroutes -->|"delegates"| node_authctl
node_userroutes -->|"delegates"| node_userctl
node_adminroutes -->|"delegates"| node_adminctl
node_dashroutes -->|"delegates"| node_dashctl
node_planroutes -->|"supports"| node_business
node_subroutes -->|"supports"| node_business
node_payroutes -->|"supports"| node_business
node_workroutes -->|"supports"| node_business
node_attroutes -->|"supports"| node_business
node_authctl -->|"reads/writes"| node_dbconn
node_userctl -->|"reads/writes"| node_dbconn
node_adminctl -->|"reads/writes"| node_dbconn
node_dashctl -->|"aggregates"| node_dbconn
node_dbconn -->|"backed by"| node_schema
node_schema -.->|"mirrored in"| node_dump
node_schema -->|"evolves via"| node_migrations
node_server -->|"protects"| node_authmw
node_authmw -->|"gates"| node_adminroutes
node_authmw -->|"gates"| node_userroutes
node_authmw -->|"gates"| node_dashroutes

click node_server "https://github.com/sandipan0611/gym-management-system/blob/main/index.js"
click node_authmw "https://github.com/sandipan0611/gym-management-system/blob/main/middleware/auth.js"
click node_dbconn "https://github.com/sandipan0611/gym-management-system/blob/main/config/db.js"
click node_authroutes "https://github.com/sandipan0611/gym-management-system/blob/main/routes/authRoutes.js"
click node_userroutes "https://github.com/sandipan0611/gym-management-system/blob/main/routes/userRoutes.js"
click node_adminroutes "https://github.com/sandipan0611/gym-management-system/blob/main/routes/adminRoutes.js"
click node_dashroutes "https://github.com/sandipan0611/gym-management-system/blob/main/routes/dashboardRoutes.js"
click node_planroutes "https://github.com/sandipan0611/gym-management-system/blob/main/routes/planRoutes.js"
click node_subroutes "https://github.com/sandipan0611/gym-management-system/blob/main/routes/subscriptionRoutes.js"
click node_payroutes "https://github.com/sandipan0611/gym-management-system/blob/main/routes/paymentRoutes.js"
click node_workroutes "https://github.com/sandipan0611/gym-management-system/blob/main/routes/workoutRoutes.js"
click node_attroutes "https://github.com/sandipan0611/gym-management-system/blob/main/routes/attendanceRoutes.js"
click node_authctl "https://github.com/sandipan0611/gym-management-system/blob/main/controllers/authController.js"
click node_userctl "https://github.com/sandipan0611/gym-management-system/blob/main/controllers/userController.js"
click node_adminctl "https://github.com/sandipan0611/gym-management-system/blob/main/controllers/adminController.js"
click node_dashctl "https://github.com/sandipan0611/gym-management-system/blob/main/controllers/dashboardController.js"
click node_schema "https://github.com/sandipan0611/gym-management-system/blob/main/db/schema.sql"
click node_dump "https://github.com/sandipan0611/gym-management-system/blob/main/db/schema_dump.sql"
click node_migrations "https://github.com/sandipan0611/gym-management-system/tree/main/scripts/migrations"
click node_app "https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/App.jsx"
click node_main "https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/main.jsx"
click node_authui "https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/components/Authentication.jsx"
click node_priceui "https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/components/PricingTiers.jsx"
click node_settingsui "https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/components/AccountSettings.jsx"
click node_admindash "https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/components/AdminDashboard.jsx"
click node_traindash "https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/components/TrainerDashboard.jsx"
click node_memberdash "https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/components/MemberDashboard.jsx"

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_app,node_main,node_authui,node_priceui,node_settingsui,node_admindash,node_traindash,node_memberdash toneBlue
class node_server,node_authmw,node_dbconn,node_authroutes,node_userroutes,node_adminroutes,node_dashroutes,node_planroutes,node_subroutes,node_payroutes,node_workroutes,node_attroutes,node_authctl,node_userctl,node_adminctl,node_dashctl,node_business toneAmber
class node_schema,node_dump,node_migrations toneMint
```

## Components

### Frontend

React + Vite client for auth and role-specific dashboards

- [App shell](https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/App.jsx): react entry · Client application bootstrap and top-level composition. · `frontend/src/App.jsx`
- [Client entry](https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/main.jsx): react mount · Vite entrypoint that mounts the app. · `frontend/src/main.jsx`
- [Auth screen](https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/components/Authentication.jsx): react component · Authentication and sign-in UI. · `frontend/src/components/Authentication.jsx`
- [Pricing tiers](https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/components/PricingTiers.jsx): react component · Membership plan and pricing presentation. · `frontend/src/components/PricingTiers.jsx`
- [Account settings](https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/components/AccountSettings.jsx): react component · User account management UI. · `frontend/src/components/AccountSettings.jsx`
- [Admin dashboard](https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/components/AdminDashboard.jsx): react view · Admin-focused operational dashboard. · `frontend/src/components/AdminDashboard.jsx`
- [Trainer dashboard](https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/components/TrainerDashboard.jsx): react view · Trainer-focused dashboard and workflow UI. · `frontend/src/components/TrainerDashboard.jsx`
- [Member dashboard](https://github.com/sandipan0611/gym-management-system/blob/main/frontend/src/components/MemberDashboard.jsx): react view · Member-focused dashboard and status UI. · `frontend/src/components/MemberDashboard.jsx`

### Backend

Express API, routes, controllers, middleware, and server bootstrap

- [API server](https://github.com/sandipan0611/gym-management-system/blob/main/index.js): express bootstrap · Starts the Express app, wires middleware and routes, and loads runtime config. · `index.js`
- [Auth guard](https://github.com/sandipan0611/gym-management-system/blob/main/middleware/auth.js): jwt rbac · Protects API endpoints and enforces role-based access. · `middleware/auth.js`
- [DB config](https://github.com/sandipan0611/gym-management-system/blob/main/config/db.js): postgres connector · Database connection and configuration entrypoint. · `config/db.js`
- [Auth routes](https://github.com/sandipan0611/gym-management-system/blob/main/routes/authRoutes.js): http routes · Login, signup, and token-related endpoints. · `routes/authRoutes.js`
- [User routes](https://github.com/sandipan0611/gym-management-system/blob/main/routes/userRoutes.js): http routes · Member and trainer lifecycle endpoints. · `routes/userRoutes.js`
- [Admin routes](https://github.com/sandipan0611/gym-management-system/blob/main/routes/adminRoutes.js): http routes · Admin-only operations and role management endpoints. · `routes/adminRoutes.js`
- [Dashboard routes](https://github.com/sandipan0611/gym-management-system/blob/main/routes/dashboardRoutes.js): http routes · Aggregated metrics and role-specific dashboard endpoints. · `routes/dashboardRoutes.js`
- [Plan routes](https://github.com/sandipan0611/gym-management-system/blob/main/routes/planRoutes.js): http routes · Membership plan endpoints. · `routes/planRoutes.js`
- [Subscription routes](https://github.com/sandipan0611/gym-management-system/blob/main/routes/subscriptionRoutes.js): http routes · Subscription lifecycle endpoints. · `routes/subscriptionRoutes.js`
- [Payment routes](https://github.com/sandipan0611/gym-management-system/blob/main/routes/paymentRoutes.js): http routes · Payment and billing endpoints. · `routes/paymentRoutes.js`
- [Workout routes](https://github.com/sandipan0611/gym-management-system/blob/main/routes/workoutRoutes.js): http routes · Workout assignment and tracking endpoints. · `routes/workoutRoutes.js`
- [Attendance routes](https://github.com/sandipan0611/gym-management-system/blob/main/routes/attendanceRoutes.js): http routes · Daily check-in and attendance endpoints. · `routes/attendanceRoutes.js`
- [Auth controller](https://github.com/sandipan0611/gym-management-system/blob/main/controllers/authController.js): session logic · Authentication, signup/signin, and token issuance. · `controllers/authController.js`
- [User controller](https://github.com/sandipan0611/gym-management-system/blob/main/controllers/userController.js): member admin · Member and trainer lifecycle, including reassignment flows. · `controllers/userController.js`
- [Admin controller](https://github.com/sandipan0611/gym-management-system/blob/main/controllers/adminController.js): rbac admin · Admin operations and role management. · `controllers/adminController.js`
- [Dashboard controller](https://github.com/sandipan0611/gym-management-system/blob/main/controllers/dashboardController.js): metrics api · Aggregates operational metrics for dashboards. · `controllers/dashboardController.js`
- **Business flows**: gym workflows · Plans, subscriptions, payments, workouts, and attendance.

### Data

PostgreSQL schema and migration artifacts

- [Schema SQL](https://github.com/sandipan0611/gym-management-system/blob/main/db/schema.sql): postgres schema · Canonical table definitions for the database. · `db/schema.sql`
- [Schema dump](https://github.com/sandipan0611/gym-management-system/blob/main/db/schema_dump.sql): postgres snapshot · Saved database state and reference dump. · `db/schema_dump.sql`
- [Migrations](https://github.com/sandipan0611/gym-management-system/tree/main/scripts/migrations): schema evolution · Incremental database changes and seed data. · `scripts/migrations`

## Connections

- Client entry → App shell: mounts · Client entry mounts the application shell.
- App shell → Auth screen: renders · App composes authentication and role-based screens.
- App shell → Pricing tiers: renders · App includes pricing and plan UI.
- App shell → Account settings: renders · App includes account management UI.
- App shell → Admin dashboard: renders · App renders the admin dashboard.
- App shell → Trainer dashboard: renders · App renders the trainer dashboard.
- App shell → Member dashboard: renders · App renders the member dashboard.
- Auth screen → Auth routes: calls · Authentication UI talks to auth endpoints.
- Admin dashboard → Dashboard routes: fetches · Dashboard views request aggregated metrics.
- Trainer dashboard → Dashboard routes: fetches · Trainer view consumes dashboard data.
- Member dashboard → Dashboard routes: fetches · Member view consumes dashboard data.
- API server → Auth routes: mounts · Server registers auth routes.
- API server → User routes: mounts · Server registers user routes.
- API server → Admin routes: mounts · Server registers admin routes.
- API server → Dashboard routes: mounts · Server registers dashboard routes.
- API server → Plan routes: mounts · Server registers plan routes.
- API server → Subscription routes: mounts · Server registers subscription routes.
- API server → Payment routes: mounts · Server registers payment routes.
- API server → Workout routes: mounts · Server registers workout routes.
- API server → Attendance routes: mounts · Server registers attendance routes.
- Auth routes → Auth controller: delegates · Auth routes hand off to auth controller logic.
- User routes → User controller: delegates · User routes hand off to user controller logic.
- Admin routes → Admin controller: delegates · Admin routes hand off to admin controller logic.
- Dashboard routes → Dashboard controller: delegates · Dashboard routes hand off to aggregation logic.
- Plan routes → Business flows: supports · Plan operations feed membership workflows.
- Subscription routes → Business flows: supports · Subscription operations feed membership workflows.
- Payment routes → Business flows: supports · Payment operations feed membership workflows.
- Workout routes → Business flows: supports · Workout operations feed gym workflows.
- Attendance routes → Business flows: supports · Attendance operations feed gym workflows.
- Auth controller → DB config: reads/writes · Auth logic persists users and sessions through the database layer.
- User controller → DB config: reads/writes · User management persists through the database layer.
- Admin controller → DB config: reads/writes · Admin operations persist through the database layer.
- Dashboard controller → DB config: aggregates · Dashboard metrics are computed from database queries.
- DB config → Schema SQL: backed by · Database config points to the PostgreSQL schema.
- Schema SQL → Schema dump: mirrored in · Schema is also captured in the dump snapshot.
- Schema SQL → Migrations: evolves via · Migrations extend the base schema over time.
- API server → Auth guard: protects · Middleware guards protected routes.
- Auth guard → Admin routes: gates · Admin endpoints require authorization and role checks.
- Auth guard → User routes: gates · User endpoints are protected where needed.
- Auth guard → Dashboard routes: gates · Dashboard endpoints are role-aware.
