# chin-ma/fitmate-frontend architecture

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

- Interactive diagram: https://gitdiagram.com/chin-ma/fitmate-frontend
- Repository: https://github.com/chin-ma/fitmate-frontend

## Overview

##### Project type and purpose
- FitMate AI is a personal fitness coaching platform. It’s a full-stack web application with a Next.js (React/TypeScript) frontend MVP and a future Python/Flask backend, integrating AI/ML (Google Gemini) and MongoDB.

##### File structure
- Top-level directories:
- app/ – Next.js “app router” pages and API routes
- components/ – UI and feature components (shadcn/ui, dashboard, workout, etc.)
- lib/ – shared types and utility functions
- public/ – static assets
- Key files: next.config.ts, tsconfig.json, postcss.config.mjs
- app/api/... contains route.ts files that implement serverless API endpoints for chat, diet recommendations, food analyze, posture analyze, and user updates.

##### README for additional insights
- Tech stack: Next.js, Tailwind CSS, shadcn/ui
- Backend, AI engine, and database are “coming soon” (Flask, Google Gemini, MongoDB)
- Features include AI-powered workout plans, dynamic adaptation, chat interface, food analysis.

##### Diagramming strategy
a. Main components
- User (Browser/Mobile app)
- Next.js Frontend
– UI layer (components/ui, components/dashboard, app/layout.tsx)
– Pages (app/page.tsx, app/dashboard/*, app/auth/login/page.tsx)
- Next.js API layer (app/api/*)
- External AI Engine (Google Gemini)
- Future Backend Service (Python/Flask)
- Database (MongoDB)
- Authentication Service (JWT email auth)
b. Relationships & interactions
1. User interacts with Next.js frontend over HTTPS
2. Frontend fetches data or posts user input to Next.js API routes
3. API routes either:
– Call Google Gemini AI (e.g., food analysis, chat)
– Connect to the future Flask backend for workout plans, user data
4. Backend persists/retrieves data in MongoDB
5. JWT tokens issued/validated by Auth service (could be part of Flask backend)
c. Architectural patterns
- Serverless/API-route layer within Next.js
- Component-based UI with shadcn/ui for reusable design
- Layered separation: UI → API → Business logic → Data store
d. Key technologies
- Next.js app router & serverless functions
- React + TypeScript + Tailwind CSS + shadcn/ui
- Google Gemini for AI/ML calls
- Python Flask microservices (planned)
- MongoDB document store
- JWT for auth

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        Browser["User Browser"]:::frontend
        subgraph "Next.js Frontend (App Router)"
            direction TB
            AppDir["app/"]:::frontend
            EntryLayout["app/layout.tsx"]:::frontend
            EntryPage["app/page.tsx"]:::frontend
            subgraph "Dashboard Pages"
                direction TB
                DashLayout["app/dashboard/layout.tsx"]:::frontend
                DashPage["app/dashboard/page.tsx"]:::frontend
                DashChat["app/dashboard/chat/page.tsx"]:::frontend
                DashDaily["app/dashboard/daily-update/page.tsx"]:::frontend
                DashRec["app/dashboard/exercises/recommended/page.tsx"]:::frontend
                DashOnboard["app/dashboard/onboarding/page.tsx"]:::frontend
                DashWorkout["app/dashboard/workout/page.tsx"]:::frontend
            end
            AuthPage["app/auth/login/page.tsx"]:::frontend
            UIlib["components/ui/"]:::frontend
            Header["components/header.tsx"]:::frontend
            Logo["components/logo.tsx"]:::frontend
            Sidebar["components/dashboard/sidebar.tsx"]:::frontend
            AIChatComp["components/dashboard/ai-chat.tsx"]:::frontend
            DailyComp["components/daily-update/daily-update.tsx"]:::frontend
            OnboardForm["components/onboarding/onboarding-form.tsx"]:::frontend
            PostureComp["components/posture-check/posture-check.tsx"]:::frontend
            WorkoutComp["components/workout/workout-detail.tsx"]:::frontend
            Public["public/"]:::frontend
            Types["lib/types.ts"]:::frontend
            Utils["lib/utils.ts"]:::frontend
        end
    end

    %% API Layer
    subgraph "API Layer (Next.js Serverless)" 
        direction TB
        ChatAPI["/api/chat"]:::api
        DietAPI["/api/diet/recommended"]:::api
        FoodAPI["/api/food/analyze"]:::api
        PostureAPI["/api/posture/analyze"]:::api
        UpdateAPI["/api/user/update_workout_status"]:::api
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        Gemini["Google Gemini AI"]:::external
        Flask["Flask Backend (coming soon)"]:::service
    end

    %% Data Layer
    Mongo["MongoDB"]:::external

    %% Connections
    Browser --> AppDir
    AppDir --> EntryLayout
    EntryLayout --> EntryPage
    AppDir --> DashLayout
    DashLayout --> DashPage
    DashLayout --> DashChat
    DashLayout --> DashDaily
    DashLayout --> DashRec
    DashLayout --> DashOnboard
    DashLayout --> DashWorkout
    AppDir --> AuthPage
    AppDir --> UIlib
    UIlib --> Header
    UIlib --> Logo
    UIlib --> Sidebar
    UIlib --> AIChatComp
    UIlib --> DailyComp
    UIlib --> OnboardForm
    UIlib --> PostureComp
    UIlib --> WorkoutComp
    AppDir --> Public
    AppDir --> Types
    AppDir --> Utils

    EntryPage --> ChatAPI
    DashPage --> DietAPI
    AuthPage --> UpdateAPI
    DashChat --> ChatAPI
    DashDaily --> UpdateAPI
    DashRec --> DietAPI
    DashOnboard --> UpdateAPI
    DashWorkout --> UpdateAPI

    ChatAPI -->|"calls AI"| Gemini
    FoodAPI -->|"image→analysis"| Gemini
    PostureAPI -->|"image→posture"| Gemini

    DietAPI --> Flask
    UpdateAPI --> Flask

    Flask --> Mongo

    %% Click Events
    click AppDir "https://github.com/chin-ma/fitmate-frontend/tree/main/app/"
    click EntryLayout "https://github.com/chin-ma/fitmate-frontend/blob/main/app/layout.tsx"
    click EntryPage "https://github.com/chin-ma/fitmate-frontend/blob/main/app/page.tsx"
    click DashLayout "https://github.com/chin-ma/fitmate-frontend/blob/main/app/dashboard/layout.tsx"
    click DashPage "https://github.com/chin-ma/fitmate-frontend/blob/main/app/dashboard/page.tsx"
    click DashChat "https://github.com/chin-ma/fitmate-frontend/blob/main/app/dashboard/chat/page.tsx"
    click DashDaily "https://github.com/chin-ma/fitmate-frontend/blob/main/app/dashboard/daily-update/page.tsx"
    click DashRec "https://github.com/chin-ma/fitmate-frontend/blob/main/app/dashboard/exercises/recommended/page.tsx"
    click DashOnboard "https://github.com/chin-ma/fitmate-frontend/blob/main/app/dashboard/onboarding/page.tsx"
    click DashWorkout "https://github.com/chin-ma/fitmate-frontend/blob/main/app/dashboard/workout/page.tsx"
    click AuthPage "https://github.com/chin-ma/fitmate-frontend/blob/main/app/auth/login/page.tsx"
    click UIlib "https://github.com/chin-ma/fitmate-frontend/tree/main/components/ui/"
    click Header "https://github.com/chin-ma/fitmate-frontend/blob/main/components/header.tsx"
    click Logo "https://github.com/chin-ma/fitmate-frontend/blob/main/components/logo.tsx"
    click Sidebar "https://github.com/chin-ma/fitmate-frontend/blob/main/components/dashboard/sidebar.tsx"
    click AIChatComp "https://github.com/chin-ma/fitmate-frontend/blob/main/components/dashboard/ai-chat.tsx"
    click DailyComp "https://github.com/chin-ma/fitmate-frontend/blob/main/components/daily-update/daily-update.tsx"
    click OnboardForm "https://github.com/chin-ma/fitmate-frontend/blob/main/components/onboarding/onboarding-form.tsx"
    click PostureComp "https://github.com/chin-ma/fitmate-frontend/blob/main/components/posture-check/posture-check.tsx"
    click WorkoutComp "https://github.com/chin-ma/fitmate-frontend/blob/main/components/workout/workout-detail.tsx"
    click Types "https://github.com/chin-ma/fitmate-frontend/blob/main/lib/types.ts"
    click Utils "https://github.com/chin-ma/fitmate-frontend/blob/main/lib/utils.ts"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#2196F3,stroke-width:1px
    classDef api fill:#E8F5E9,stroke:#4CAF50,stroke-width:1px
    classDef service fill:#FFF3E0,stroke:#FB8C00,stroke-width:1px,stroke-dasharray: 5 5
    classDef external fill:#FFEBEE,stroke:#F44336,stroke-width:1px
    class Browser,AppDir,EntryLayout,EntryPage,dashLayout,DashPage,DashChat,DashDaily,DashRec,DashOnboard,DashWorkout,AuthPage,UIlib,Header,Logo,Sidebar,AIChatComp,DailyComp,OnboardForm,PostureComp,WorkoutComp,Public,Types,Utils frontend
    class ChatAPI,DietAPI,FoodAPI,PostureAPI,UpdateAPI api
    class Flask service
    class Gemini,Mongo external
```
