# utshobbose/fittrack architecture

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

- Interactive diagram: https://gitdiagram.com/utshobbose/fittrack
- Repository: https://github.com/utshobbose/fittrack

## Overview

##### Project type and purpose
- FitTrack is a full-stack fitness management web application. Its goal is to help users manage accounts, calculate BMI/calorie needs, plan meals, track water intake, browse recipes, purchase products, log workouts (including AI-generated yoga and workout routines), view nearby gyms on a map, and monitor progress over time.

##### File structure
- Top-level directories
– frontend: React + Tailwind SPA
– backend: Express.js REST API
- Backend layers (MVC)
– controllers: HTTP handlers for each domain (User, Product, Order, Recipe, Progress, WorkoutAI, YogaAI)
– models: Mongoose schemas for MongoDB
– routes: Route definitions mapping URLs to controllers
– middleware: Authentication (AuthMiddleware)
– server.js: App setup, middleware registration, route mounting, DB connection
- Frontend structure
– public: static assets (audio files)
– src/components: reusable UI pieces (BMI calculator, trackers, lists, forms, cards, AI generators, video/music grids)
– src/pages: top-level routes/views (home, dashboard, shop, checkout, trackers, AI pages, 404)
– src/context: React Context providers for API calls and authentication state
– build/config: Vite, Tailwind, ESLint, PostCSS, Vercel config

##### README insights
- Tech stack: React, Tailwind CSS, Express.js, MongoDB
- External integrations: Open Street Maps API (gym locator), Groq AI API (yoga/workout routine generation)

a. Main components
1. Client (Browser) – React SPA served via Vite/production build
2. API Gateway / Web Server – Express.js app in Node.js
3. Database – MongoDB (self-hosted or Atlas)
4. External Services –
- Open Street Maps API
- Groq AI API
5. Static Asset Storage – CDN or Node static server for public/music files
b. Relationships & interactions
- Browser ↔︎ Express API over HTTPS (REST endpoints)
- Express → MongoDB via Mongoose driver
- Express → Open Street Maps API for gym location lookups
- Express → Groq AI API for yoga/workout routine generation
- Browser state management via React Context for auth and API layer
- Static assets served from /public or CDN
c. Architectural patterns
- Backend: Monolithic RESTful service following MVC (Models/Controllers/Routes) + middleware for auth
- Frontend: Component-based SPA, client-side routing, context for cross-cutting concerns
- Separation of concerns: UI, business logic, data layer separated across tiers
d. Key technologies & libraries
- Frontend: React, React Router, Tailwind CSS, Vite, PostCSS
- Backend: Node.js, Express.js, Mongoose, JSON Web Tokens (AuthMiddleware)
- Database: MongoDB
- External APIs: Open Street Maps, Groq AI

##### Detail
- Break the backend into its modules: AuthMiddleware intercepts → Route handlers dispatch to Controller → Controller uses Models → Models talk to MongoDB
- On the frontend, illustrate how Context wraps the App, how pages import components, and how API calls flow through the context layer
- Edge-case flows: public vs. protected routes, error handling paths

## Diagram (Mermaid)

