# shobhit9742/fitbuddy architecture

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

- Interactive diagram: https://gitdiagram.com/shobhit9742/fitbuddy
- Repository: https://github.com/shobhit9742/fitbuddy

## Overview

##### Project Type & Purpose
- FitBuddy is a full-stack fitness-tracking web application.
- Frontend: a React/Vite single-page application (SPA) for workout logging, meal tracking, calculators, and user authentication.
- Backend: a Node.js/Express REST API backed by a JSON-server data store (db.json) providing user, meal, food, and workout endpoints.

##### File Structure
- Top-Level:
– /frontend: React SPA
– /backend: Node/Express API using JSON-server
– README.md, .gitignore, Photos (screenshots)
- Frontend Highlights:
– src/pages (Authentication, Dashboard, Workouts, etc.)
– src/components (sign-in/up forms, calculators, cards, navbar)
– src/api/index.js (API client)
– src/redux (userSlice, store)
– vite.config.js, public/index.html
- Backend Highlights:
– server.js (Express app entry)
– src/routes (User.js, Meal.js)
– src/controllers (User.js, foodController.js, mealController.js)
– src/models (Mongoose-style schemas, but mapped to JSON)
– src/middleware/verifyToken.js (JWT auth)
– src/db.json (data store)

##### README for Additional Insights
- Purpose and feature list (Workout CRUD, meal logging, calculators, admin dashboard).
- Tech stack: React, Redux, Material-UI, JSON-server, Express.
- Deployment: Frontend on Vercel, JSON-server on Render (or local).

