# giavinh79/gymtrackapiv2 architecture

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

- Interactive diagram: https://gitdiagram.com/giavinh79/gymtrackapiv2
- Repository: https://github.com/giavinh79/gymtrackapiv2

## Overview

##### Main Components
- API Server (Spring Boot)
- Represented by the bulk of the source code under src/main/java, organized by feature (e.g., auth, exercise, routine, etc.).
- Contains controllers, services, repositories, exception handling, and filters.
- Database (PostgreSQL)
- Managed by Flyway using versioned SQL migration files (located in src/main/resources/db/migration).
- Connections to PostgreSQL are set up locally via Docker (see docker-compose.yml in the db folder).
- External Services and Integrations
- Firebase: Used for authentication (code and filters under src/main/java/com/gymtrack/api/filter/auth and src/main/java/com/gymtrack/api/platform/firebase).
- Cache: Redis is mentioned in the README (commands are provided for clearing it via Docker), even though it might be part of the Docker Compose in the db folder.
- AWS Secrets Manager (not yet implemented but mentioned for production) and AWS S3 for image storage.
- CI/CD and Deployment
- GitHub Actions (workflow files in .github/workflows) for automated builds and tests.
- The deployment is set to eventually utilize AWS Lightsail with a Supabase-hosted PostgreSQL instance.
- Additional Components:
- Postman collection for API testing located in the postman folder.
- Infrastructure configurations such as appspec.yml and buildspec.yml.
- Build automation with Maven, denoted by pom.xml and maven-wrapper files.

##### Relationships and Interactions
- The API Server (Spring Boot) communicates with
- the PostgreSQL database for data persistence (via repositories).
- external authentication services (Firebase) for securing protected API endpoints.
- Redis for caching (if used during runtime).
- The controllers route requests that propagate to the corresponding services and then to the repositories.
- The data migration and schema evolution is handled by Flyway on the PostgreSQL instance.
- The CI/CD pipeline (via GitHub Actions) automates testing, building, and potentially deployment tasks.
- The front-end communicates with this API server via REST calls and the documentation is available via Swagger.

##### Architectural Patterns and Principles
- N-tier Architecture:
- The project organization by feature/domain across separate packages (controllers, services, repositories) reflects a layered architecture.
- Dependency Injection:
- Standard in Spring Boot for managing service and repository lifecycles.
- Externalized Configuration and Secrets Management:
- The project employs configuration files (application.yml, application-prod.sample.yml, etc.) for language-level and environment level configuration.
- Versioned Database Migrations:
- Use of Flyway guarantees that each deployment’s database schema is in sync with application expectations.
- Modularization by Feature:

##### Technologies and Frameworks
- Java Spring Boot
- PostgreSQL (via Docker for local development)
- Docker Compose (for orchestrating the database and possibly Redis/pgAdmin)
- Firebase (for authentication)
- Flyway (for database migrations)
- MapStruct (for DTO and entity mapping)
- Maven (for build automation)
- GitHub Actions (for CI/CD)

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["External Client (Frontend)"]:::externalClient

    subgraph "API Layer"
        B["API Server (Spring Boot)"]:::api
        click B "https://github.com/giavinh79/gymtrackapiv2/tree/master/src/main/java/com/gymtrack/api"
        B1["Controller Layer (REST Endpoints)"]:::api
        B2["Service Layer (Business Logic)"]:::api
        B3["Repository Layer (Data Access)"]:::api
        click B3 "https://github.com/giavinh79/gymtrackapiv2/tree/master/src/main/java/com/gymtrack/api/feature"
    end

    subgraph "Docker Environment"
        D["PostgreSQL Database (Flyway Managed)"]:::db
        F["Flyway Migrations"]:::db
        click F "https://github.com/giavinh79/gymtrackapiv2/tree/master/src/main/resources/db/migration"
        E["Redis Cache"]:::db
        G["Docker Compose Configuration"]:::db
        click G "https://github.com/giavinh79/gymtrackapiv2/blob/master/db/docker-compose.yml"
    end

    subgraph "External Services"
        H["Firebase Filters"]:::external
        click H "https://github.com/giavinh79/gymtrackapiv2/tree/master/src/main/java/com/gymtrack/api/filter/auth"
        I["Firebase Platform Integration"]:::external
        click I "https://github.com/giavinh79/gymtrackapiv2/tree/master/src/main/java/com/gymtrack/api/platform/firebase"
        J["AWS Services (Secrets Manager, S3)"]:::external
    end

    subgraph "Development & Deployment"
        K["CI/CD Pipeline (GitHub Actions)"]:::ci
        click K "https://github.com/giavinh79/gymtrackapiv2/tree/master/.github/workflows"
        L["Build Automation (Maven)"]:::ci
        click L "https://github.com/giavinh79/gymtrackapiv2/blob/master/pom.xml"
        M1["AppSpec Config"]:::ci
        click M1 "https://github.com/giavinh79/gymtrackapiv2/blob/master/appspec.yml"
        M2["BuildSpec Config"]:::ci
        click M2 "https://github.com/giavinh79/gymtrackapiv2/blob/master/buildspec.yml"
        N["API Testing (Postman Collection)"]:::ci
        click N "https://github.com/giavinh79/gymtrackapiv2/tree/master/postman"
    end

    A -->|"REST_calls"| B
    B -->|"routesTo"| B1
    B1 -->|"calls"| B2
    B2 -->|"accesses"| B3
    B3 -->|"reads/writes"| D
    D -->|"managed_by"| F
    B -->|"authenticatesUsing"| H
    B -->|"integratesWith"| I
    B -->|"cachesUsing"| E
    B -->|"storesDataIn"| J
    K -->|"deploys"| B
    K --> M1
    K --> M2
    K --> N

    classDef api fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef db fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef ci fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef externalClient fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    
    class A externalClient
```
