# divyasinha111/fitness_hub architecture

> Architecture diagram of the GitHub repository divyasinha111/fitness_hub, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/divyasinha111/fitness_hub
- Repository: https://github.com/divyasinha111/fitness_hub

## Overview

##### Project Type and Purpose
- This is a full-stack web application: a fitness platform built with a React/Vite frontend, an Express/Node backend, and a database (likely MongoDB via Mongoose).
- Purpose: deliver interactive fitness tools (calculators, AI-driven workout planner, nutrition guides, yoga/meditation pages) through a SPA interface with persistent user data and personalization.

##### File Structure Analysis
a. Top-level
- README.md, .gitignore, vite.config.js – project metadata and build config for the frontend.
- package.json (root) and package-lock.json – defines frontend dependencies and scripts.
- public/ and index.html – static assets for the React app.
- src/ – React application source code.
- backend/ – Express server code, environment file, route definitions, separate Node package.json.
- model/ – Mongoose user schema (used by the backend).
b. Frontend Patterns (src/)
- pages/ – feature pages (BMI, Body Fat, AI Workout, etc.)
- components/ – reusable UI (Navbar, Footer, ScrollToTop)
- context/ – application-wide state (ThemeContext)
c. Backend (backend/)
- server.js / server.jsx – Express app entry point
- routes/userroutes.js – RESTful endpoints (/register, /login, user profiles, etc.)
- .env – secrets (e.g., MONGODB_URI, JWT_SECRET)
d. Model (model/)
- user.js – Mongoose schema for user accounts and profile data
e. Key configuration: vite.config.js for frontend bundling, package.json scripts for build/start.

##### README Insights
- Lists core user-facing features (calculators, AI planner, nutrition, yoga)
- Tech stack callout: ReactJS (frontend), CSS3/HTML5, APIs
- Implies a backend API layer for personalization and AI calls.

