# neopromic/infinity architecture

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

- Interactive diagram: https://gitdiagram.com/neopromic/infinity
- Repository: https://github.com/neopromic/infinity

## Overview

##### Project Type & Purpose
- This is a full-stack web application built with Next.js. Its purpose is to be a workout and training management platform.
- The README and file tree reveal key features such as authentication (signup/signin), user profile management, routines creation, and a rich set of UI components.
- The project integrates with Firebase—for both authentication and database (as seen in services/database/firebase.ts and other utility functions).

##### File Structure
- The top-level directories include:
- The app directory: Contains route definitions and page components. This features API routes (app/api) for authentication (using NextAuth, as indicated by the [[...nextauth]] route folder), and user-facing pages (home, profile, routines, auth, etc.).
- components directory: Provides modular UI components (ranging from layout elements to specific workout components).
- services: Contains the database integration logic with Firebase and utility modules for common database operations.
- lib & utils: House helper functions and context/providers for state or theme management.
- Configuration files: e.g., next.config.js, tailwind.config.ts, pnpm-lock.yaml, etc., which outline build, styling, and deployment settings.

##### Core Components
a. Frontend (Client-Side)
- Pages (e.g., home, profile, routines, landing) depicted as user interfaces.
- UI Components: Broken down into categories (e.g., Header, Landing content, Workout display components, typography, and a set of reusable UI elements in components/ui).
- Global styling and layout: Shown in app/globals.css and main layout components (app/layout.tsx).

b. Backend/API
- API Endpoints: In app/api (for authentication, via next-auth integration). Represent this as a “Server API Layer” handling requests like login, signup, etc.
- Authentication: The authentication endpoints and processing (e.g., /api/auth/[...nextauth]).

c. Database & External Services
- Firebase Integration: A distinct “Firebase Service” block that handles database operations and authentication setup (services/database/firebase.ts and accompanying utils).
- Environment & Configuration: .env files, dotenv usage, and configuration files that manage keys and environment variables for secure Firebase integration.

d. State & Context Management
- Global state providers such as authContext (in utils/context) and theme-provider (in utils/providers) managing client state and appearance.

##### Relationships & Data Flow
- The User interacts with the Frontend (pages and components) which shows workouts, routines, and authentication pages.
- The Frontend communicates with the Backend API endpoints (handled with Next.js routes in app/api) for operations like user authentication.
- The Backend, in turn, interacts with Firebase. This connection manages user data and workouts (handled in services/database).
- Utility functions and shared context (in lib and utils) provide common logic and state management used across both client and server components.
- The client’s Firebase SDK integration (via the configuration in services/database/firebase.ts and utils/firebaseAdmin.ts) ties the front- and backend together securely.

##### Architectural Patterns & Design Principles
- Component-based architecture: A clear separation via modular components (UI components, layout components, etc.).
- File-based routing (Next.js) is used for both UI pages and API routes.
- Separation of concerns: Authentication, routing, UI rendering, and data management are in distinct directories.
- Use of context/providers for state management enhances a reactive and declarative UI design.
- External configuration management with .env for sensitive data.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    User("User"):::external

    %% Global State & Utils Subgraph
    subgraph "Global State & Utils"
        AC("Auth Context"):::util
        TP("Theme Provider"):::util
    end

    %% Frontend Layer Subgraph
    subgraph "Frontend Layer"
        PL("Pages & Layouts"):::frontend
        UC("UI Components"):::frontend
    end

    %% Backend/API and External Services
    API("API Layer"):::backend
    FS("Firebase Service"):::service
    FA("Firebase Admin Integration"):::service

    %% Connections
    User -->|"interacts"| PL
    AC -->|"providesState"| PL
    TP -->|"managesTheme"| PL
    PL -->|"renders"| UC
    PL -->|"calls"| API
    API -->|"readsWrites"| FS
    API -->|"adminAccess"| FA

    %% Click Events
    click PL "https://github.com/neopromic/infinity/tree/main/app"
    click UC "https://github.com/neopromic/infinity/tree/main/components"
    click API "https://github.com/neopromic/infinity/blob/main/app/api/auth/[...nextauth]"
    click FS "https://github.com/neopromic/infinity/blob/main/services/database/firebase.ts"
    click AC "https://github.com/neopromic/infinity/tree/main/utils/context"
    click TP "https://github.com/neopromic/infinity/tree/main/utils/providers"
    click FA "https://github.com/neopromic/infinity/blob/main/utils/firebaseAdmin.ts"

    %% Styles
    classDef external fill:#d3d3d3,stroke:#000,stroke-width:2px;
    classDef frontend fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef service fill:#ffcccb,stroke:#000,stroke-width:2px;
    classDef util fill:#ffe4b5,stroke:#000,stroke-width:2px;
```
