# nandhuatgit/sport-fit architecture

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

- Interactive diagram: https://gitdiagram.com/nandhuatgit/sport-fit
- Repository: https://github.com/nandhuatgit/sport-fit

## Overview

1. **Overall shape**
   - This is a **Node.js/Express backend with a static HTML/CSS/JS frontend**.
   - The app is organized around a **modular API layer**, **MongoDB-style data models**, and a **browser-based UI** served from `public/`.

2. **Entry point and server layer**
   - `server.js` is the application bootstrap and likely wires together Express, middleware, routes, static file hosting, and database connection.
   - This is the central coordination point for the whole system.

3. **Frontend boundary**
   - The UI lives in `public/` and is composed of plain HTML pages such as `welcome.html`, `login.html`, `register.html`, `dashboard.html`, `account.html`, and `auth.html`.
   - Client-side behavior is handled by `public/js/auth.js` and `public/js/dashboard.js`, with styling in `public/css/style.css` and `public/style.css`.
   - The frontend is page-based rather than a SPA framework, so the browser talks to backend routes directly and updates the dashboard with fetched data.

4. **Authentication subsystem**
   - `routes/auth.js` handles registration/login flows.
   - `middleware/authMiddleware.js` protects authenticated resources, which suggests token/session-based access control.
   - The README mentions JWT, so the intended architecture is **JWT-backed authentication with guarded API endpoints**.

5. **Core recommendation and user-data subsystem**
   - `routes/user.js` appears to manage user-specific profile or dashboard data.
   - `routes/diet.js` and `routes/sports.js` likely provide the personalized fitness outputs: diet plans and sport/workout recommendations.
   - These routes are the main business logic surface for generating and returning tailored fitness content.

6. **AI / recommendation subsystem**
   - `routes/ai.js` is the entry point for the “AI chat assistant” described in the README.
   - Based on the repository contents, this is probably a **rule-based recommendation/chat layer**, not a heavy ML service.
   - The AI component likely consumes structured sport and fitness rules and returns guidance to the frontend.

7. **Data and domain model layer**
   - The `models/` directory contains `User.js`, `Diet.js`, `Sport.js`, and `History.js`.
   - This suggests a persistence model with:
     - users and authentication state,
     - generated diet plans,
     - sport/workout plans,
     - history or tracking records for past recommendations or user activity.
   - These are the main data boundaries for the backend.

8. **Structured knowledge base**
   - `data/sportsData.js` is a non-database dataset used as a lookup source for sport-specific logic.
   - This file is important architecturally because it likely powers the rule engine and keeps recommendation logic separate from user records.

9. **Request flow**
   - A typical flow is: browser page loads from `public/` → client JS calls an Express route → route uses middleware if needed → route reads from models and/or `sportsData.js` → response is returned to the browser for display in the dashboard or chat UI.
   - Personalized outputs are therefore assembled on the backend, not in the browser.

10. **Persistent state vs. derived state**
   - Persistent state is represented by the models in `models/`, especially user records and history.
   - Derived state is the recommendation output generated from rules and datasets, likely stored only when needed for tracking or dashboard display.

11. **Important boundaries**
   - **Presentation boundary:** static pages and client JS in `public/`.
   - **API boundary:** Express routes in `routes/`.
   - **Access-control boundary:** `middleware/authMiddleware.js`.
   - **Domain/data boundary:** Mongoose-style models and `data/sportsData.js`.
   - This separation is one of the main architectural features of the repo.

12. **Infrastructure and runtime**
   - The repository is built around **Node.js**, **Express**, and a **MongoDB-compatible model layer**.
   - The presence of `.env` indicates environment-based configuration for secrets and connection settings.
   - `package-lock.json` confirms a standard npm-managed backend project.

13. **What to show in an architecture diagram**
   - Put the browser/UI on one side, Express backend in the center, and the database/model layer plus `sportsData.js` as the backend’s data sources.
   - Show auth middleware guarding the user/dashboard/recommendation routes.
   - Show `ai.js`, `diet.js`, `sports.js`, and `user.js` as separate functional modules under the API layer, with `auth.js` as the login/register edge.

14. **Key design takeaway**
   - The repository is a **modular fitness recommendation system** where the backend does the personalization work, the frontend is lightweight and static, and the sport-specific intelligence is driven by a mix of stored models and a structured rule dataset.