a. Main Components
1. Client (Browser) / React SPA
2. Static Asset Host (served via Vite dev server or built files hosted on a CDN/server)
3. Backend API Server (Express/Node)
4. Database (MongoDB via Mongoose)
5. External AI Service (for AI-powered workout planner)
6. (Optional) Authentication Service or JWT layer
b. Relationships & Data Flow
- User’s browser → HTTP(S) requests → Static assets (index.html + JS bundle) → Render React app
- React app → AJAX/Fetch calls to Express API endpoints (e.g., /api/users, /api/calories)
- Express routes invoke Mongoose models → CRUD operations on MongoDB
- For AI planner: Express server → calls out to external AI REST/GraphQL API → processes response → returns plan to frontend
- Frontend consumes JSON responses, updates UI, persists tokens in localStorage or cookies
c. Architectural Patterns & Principles
- SPA with clear separation of concerns (UI vs. API)
- RESTful API for backend services
- MVC-style layering in backend (Routes → Controllers/Models)
- Context API for global state on frontend (theming, user auth state)
- Component-based UI for isolation and reusability
d. Technologies & Libraries
- Frontend: React, Vite, React Router (implied via pages folder), Context API, CSS Modules or scoped CSS
- Backend: Node.js, Express, dotenv, Mongoose
- Database: MongoDB (self-hosted or Atlas)
- External: AI-free/openAI or custom ML microservice
- DevOps: npm scripts, possible CI/CD (not shown but inferable)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        direction TB
        Browser["User Browser"]:::frontend
        CDN["Static Asset Host (public/index.html)"]:::frontend
        RootPkg["Root package.json"]:::frontend
        Config["Vite Configuration (vite.config.js)"]:::frontend
        Main["React Entry (src/main.jsx)"]:::frontend
        App["App Component (src/App.jsx)"]:::frontend
        Styles["Global Stylesheet (src/index.css)"]:::frontend
        Context["Theme Context (src/context/ThemeContext.jsx)"]:::frontend
        subgraph "UI Components"
            Scroll["ScrollToTop.jsx"]:::frontend
            Navbar["Navbar.jsx"]:::frontend
            Footer["Footer.jsx"]:::frontend
        end
        subgraph "Feature Pages"
            Home["Home.jsx"]:::frontend
            BMI["BmiCalculator.jsx"]:::frontend
            BodyFat["BodyFatCalculator.jsx"]:::frontend
            Calorie["CalorieCalculator.jsx"]:::frontend
            Conception["Conception.jsx"]:::frontend
            ExercisesList["ExercisesList.jsx"]:::frontend
            Exercises["Exercises.jsx"]:::frontend
            Nutrition["Nutrition.jsx"]:::frontend
            Periods["PeriodsCalculator.jsx"]:::frontend
            Pregnancy["PregnancyWeightGainCalculator.jsx"]:::frontend
            WorkoutPlanner["WorkoutPlanner.jsx"]:::frontend
            Yoga["Yoga.jsx"]:::frontend
            Carousel["Carousel.jsx"]:::frontend
        end
        Browser -->|"GET /"| CDN
        CDN -->|"Serves bundle"| Main
        RootPkg -->|defines scripts| Config
        Config -->|"builds assets"| CDN
        Main -->|"renders"| App
        App --> Context
        App -->|"uses"| Scroll
        App --> Navbar
        App --> Footer
        App -->|"routes to"| Home
        App -->|"routes to"| BMI
        App -->|"routes to"| BodyFat
        App -->|"routes to"| Calorie
        App -->|"routes to"| Conception
        App -->|"routes to"| ExercisesList
        App -->|"routes to"| Exercises
        App -->|"routes to"| Nutrition
        App -->|"routes to"| Periods
        App -->|"routes to"| Pregnancy
        App -->|"routes to"| WorkoutPlanner
        App -->|"routes to"| Yoga
        App -->|"routes to"| Carousel
    end

    %% Backend Layer
    subgraph "Backend"
        direction TB
        Express["Express API Server (backend/server.js)"]:::backend
        Env["Environment (.env)"]:::backend
        Routes["User Routes (backend/routes/userroutes.js)"]:::backend
        BackendPkg["Backend package.json"]:::backend
        Express --> Routes
        Express --> Env
        BackendPkg --> Express
    end

    %% Database Layer
    subgraph "Database"
        direction TB
        UserModel["User Model (model/user.js)"]:::db
        Mongo["MongoDB"]:::db
        Routes --> UserModel
        UserModel --> Mongo
    end

    %% External Services
    ExternalAI["External AI Service"]:::external

    %% Data Flows
    App -->|AJAX calls| Express
    Express -->|JSON responses| App
    Express -->|request workout plan| ExternalAI
    ExternalAI -->|response| Express

    %% Click Events
    click Main "https://github.com/divyasinha111/fitness_hub/blob/main/src/main.jsx"
    click App "https://github.com/divyasinha111/fitness_hub/blob/main/src/App.jsx"
    click CDN "https://github.com/divyasinha111/fitness_hub/blob/main/public/index.html"
    click Config "https://github.com/divyasinha111/fitness_hub/blob/main/vite.config.js"
    click Styles "https://github.com/divyasinha111/fitness_hub/blob/main/src/index.css"
    click Context "https://github.com/divyasinha111/fitness_hub/blob/main/src/context/ThemeContext.jsx"
    click Scroll "https://github.com/divyasinha111/fitness_hub/blob/main/src/components/ScrollToTop.jsx"
    click Navbar "https://github.com/divyasinha111/fitness_hub/blob/main/src/components/navbar/Navbar.jsx"
    click Footer "https://github.com/divyasinha111/fitness_hub/blob/main/src/components/footer/Footer.jsx"
    click Home "https://github.com/divyasinha111/fitness_hub/blob/main/src/pages/Home/Home.jsx"
    click BMI "https://github.com/divyasinha111/fitness_hub/blob/main/src/pages/BMICalculator/BmiCalculator.jsx"
    click BodyFat "https://github.com/divyasinha111/fitness_hub/blob/main/src/pages/BodyFatCalculator/BodyFatCalculator.jsx"
    click Calorie "https://github.com/divyasinha111/fitness_hub/blob/main/src/pages/CalorieCalculator/CalorieCalculator.jsx"
    click Conception "https://github.com/divyasinha111/fitness_hub/blob/main/src/pages/Conception/Conception.jsx"
    click ExercisesList "https://github.com/divyasinha111/fitness_hub/blob/main/src/pages/ExercisesList/ExercisesList.jsx"
    click Exercises "https://github.com/divyasinha111/fitness_hub/blob/main/src/pages/Exercises/Exercises.jsx"
    click Nutrition "https://github.com/divyasinha111/fitness_hub/blob/main/src/pages/Nutrition/Nutrition.jsx"
    click Periods "https://github.com/divyasinha111/fitness_hub/blob/main/src/pages/PeriodsCalculator/PeriodsCalculator.jsx"
    click Pregnancy "https://github.com/divyasinha111/fitness_hub/blob/main/src/pages/PregnancyWeightGainCalculator/PregnancyWeightGainCalculator.jsx"
    click WorkoutPlanner "https://github.com/divyasinha111/fitness_hub/blob/main/src/pages/WorkoutPlanner/WorkoutPlanner.jsx"
    click Yoga "https://github.com/divyasinha111/fitness_hub/blob/main/src/pages/Yoga/Yoga.jsx"
    click Carousel "https://github.com/divyasinha111/fitness_hub/blob/main/src/pages/carousel/Carousel.jsx"
    click Express "https://github.com/divyasinha111/fitness_hub/blob/main/backend/server.js"
    click Env "https://github.com/divyasinha111/fitness_hub/blob/main/backend/.env"
    click Routes "https://github.com/divyasinha111/fitness_hub/blob/main/backend/routes/userroutes.js"
    click BackendPkg "https://github.com/divyasinha111/fitness_hub/blob/main/backend/package.json"
    click UserModel "https://github.com/divyasinha111/fitness_hub/blob/main/model/user.js"
    click RootPkg "https://github.com/divyasinha111/fitness_hub/blob/main/package.json"

    %% Styles
    classDef frontend fill:#D6E9FF,stroke:#3B73B8,color:#000000
    classDef backend fill:#DFFFE0,stroke:#4CAF50,color:#000000
    classDef db fill:#FFF3CD,stroke:#FFCA28,color:#000000
    classDef external fill:#F0F0F0,stroke:#A0A0A0,color:#000000
```