a. Main Components
- User’s Browser (SPA client)
- React App:
– Presentation Layer (components & pages)
– State Management (Redux store)
– API Client (src/api/index.js)
- REST API Server (Express):
– Router Layer (src/routes)
– Controller Layer (src/controllers)
– Model Layer (src/models)
– Auth Middleware (verifyToken)
- Data Store: JSON-server (db.json)
- External Hosting Services: Vercel (frontend), Render or local JSON-server (backend)
b. Relationships & Interactions
1. User ⇒ Browser ⇒ React App UI
2. React App dispatches Redux actions → API Client issues HTTP requests
3. Express receives requests → verifyToken (for protected routes) → routes → controllers → model layer → JSON-server reads/writes db.json
4. JSON-server response bubbles back through controllers → Express → JSON payload → React API client → Redux store → UI update
c. Architectural Patterns & Design Principles
- Frontend: Component-based UI, unidirectional data flow (Redux), separation of concerns (pages vs. shared components).
- Backend: MVC-inspired layering (Routes → Controllers → Models), middleware for cross-cutting concerns (authentication).
- RESTful API design, token-based stateless auth (JWT).
d. Key Technologies & Frameworks
- React.js, Vite, Redux, Material-UI (frontend)
- Node.js, Express, JSON-server, JWT (backend)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (5173)" 
        direction TB
        FBrowser["User Browser"]:::external
        subgraph "React App"
            direction TB
            Entry["main.jsx"]:::frontend
            Config["vite.config.js"]:::frontend
            HTML["index.html"]:::frontend
            subgraph "Pages & Components"
                direction TB
                Pages["Pages Directory"]:::frontend
                Components["Shared Components"]:::frontend
            end
            subgraph "State Management"
                direction TB
                Store["Redux Store"]:::frontend
                UserSlice["User Slice"]:::frontend
            end
            APIClient["API Client"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend (5000)"
        direction TB
        BEEntry["server.js"]:::backend
        AuthMW["verifyToken.js"]:::backend
        subgraph "Routes"
            direction TB
            UserRoutes["User Routes"]:::backend
            MealRoutes["Meal Routes"]:::backend
        end
        subgraph "Controllers"
            direction TB
            UserCtrl["User Controller"]:::backend
            MealCtrl["Meal Controller"]:::backend
            FoodCtrl["Food Controller"]:::backend
        end
        subgraph "Models"
            direction TB
            UserModel["User Schema"]:::backend
            FoodModel["Food Schema"]:::backend
            MealsModel["Meals Schema"]:::backend
            WorkoutModel["Workout Schema"]:::backend
            MealsSchema["Additional Meals Schema"]:::backend
        end
    end

    %% Data Store
    Data["db.json"]:::datastore

    %% Hosting Services
    subgraph "Hosting"
        direction TB
        Vercel["Vercel (Frontend)"]:::external
        Render["Render/$env"]:::external
    end

    %% Relationships
    FBrowser -->|"loads"| Entry
    Entry -->|uses config| Config
    Entry -->|serves template| HTML
    Entry -->|renders| Pages
    Entry -->|renders| Components
    Entry -->|connects to| Store
    Entry -->|calls| APIClient
    APIClient -->|"HTTP requests"| BEEntry
    BEEntry -->|"uses"| AuthMW
    AuthMW -->|guards| UserRoutes
    AuthMW -->|guards| MealRoutes
    UserRoutes -->|calls| UserCtrl
    MealRoutes -->|calls| MealCtrl
    MealRoutes -->|calls| FoodCtrl
    UserCtrl -->|accesses| UserModel
    MealCtrl -->|accesses| MealsModel
    MealCtrl -->|accesses| FoodModel
    FoodCtrl -->|accesses| FoodModel
    UserCtrl -->|reads/writes| Data
    MealCtrl -->|reads/writes| Data
    FoodCtrl -->|reads/writes| Data
    Data -->|responds| Controllers
    Vercel -->|"hosts"| Entry
    Render -->|"hosts"| BEEntry

    %% Click Events
    click Entry "https://github.com/shobhit9742/fitbuddy/blob/main/frontend/src/main.jsx"
    click Config "https://github.com/shobhit9742/fitbuddy/blob/main/frontend/vite.config.js"
    click HTML "https://github.com/shobhit9742/fitbuddy/blob/main/frontend/index.html"
    click Pages "https://github.com/shobhit9742/fitbuddy/tree/main/frontend/src/pages"
    click Components "https://github.com/shobhit9742/fitbuddy/tree/main/frontend/src/components"
    click Store "https://github.com/shobhit9742/fitbuddy/blob/main/frontend/src/redux/store.js"
    click UserSlice "https://github.com/shobhit9742/fitbuddy/blob/main/frontend/src/redux/reducers/userSlice.js"
    click APIClient "https://github.com/shobhit9742/fitbuddy/blob/main/frontend/src/api/index.js"
    click BEEntry "https://github.com/shobhit9742/fitbuddy/blob/main/backend/server.js"
    click UserRoutes "https://github.com/shobhit9742/fitbuddy/blob/main/backend/src/routes/User.js"
    click MealRoutes "https://github.com/shobhit9742/fitbuddy/blob/main/backend/src/routes/Meal.js"
    click UserCtrl "https://github.com/shobhit9742/fitbuddy/blob/main/backend/src/controllers/User.js"
    click MealCtrl "https://github.com/shobhit9742/fitbuddy/blob/main/backend/src/controllers/mealController.js"
    click FoodCtrl "https://github.com/shobhit9742/fitbuddy/blob/main/backend/src/controllers/foodController.js"
    click UserModel "https://github.com/shobhit9742/fitbuddy/blob/main/backend/src/models/User.js"
    click FoodModel "https://github.com/shobhit9742/fitbuddy/blob/main/backend/src/models/Food.js"
    click MealsModel "https://github.com/shobhit9742/fitbuddy/blob/main/backend/src/models/Meals.js"
    click WorkoutModel "https://github.com/shobhit9742/fitbuddy/blob/main/backend/src/models/Workout.js"
    click MealsSchema "https://github.com/shobhit9742/fitbuddy/blob/main/backend/src/models/mealsSchema.js"
    click AuthMW "https://github.com/shobhit9742/fitbuddy/blob/main/backend/src/middleware/verifyToken.js"
    click Data "https://github.com/shobhit9742/fitbuddy/blob/main/backend/src/db.json"
    click Vercel "https://github.com/shobhit9742/fitbuddy/blob/main/frontend/vercel.json"
    click Render "https://github.com/shobhit9742/fitbuddy/blob/main/backend/$env.example"

    %% Styles
    classDef frontend fill:#cfe2ff,stroke:#000,stroke-width:1px
    classDef backend fill:#d1e7dd,stroke:#000,stroke-width:1px
    classDef datastore fill:#fcd5ce,stroke:#000,stroke-width:1px
    classDef external fill:#e2e3e5,stroke:#000,stroke-width:1px
```