Main entry points: [`server.js`](https://github.com/nandhuatgit/sport-fit/blob/master/server.js) (Server), [`public/js/dashboard.js`](https://github.com/nandhuatgit/sport-fit/blob/master/public/js/dashboard.js) (Dashboard JS), [`routes/diet.js`](https://github.com/nandhuatgit/sport-fit/blob/master/routes/diet.js) (Diet API), [`routes/sports.js`](https://github.com/nandhuatgit/sport-fit/blob/master/routes/sports.js) (Sports API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_welcome_page["Welcome<br/>static page<br/>[welcome.html]"]
  node_login_page["Login<br/>static page<br/>[login.html]"]
  node_register_page["Register<br/>static page<br/>[register.html]"]
  node_auth_page["Auth Shell<br/>static page<br/>[auth.html]"]
  node_dashboard_page["Dashboard<br/>static page<br/>[dashboard.html]"]
  node_account_page["Account<br/>static page<br/>[account.html]"]
  node_auth_js["Auth JS<br/>client script<br/>[auth.js]"]
  node_dashboard_js["Dashboard JS<br/>client script<br/>[dashboard.js]"]
  node_style_css["Styles<br/>[style.css]"]
  node_legacy_css["Legacy Styles<br/>stylesheet<br/>[style.css]"]
end

subgraph group_backend["Backend"]
  node_server["Server<br/>express bootstrap<br/>[server.js]"]
  node_auth_route["Auth API<br/>route module<br/>[auth.js]"]
  node_user_route["User API<br/>route module<br/>[user.js]"]
  node_diet_route["Diet API<br/>route module<br/>[diet.js]"]
  node_sports_route["Sports API<br/>route module<br/>[sports.js]"]
  node_ai_route["AI API<br/>route module<br/>[ai.js]"]
  node_auth_mw{{"Auth Guard<br/>middleware<br/>[authMiddleware.js]"}}
end

subgraph group_data["Data"]
  node_user_model[("User<br/>data model<br/>[User.js]")]
  node_diet_model[("Diet<br/>data model<br/>[Diet.js]")]
  node_sport_model[("Sport<br/>data model<br/>[Sport.js]")]
  node_history_model[("History<br/>data model<br/>[History.js]")]
  node_sports_data["Sports Data<br/>lookup dataset<br/>[sportsData.js]"]
end

node_server -->|"mounts"| node_auth_route
node_server -->|"mounts"| node_user_route
node_server -->|"mounts"| node_diet_route
node_server -->|"mounts"| node_sports_route
node_server -->|"mounts"| node_ai_route
node_server -->|"uses"| node_auth_mw
node_auth_route -->|"reads/writes"| node_user_model
node_user_route -->|"protected by"| node_auth_mw
node_user_route -->|"reads/writes"| node_user_model
node_diet_route -->|"protected by"| node_auth_mw
node_diet_route -->|"reads/writes"| node_diet_model
node_diet_route -->|"uses"| node_user_model
node_sports_route -->|"protected by"| node_auth_mw
node_sports_route -->|"reads/writes"| node_sport_model
node_sports_route -->|"consults"| node_sports_data
node_ai_route -->|"protected by"| node_auth_mw
node_ai_route -->|"consults"| node_sports_data
node_ai_route -->|"reads/writes"| node_history_model
node_dashboard_js -->|"calls"| node_user_route
node_dashboard_js -->|"calls"| node_diet_route
node_dashboard_js -->|"calls"| node_sports_route
node_dashboard_js -->|"calls"| node_ai_route
node_auth_js -->|"calls"| node_auth_route
node_welcome_page -->|"navigates"| node_login_page
node_welcome_page -->|"navigates"| node_register_page
node_login_page -->|"uses"| node_auth_js
node_register_page -->|"uses"| node_auth_js
node_dashboard_page -->|"uses"| node_dashboard_js
node_auth_page -->|"uses"| node_auth_js
node_account_page -.->|"uses"| node_dashboard_js
node_server -->|"serves"| node_welcome_page
node_server -->|"serves"| node_dashboard_page
node_server -->|"serves"| node_account_page
node_server -->|"connects"| node_user_model
node_server -->|"connects"| node_history_model

click node_server "https://github.com/nandhuatgit/sport-fit/blob/master/server.js"
click node_auth_route "https://github.com/nandhuatgit/sport-fit/blob/master/routes/auth.js"
click node_user_route "https://github.com/nandhuatgit/sport-fit/blob/master/routes/user.js"
click node_diet_route "https://github.com/nandhuatgit/sport-fit/blob/master/routes/diet.js"
click node_sports_route "https://github.com/nandhuatgit/sport-fit/blob/master/routes/sports.js"
click node_ai_route "https://github.com/nandhuatgit/sport-fit/blob/master/routes/ai.js"
click node_auth_mw "https://github.com/nandhuatgit/sport-fit/blob/master/middleware/authMiddleware.js"
click node_user_model "https://github.com/nandhuatgit/sport-fit/blob/master/models/User.js"
click node_diet_model "https://github.com/nandhuatgit/sport-fit/blob/master/models/Diet.js"
click node_sport_model "https://github.com/nandhuatgit/sport-fit/blob/master/models/Sport.js"
click node_history_model "https://github.com/nandhuatgit/sport-fit/blob/master/models/History.js"
click node_sports_data "https://github.com/nandhuatgit/sport-fit/blob/master/data/sportsData.js"
click node_welcome_page "https://github.com/nandhuatgit/sport-fit/blob/master/public/welcome.html"
click node_login_page "https://github.com/nandhuatgit/sport-fit/blob/master/public/login.html"
click node_register_page "https://github.com/nandhuatgit/sport-fit/blob/master/public/register.html"
click node_auth_page "https://github.com/nandhuatgit/sport-fit/blob/master/public/auth.html"
click node_dashboard_page "https://github.com/nandhuatgit/sport-fit/blob/master/public/dashboard.html"
click node_account_page "https://github.com/nandhuatgit/sport-fit/blob/master/public/account.html"
click node_auth_js "https://github.com/nandhuatgit/sport-fit/blob/master/public/js/auth.js"
click node_dashboard_js "https://github.com/nandhuatgit/sport-fit/blob/master/public/js/dashboard.js"
click node_style_css "https://github.com/nandhuatgit/sport-fit/blob/master/public/css/style.css"
click node_legacy_css "https://github.com/nandhuatgit/sport-fit/blob/master/public/style.css"

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_welcome_page,node_login_page,node_register_page,node_auth_page,node_dashboard_page,node_account_page,node_auth_js,node_dashboard_js,node_style_css,node_legacy_css toneBlue
class node_server,node_auth_route,node_user_route,node_diet_route,node_sports_route,node_ai_route,node_auth_mw toneAmber
class node_user_model,node_diet_model,node_sport_model,node_history_model,node_sports_data toneMint
```

## Components

### Frontend

Static browser UI and client scripts

- [Welcome](https://github.com/nandhuatgit/sport-fit/blob/master/public/welcome.html): static page · Public landing page · `public/welcome.html`
- [Login](https://github.com/nandhuatgit/sport-fit/blob/master/public/login.html): static page · Login form page · `public/login.html`
- [Register](https://github.com/nandhuatgit/sport-fit/blob/master/public/register.html): static page · Account creation page · `public/register.html`
- [Auth Shell](https://github.com/nandhuatgit/sport-fit/blob/master/public/auth.html): static page · Authentication-related browser entry page · `public/auth.html`
- [Dashboard](https://github.com/nandhuatgit/sport-fit/blob/master/public/dashboard.html): static page · Main authenticated user dashboard · `public/dashboard.html`
- [Account](https://github.com/nandhuatgit/sport-fit/blob/master/public/account.html): static page · Account details page · `public/account.html`
- [Auth JS](https://github.com/nandhuatgit/sport-fit/blob/master/public/js/auth.js): client script · Handles login and registration interactions · `public/js/auth.js`
- [Dashboard JS](https://github.com/nandhuatgit/sport-fit/blob/master/public/js/dashboard.js): client script · Fetches and renders personalized dashboard data · `public/js/dashboard.js`
- [Styles](https://github.com/nandhuatgit/sport-fit/blob/master/public/css/style.css): stylesheet · Shared page styling · `public/css/style.css`
- [Legacy Styles](https://github.com/nandhuatgit/sport-fit/blob/master/public/style.css): stylesheet · Additional top-level styling file · `public/style.css`

### Backend

Express server, routes, and middleware

- [Server](https://github.com/nandhuatgit/sport-fit/blob/master/server.js): express bootstrap · Application entry point that wires middleware, routes, static hosting, and database setup · `server.js`
- [Auth API](https://github.com/nandhuatgit/sport-fit/blob/master/routes/auth.js): route module · Registration and login endpoints · `routes/auth.js`
- [User API](https://github.com/nandhuatgit/sport-fit/blob/master/routes/user.js): route module · User profile and dashboard-related endpoints · `routes/user.js`
- [Diet API](https://github.com/nandhuatgit/sport-fit/blob/master/routes/diet.js): route module · Diet plan generation and retrieval endpoints · `routes/diet.js`
- [Sports API](https://github.com/nandhuatgit/sport-fit/blob/master/routes/sports.js): route module · Workout and sport recommendation endpoints · `routes/sports.js`
- [AI API](https://github.com/nandhuatgit/sport-fit/blob/master/routes/ai.js): route module · Chat assistant and recommendation orchestration endpoints · `routes/ai.js`
- [Auth Guard](https://github.com/nandhuatgit/sport-fit/blob/master/middleware/authMiddleware.js): middleware · Protects authenticated routes and gates access to user data · `middleware/authMiddleware.js`

### Data

Persistent models and lookup data

- [User](https://github.com/nandhuatgit/sport-fit/blob/master/models/User.js): data model · Stored user identity and account state · `models/User.js`
- [Diet](https://github.com/nandhuatgit/sport-fit/blob/master/models/Diet.js): data model · Persisted diet plan records · `models/Diet.js`
- [Sport](https://github.com/nandhuatgit/sport-fit/blob/master/models/Sport.js): data model · Persisted sport or workout plan records · `models/Sport.js`
- [History](https://github.com/nandhuatgit/sport-fit/blob/master/models/History.js): data model · Stored recommendation or activity history · `models/History.js`
- [Sports Data](https://github.com/nandhuatgit/sport-fit/blob/master/data/sportsData.js): lookup dataset · Structured sport knowledge used by recommendation logic · `data/sportsData.js`

## Connections

- Server → Auth API: mounts · Registers authentication endpoints
- Server → User API: mounts · Registers user endpoints
- Server → Diet API: mounts · Registers diet endpoints
- Server → Sports API: mounts · Registers sport endpoints
- Server → AI API: mounts · Registers AI/chat endpoints
- Server → Auth Guard: uses · Applies access control to protected routes
- Auth API → User: reads/writes · Creates and authenticates users
- User API → Auth Guard: protected by · Requires authenticated access
- User API → User: reads/writes · Loads and updates user data
- Diet API → Auth Guard: protected by · Requires authenticated access
- Diet API → Diet: reads/writes · Persists diet plans
- Diet API → User: uses · Associates plans with a user
- Sports API → Auth Guard: protected by · Requires authenticated access
- Sports API → Sport: reads/writes · Persists workout plans
- Sports API → Sports Data: consults · Uses structured sport knowledge
- AI API → Auth Guard: protected by · Requires authenticated access
- AI API → Sports Data: consults · Uses sport rules and lookup data
- AI API → History: reads/writes · Stores assistant or recommendation history
- Dashboard JS → User API: calls · Fetches user-specific dashboard data
- Dashboard JS → Diet API: calls · Loads diet recommendations
- Dashboard JS → Sports API: calls · Loads sport recommendations
- Dashboard JS → AI API: calls · Sends chat and assistant requests
- Auth JS → Auth API: calls · Submits login and registration requests
- Welcome → Login: navigates · Entry path into authentication
- Welcome → Register: navigates · Entry path into account creation
- Login → Auth JS: uses · Client-side auth behavior
- Register → Auth JS: uses · Client-side auth behavior
- Dashboard → Dashboard JS: uses · Client-side dashboard behavior
- Auth Shell → Auth JS: uses · Shared auth interaction layer
- Account → Dashboard JS: uses · Reuses dashboard-style data fetching
- Server → Welcome: serves · Exposes public static pages
- Server → Dashboard: serves · Exposes authenticated UI pages
- Server → Account: serves · Exposes authenticated UI pages
- Server → User: connects · Uses database-backed domain models
- Server → History: connects · Uses database-backed domain models
