How sandipan0611/gym-management-system works
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 API server · App.jsx App shell · dashboardRoutes.js Dashboard routes · db.js DB config
Components 28
Frontend
React + Vite client for auth and role-specific dashboards
- App shell · Client application bootstrap and top-level composition.
frontend/src/App.jsx - Client entry · Vite entrypoint that mounts the app.
frontend/src/main.jsx - Auth screen · Authentication and sign-in UI.
frontend/src/components/Authentication.jsx - Pricing tiers · Membership plan and pricing presentation.
frontend/src/components/PricingTiers.jsx - Account settings · User account management UI.
frontend/src/components/AccountSettings.jsx - Admin dashboard · Admin-focused operational dashboard.
frontend/src/components/AdminDashboard.jsx - Trainer dashboard · Trainer-focused dashboard and workflow UI.
frontend/src/components/TrainerDashboard.jsx - Member dashboard · Member-focused dashboard and status UI.
frontend/src/components/MemberDashboard.jsx
Backend
Express API, routes, controllers, middleware, and server bootstrap
- API server · Starts the Express app, wires middleware and routes, and loads runtime config.
index.js - Auth guard · Protects API endpoints and enforces role-based access.
middleware/auth.js - DB config · Database connection and configuration entrypoint.
config/db.js - Auth routes · Login, signup, and token-related endpoints.
routes/authRoutes.js - User routes · Member and trainer lifecycle endpoints.
routes/userRoutes.js - Admin routes · Admin-only operations and role management endpoints.
routes/adminRoutes.js - Dashboard routes · Aggregated metrics and role-specific dashboard endpoints.
routes/dashboardRoutes.js - Plan routes · Membership plan endpoints.
routes/planRoutes.js - Subscription routes · Subscription lifecycle endpoints.
routes/subscriptionRoutes.js - Payment routes · Payment and billing endpoints.
routes/paymentRoutes.js - Workout routes · Workout assignment and tracking endpoints.
routes/workoutRoutes.js - Attendance routes · Daily check-in and attendance endpoints.
routes/attendanceRoutes.js - Auth controller · Authentication, signup/signin, and token issuance.
controllers/authController.js - User controller · Member and trainer lifecycle, including reassignment flows.
controllers/userController.js - Admin controller · Admin operations and role management.
controllers/adminController.js - Dashboard controller · Aggregates operational metrics for dashboards.
controllers/dashboardController.js - Business flows · Plans, subscriptions, payments, workouts, and attendance.
Data
PostgreSQL schema and migration artifacts
- Schema SQL · Canonical table definitions for the database.
db/schema.sql - Schema dump · Saved database state and reference dump.
db/schema_dump.sql - Migrations · Incremental database changes and seed data.
scripts/migrations
Connections 40
- 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.