# dream-programmer-lazy/kltn_web_gym_ai architecture

> Architecture diagram of the GitHub repository dream-programmer-lazy/kltn_web_gym_ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dream-programmer-lazy/kltn_web_gym_ai
- Repository: https://github.com/dream-programmer-lazy/kltn_web_gym_ai

## Overview

KOI Fitness is a gym membership and churn-risk management application. Prospective members submit fitness details; the backend requests an AI churn prediction and stores the resulting profile. Staff can view, add, batch-import, and delete member records through an admin dashboard, while users and admins have separate registration/login and dashboard routes. The repository also contains a Python prediction API and model-training code. Some page and ML internals were not excerpted, so links involving them are omitted unless the source index or excerpts establish them.

Main entry points: [`frontend/src/App.jsx`](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/frontend/src/App.jsx) (Route application), [`backend/server.js`](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/server.js) (Express server), [`backend/routes/customerRoutes.js`](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/routes/customerRoutes.js) (Customer routes), [`backend/controllers/customerController.js`](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/controllers/customerController.js) (Customer controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_frontend_app["Route application<br/>[App.jsx]"]
  node_landing["Public landing<br/>[LandingPage.jsx]"]
  node_admin_ui["Member dashboard"]
  node_login_ui["Login page<br/>[Login.jsx]"]
  node_admin_register_ui["Admin registration<br/>[Register.jsx]"]
  node_user_register_ui["User registration<br/>[UserRegister.jsx]"]
  node_user_dashboard["User dashboard<br/>[UserDashboard.jsx]"]
end

subgraph group_identity["Identity and access"]
  node_auth_routes["Auth routes<br/>[authRoutes.js]"]
  node_auth_controller["Auth controller<br/>[authController.js]"]
  node_user_model["User model<br/>[User.js]"]
  node_auth_middleware["Auth middleware<br/>[authMiddleware.js]"]
end

subgraph group_members["Member management"]
  node_backend["Express server<br/>[server.js]"]
  node_customer_routes["Customer routes<br/>[customerRoutes.js]"]
  node_customer_controller["Customer controller"]
  node_customer_model["Customer model<br/>[Customer.js]"]
end

subgraph group_prediction["Churn prediction"]
  node_ml_api["Prediction API<br/>[app.py]"]
  node_model_training["Model training<br/>[train_model.py]"]
  node_ml_model["Trained model"]
end

node_visitor(("Prospective member"))
node_staff(("Staff user"))
node_mongo[("MongoDB")]

node_visitor -->|"visits"| node_landing
node_landing -->|"submits registration"| node_backend
node_staff -.->|"signs in"| node_login_ui
node_staff -.->|"manages members"| node_admin_ui
node_frontend_app -->|"routes to"| node_landing
node_frontend_app -->|"routes to"| node_login_ui
node_frontend_app -->|"routes to"| node_admin_register_ui
node_frontend_app -->|"routes to"| node_user_register_ui
node_frontend_app -->|"routes to"| node_admin_ui
node_frontend_app -->|"routes to"| node_user_dashboard
node_backend -->|"mounts routes"| node_auth_routes
node_backend -->|"mounts routes"| node_customer_routes
node_backend -->|"connects to"| node_mongo
node_auth_routes -->|"dispatches"| node_auth_controller
node_auth_controller -->|"queries and saves"| node_user_model
node_customer_routes -->|"guards routes"| node_auth_middleware
node_customer_routes -->|"dispatches"| node_customer_controller
node_customer_controller -->|"reads and writes"| node_customer_model
node_customer_controller -->|"requests prediction"| node_ml_api
node_admin_ui -->|"loads and manages records"| node_backend
node_ml_api -.->|"uses model"| node_ml_model
node_model_training -.->|"produces model"| node_ml_model

click node_frontend_app "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/frontend/src/App.jsx"
click node_landing "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/frontend/src/pages/LandingPage.jsx"
click node_admin_ui "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/frontend/src/pages/CustomerManagement.jsx"
click node_login_ui "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/frontend/src/pages/Login.jsx"
click node_admin_register_ui "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/frontend/src/pages/Register.jsx"
click node_user_register_ui "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/frontend/src/pages/UserRegister.jsx"
click node_user_dashboard "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/frontend/src/pages/UserDashboard.jsx"
click node_backend "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/server.js"
click node_auth_routes "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/routes/authRoutes.js"
click node_auth_controller "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/controllers/authController.js"
click node_user_model "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/models/User.js"
click node_customer_routes "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/routes/customerRoutes.js"
click node_auth_middleware "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/middlewares/authMiddleware.js"
click node_customer_controller "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/controllers/customerController.js"
click node_customer_model "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/models/Customer.js"
click node_ml_api "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/ml-api/app.py"
click node_model_training "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/ml-api/train_model.py"
click node_ml_model "https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/ml-api/gym_churn_model.pkl"

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_frontend_app,node_landing,node_admin_ui,node_login_ui,node_admin_register_ui,node_user_register_ui,node_user_dashboard,node_staff toneBlue
class node_auth_routes,node_auth_controller,node_user_model,node_auth_middleware,node_mongo toneAmber
class node_backend,node_customer_routes,node_customer_controller,node_customer_model toneMint
class node_ml_api,node_model_training,node_ml_model toneRose
class node_visitor toneIndigo
```

## Components

### Web application

- [Route application](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Public landing](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/frontend/src/pages/LandingPage.jsx): `frontend/src/pages/LandingPage.jsx`
- [Member dashboard](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/frontend/src/pages/CustomerManagement.jsx): `frontend/src/pages/CustomerManagement.jsx`
- [Login page](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/frontend/src/pages/Login.jsx): `frontend/src/pages/Login.jsx`
- [Admin registration](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/frontend/src/pages/Register.jsx): `frontend/src/pages/Register.jsx`
- [User registration](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/frontend/src/pages/UserRegister.jsx): `frontend/src/pages/UserRegister.jsx`
- [User dashboard](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/frontend/src/pages/UserDashboard.jsx): `frontend/src/pages/UserDashboard.jsx`

### Identity and access

- [Auth routes](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/routes/authRoutes.js): `backend/routes/authRoutes.js`
- [Auth controller](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/controllers/authController.js): `backend/controllers/authController.js`
- [User model](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/models/User.js): `backend/models/User.js`
- [Auth middleware](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/middlewares/authMiddleware.js): `backend/middlewares/authMiddleware.js`

### Member management

- [Express server](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/server.js): `backend/server.js`
- [Customer routes](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/routes/customerRoutes.js): `backend/routes/customerRoutes.js`
- [Customer controller](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/controllers/customerController.js): `backend/controllers/customerController.js`
- [Customer model](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/backend/models/Customer.js): `backend/models/Customer.js`

### Churn prediction

- [Prediction API](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/ml-api/app.py): `ml-api/app.py`
- [Model training](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/ml-api/train_model.py): `ml-api/train_model.py`
- [Trained model](https://github.com/dream-programmer-lazy/kltn_web_gym_ai/blob/main/ml-api/gym_churn_model.pkl): `ml-api/gym_churn_model.pkl`

### Other components

- **Prospective member**
- **Staff user**
- **MongoDB**

## Connections

- Prospective member → Public landing: visits (evidence: `frontend/src/pages/LandingPage.jsx`)
- Public landing → Express server: submits registration (evidence: `frontend/src/pages/LandingPage.jsx`)
- Staff user → Login page: signs in
- Staff user → Member dashboard: manages members
- Route application → Public landing: routes to (evidence: `frontend/src/App.jsx`)
- Route application → Login page: routes to (evidence: `frontend/src/App.jsx`)
- Route application → Admin registration: routes to (evidence: `frontend/src/App.jsx`)
- Route application → User registration: routes to (evidence: `frontend/src/App.jsx`)
- Route application → Member dashboard: routes to (evidence: `frontend/src/App.jsx`)
- Route application → User dashboard: routes to (evidence: `frontend/src/App.jsx`)
- Express server → Auth routes: mounts routes (evidence: `backend/server.js`)
- Express server → Customer routes: mounts routes (evidence: `backend/server.js`)
- Express server → MongoDB: connects to (evidence: `backend/server.js`)
- Auth routes → Auth controller: dispatches (evidence: `backend/routes/authRoutes.js`)
- Auth controller → User model: queries and saves (evidence: `backend/controllers/authController.js`)
- Customer routes → Auth middleware: guards routes (evidence: `backend/routes/customerRoutes.js`)
- Customer routes → Customer controller: dispatches (evidence: `backend/routes/customerRoutes.js`)
- Customer controller → Customer model: reads and writes (evidence: `backend/controllers/customerController.js`)
- Customer controller → Prediction API: requests prediction (evidence: `backend/controllers/customerController.js`)
- Member dashboard → Express server: loads and manages records (evidence: `frontend/src/pages/CustomerManagement.jsx`)
- Prediction API → Trained model: uses model
- Model training → Trained model: produces model