```mermaid
graph TB
    %% Presentation Tier
    subgraph "Presentation Tier (Frontend)"
        direction TB
        ReactSPA["React SPA"]:::front
        MainJS["SPA Entry Point\n(main.jsx)"]:::front
        HTML["HTML Template\n(index.html)"]:::front
        subgraph "Pages"
            direction TB
            HomePage["HomePage.jsx"]:::front
            DashboardPage["DashboardPage.jsx"]:::front
            ShopPage["ShopPage.jsx"]:::front
            WorkoutVideoPage["WorkoutVideoPage.jsx"]:::front
            YogaMeditationPage["YogaMeditationPage.jsx"]:::front
            Page404["404Page.jsx"]:::front
        end
        subgraph "Shared Components"
            direction TB
            BMICalc["BMI Calculator"]:::front
            WaterTracker["Water Intake Tracker"]:::front
            RecipeCard["Recipe Card"]:::front
            WorkoutGrid["Workout Video Grid"]:::front
            YogaGen["Yoga AI Generator"]:::front
            GymMap["Gym Locator Map"]:::front
        end
        subgraph "Context Providers"
            direction TB
            AuthContext["Auth Context"]:::front
            APIContext["API Context"]:::front
        end
        StaticAssets["Static Assets\n(music files)"]:::front
        subgraph "Build & Config"
            direction TB
            TailwindConfig["tailwind.config.js"]:::front
            ViteConfig["vite.config.js"]:::front
            ESLintConfig["eslint.config.js"]:::front
        end
    end

    %% Application Tier
    subgraph "Application Tier (Backend)"
        direction TB
        Server["Express Server"]:::backend
        AuthMid["AuthMiddleware"]:::backend
        subgraph "Routing Layer"
            direction TB
            UserRoutes["UserRoutes.js"]:::backend
            ProductRoutes["ProductRoutes.js"]:::backend
            OrderRoutes["OrderRoutes.js"]:::backend
            RecipeRoutes["RecipeRoutes.js"]:::backend
            ProgressRoutes["ProgressRoutes.js"]:::backend
            WorkoutAIRoutes["WorkoutAIRoutes.js"]:::backend
            YogaAIRoutes["YogaAIRoutes.js"]:::backend
        end
        subgraph "Controller Layer"
            direction TB
            UserController["UserController.js"]:::backend
            ProductController["ProductController.js"]:::backend
            OrderController["OrderController.js"]:::backend
            RecipeController["RecipeController.js"]:::backend
            WorkoutAIController["WorkoutAIController.js"]:::backend
            YogaAIController["YogaAIController.js"]:::backend
        end
        subgraph "Model Layer"
            direction TB
            UserModel["UserModel.js"]:::backend
            ProductModel["ProductModel.js"]:::backend
            OrderModel["OrderModel.js"]:::backend
            RecipeModel["RecipeModel.js"]:::backend
            ProgressModel["ProgressModel.js"]:::backend
            WorkoutAIModel["WorkoutAIModel.js"]:::backend
            YogaAIModel["YogaAIModel.js"]:::backend
        end
    end

    %% Data Tier & External
    subgraph "Data & External Services"
        direction TB
        MongoDB["MongoDB"]:::db
        OpenStreetMaps["OpenStreetMaps API"]:::ext
        GroqAI["Groq AI API"]:::ext
    end

    %% Connections
    ReactSPA -->|"HTTPS REST"| Server
    ReactSPA --> AuthContext
    ReactSPA --> APIContext
    MainJS --> ReactSPA
    HTML --> ReactSPA
    Server --> AuthMid
    AuthMid --> UserRoutes
    AuthMid --> ProductRoutes
    AuthMid --> OrderRoutes
    AuthMid --> RecipeRoutes
    AuthMid --> ProgressRoutes
    AuthMid --> WorkoutAIRoutes
    AuthMid --> YogaAIRoutes
    UserRoutes --> UserController
    ProductRoutes --> ProductController
    OrderRoutes --> OrderController
    RecipeRoutes --> RecipeController
    ProgressRoutes --> RecipeController
    WorkoutAIRoutes --> WorkoutAIController
    YogaAIRoutes --> YogaAIController
    UserController --> UserModel
    ProductController --> ProductModel
    OrderController --> OrderModel
    RecipeController --> RecipeModel
    WorkoutAIController --> WorkoutAIModel
    YogaAIController --> YogaAIModel
    WorkoutAIController --> GroqAI
    YogaAIController --> GroqAI
    UserModel --> MongoDB
    ProductModel --> MongoDB
    OrderModel --> MongoDB
    RecipeModel --> MongoDB
    ProgressModel --> MongoDB
    WorkoutAIModel --> MongoDB
    YogaAIModel --> MongoDB
    Server --> MongoDB
    Server --> OpenStreetMaps

    %% Click Events
    click ReactSPA "https://github.com/utshobbose/fittrack/tree/main/frontend/src"
    click MainJS "https://github.com/utshobbose/fittrack/blob/main/frontend/src/main.jsx"
    click HTML "https://github.com/utshobbose/fittrack/blob/main/frontend/index.html"
    click HomePage "https://github.com/utshobbose/fittrack/blob/main/frontend/src/pages/homepage.jsx"
    click DashboardPage "https://github.com/utshobbose/fittrack/blob/main/frontend/src/pages/dashboardpage.jsx"
    click ShopPage "https://github.com/utshobbose/fittrack/blob/main/frontend/src/pages/shoppage.jsx"
    click WorkoutVideoPage "https://github.com/utshobbose/fittrack/blob/main/frontend/src/pages/workoutvideopage.jsx"
    click YogaMeditationPage "https://github.com/utshobbose/fittrack/blob/main/frontend/src/pages/yogameditationpage.jsx"
    click Page404 "https://github.com/utshobbose/fittrack/blob/main/frontend/src/pages/404page.jsx"
    click BMICalc "https://github.com/utshobbose/fittrack/blob/main/frontend/src/components/bmi.jsx"
    click WaterTracker "https://github.com/utshobbose/fittrack/blob/main/frontend/src/components/WaterIntakeTracker.jsx"
    click RecipeCard "https://github.com/utshobbose/fittrack/blob/main/frontend/src/components/recipe.jsx"
    click WorkoutGrid "https://github.com/utshobbose/fittrack/blob/main/frontend/src/components/workoutvideogrid.jsx"
    click YogaGen "https://github.com/utshobbose/fittrack/blob/main/frontend/src/components/yogaAIgenerator.jsx"
    click GymMap "https://github.com/utshobbose/fittrack/blob/main/frontend/src/components/gymmap.jsx"
    click AuthContext "https://github.com/utshobbose/fittrack/blob/main/frontend/src/context/authcontext.jsx"
    click APIContext "https://github.com/utshobbose/fittrack/blob/main/frontend/src/context/api.jsx"
    click StaticAssets "https://github.com/utshobbose/fittrack/tree/main/frontend/public/music/"
    click TailwindConfig "https://github.com/utshobbose/fittrack/blob/main/frontend/tailwind.config.js"
    click ViteConfig "https://github.com/utshobbose/fittrack/blob/main/frontend/vite.config.js"
    click ESLintConfig "https://github.com/utshobbose/fittrack/blob/main/frontend/eslint.config.js"
    click Server "https://github.com/utshobbose/fittrack/blob/main/backend/server.js"
    click AuthMid "https://github.com/utshobbose/fittrack/blob/main/backend/middleware/AuthMiddleware.js"
    click UserRoutes "https://github.com/utshobbose/fittrack/blob/main/backend/routes/UserRoutes.js"
    click ProductRoutes "https://github.com/utshobbose/fittrack/blob/main/backend/routes/ProductRoutes.js"
    click OrderRoutes "https://github.com/utshobbose/fittrack/blob/main/backend/routes/OrderRoutes.js"
    click RecipeRoutes "https://github.com/utshobbose/fittrack/blob/main/backend/routes/RecipeRoutes.js"
    click ProgressRoutes "https://github.com/utshobbose/fittrack/blob/main/backend/routes/ProgressRoutes.js"
    click WorkoutAIRoutes "https://github.com/utshobbose/fittrack/blob/main/backend/routes/WorkoutAIRoutes.js"
    click YogaAIRoutes "https://github.com/utshobbose/fittrack/blob/main/backend/routes/YogaAIRoutes.js"
    click UserController "https://github.com/utshobbose/fittrack/blob/main/backend/controllers/UserController.js"
    click ProductController "https://github.com/utshobbose/fittrack/blob/main/backend/controllers/ProductController.js"
    click OrderController "https://github.com/utshobbose/fittrack/blob/main/backend/controllers/OrderController.js"
    click RecipeController "https://github.com/utshobbose/fittrack/blob/main/backend/controllers/RecipeController.js"
    click WorkoutAIController "https://github.com/utshobbose/fittrack/blob/main/backend/controllers/WorkoutAIController.js"
    click YogaAIController "https://github.com/utshobbose/fittrack/blob/main/backend/controllers/YogaAIController.js"
    click UserModel "https://github.com/utshobbose/fittrack/blob/main/backend/models/UserModel.js"
    click ProductModel "https://github.com/utshobbose/fittrack/blob/main/backend/models/ProductModel.js"
    click OrderModel "https://github.com/utshobbose/fittrack/blob/main/backend/models/OrderModel.js"
    click RecipeModel "https://github.com/utshobbose/fittrack/blob/main/backend/models/RecipeModel.js"
    click ProgressModel "https://github.com/utshobbose/fittrack/blob/main/backend/models/ProgressModel.js"
    click WorkoutAIModel "https://github.com/utshobbose/fittrack/blob/main/backend/models/WorkoutAIModel.js"
    click YogaAIModel "https://github.com/utshobbose/fittrack/blob/main/backend/models/YogaAIModel.js"

    %% Styles
    classDef front fill:#ADD8E6,stroke:#000
    classDef backend fill:#90EE90,stroke:#000
    classDef db fill:#FFA500,stroke:#000
    classDef ext fill:#D3D3D3,stroke:#000
```
