How nandhuatgit/sport-fit works
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 Server · dashboard.js Dashboard JS · diet.js Diet API · sports.js Sports API
Components 22
Frontend
Static browser UI and client scripts
- Welcome · Public landing page
public/welcome.html - Login · Login form page
public/login.html - Register · Account creation page
public/register.html - Auth Shell · Authentication-related browser entry page
public/auth.html - Dashboard · Main authenticated user dashboard
public/dashboard.html - Account · Account details page
public/account.html - Auth JS · Handles login and registration interactions
public/js/auth.js - Dashboard JS · Fetches and renders personalized dashboard data
public/js/dashboard.js - Styles · Shared page styling
public/css/style.css - Legacy Styles · Additional top-level styling file
public/style.css
Backend
Express server, routes, and middleware
- Server · Application entry point that wires middleware, routes, static hosting, and database setup
server.js - Auth API · Registration and login endpoints
routes/auth.js - User API · User profile and dashboard-related endpoints
routes/user.js - Diet API · Diet plan generation and retrieval endpoints
routes/diet.js - Sports API · Workout and sport recommendation endpoints
routes/sports.js - AI API · Chat assistant and recommendation orchestration endpoints
routes/ai.js - Auth Guard · Protects authenticated routes and gates access to user data
middleware/authMiddleware.js
Data
Persistent models and lookup data
- User · Stored user identity and account state
models/User.js - Diet · Persisted diet plan records
models/Diet.js - Sport · Persisted sport or workout plan records
models/Sport.js - History · Stored recommendation or activity history
models/History.js - Sports Data · Structured sport knowledge used by recommendation logic
data/sportsData.js
Connections 35
- 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