# sahilmor/fitnessbuddy architecture

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

- Interactive diagram: https://gitdiagram.com/sahilmor/fitnessbuddy
- Repository: https://github.com/sahilmor/fitnessbuddy

## Overview

This project, "Fitness Buddy", is a modern full-stack fitness tracking and social platform. The primary purpose of the application is to allow users to manage workouts, engage in community features (posts, likes, comments), and manage profiles, all while leveraging the strengths of Next.js, TypeScript, Tailwind CSS, and Supabase for backend services such as authentication, database operations, and real-time updates.

##### Main Components to Highlight
- Frontend Application: Represented by the Next.js App Router. This includes:
- Pages in the src/app directory structured into sub-components like authentication (src/app/auth), community (src/app/community), profile (src/app/profile), dashboard, schedule, tracking, and workouts.
- Layout and UI components located in src/components. Mention the layout (header, footer, nav) and reusable UI elements (buttons, inputs, alerts, etc.).
- Static assets from the public folder.

- API & Backend Routes:
- API endpoints in src/app/api covering various aspects such as authentication (/api/auth/*), workouts (/api/workouts/*), community posts (/api/community and /api/posts), comments, likes, goals, and achievements. Represent these as RESTful endpoints that the frontend calls to interact with the backend.

- Integration with External Services:
- Supabase as the backend service covering authentication, database, storage, and real-time subscriptions. Show a connection between the API layer and Supabase.
- Additional tools and libraries (e.g., React Hook Form, Sonner for toast notifications) that add functionality to the frontend.

- Database:

##### Relationships and Interactions
- Frontend-to-API Communication:
- Authentication Flow:
- Data Flow for Workouts & Community Features:
- How users create or interact with workouts, posts, and comments via API endpoints, which then query or update the database on Supabase.
- Component Communication:
- How components (in src/components) like session and theme providers supply the necessary context across the UI, connecting with authentication and state management in the application.

##### Architectural Patterns & Design Principles
- Modular Structure:
- The clear separation between directories for pages, API endpoints, reusable components, and library utilities suggests a modular design.
- MVC-like concepts:
- The Next.js application acts as the ‘View and Controller’ layer, while Supabase is the ‘Model’ handling persistent data.
- Client-Server Separation:
- Distinction between the client (the Next.js frontend) and server (Supabase and the internal API logic routed via Next.js API routes).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        NS["Next.js Frontend (Pages & Routing)"]:::frontend
        UI["Layout & Reusable UI Components"]:::ui
        NS -->|"renders"| UI
        SA["Static Assets"]:::static
        SA -->|"provides assets"| NS
    end

    %% Backend API Layer
    subgraph "Backend API Layer"
        API["API Endpoints & Backend Routes"]:::api
        NS -->|"API calls"| API
    end

    %% Backend Services
    subgraph "Backend Services"
        SUP["Supabase Integration Service"]:::supabase
        PR["Database & ORM Integration (Prisma)"]:::database
        API -->|"auth & data operations"| SUP
        API -->|"ORM queries"| PR
    end

    %% Click Events
    click NS "https://github.com/sahilmor/fitnessbuddy/tree/main/src/app"
    click UI "https://github.com/sahilmor/fitnessbuddy/tree/main/src/components"
    click API "https://github.com/sahilmor/fitnessbuddy/tree/main/src/app/api"
    click SUP "https://github.com/sahilmor/fitnessbuddy/blob/main/src/lib/supabase.ts"
    click PR "https://github.com/sahilmor/fitnessbuddy/blob/main/src/lib/prisma.ts"
    click SA "https://github.com/sahilmor/fitnessbuddy/tree/main/public"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef ui fill:#e2f0d9,stroke:#5cb85c,stroke-width:2px;
    classDef api fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef supabase fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef database fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef static fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
