# aussieguy0/gym-buddy architecture

> Architecture diagram of the GitHub repository aussieguy0/gym-buddy, 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/aussieguy0/gym-buddy
- Repository: https://github.com/aussieguy0/gym-buddy

## Overview

##### Main Components
- Frontend Client: Represent the React-based client application found under the “frontend” directory. It includes components, pages (such as Login, Register, Workouts, etc.), and service modules (Api.ts, Http.ts) for interacting with the backend REST API.
- Backend Service: Represent the Kotlin-based web server located in the “backend” directory. It encapsulates several sub-components:
– Routing & Controllers: Components such as Routes.kt, AuthenticationController.kt, WorkoutController.kt, GraphController.kt, etc. handle various API endpoints (all under the /api/v1 prefix).
– Business Logic & Services: Service classes like AuthenticationService, WorkoutService, GraphService, and supporting utilities and exception handling.
– Database Access Layer: Modules that use direct JDBC interactions, jOOQ generated classes, and migrations (via Flyway and SQL files under resources/db/migration) to manage Postgres persistence.
– Testing: Unit and integration tests in the “backend/src/test” directory.
- Database: A PostgreSQL database acting as the persistent store with information populated from CSV files and maintained through Flyway migrations.

##### Relationships and Data Flow
- Within the Backend, component interactions should be clearly mapped: Routes invoke Controllers; Controllers use Service classes for business logic; Services interface with the Database Access Layer and helper utilities.

##### Architectural Patterns or Design Principles
- Separation of Concerns: The clear division between frontend (presentation layer) and backend (API & business logic) is evident.
- RESTful API Design: All endpoints under /api/v1 are a central theme that bridges frontend and backend.
- Database Migration & Versioning: Use of Flyway for DB version control and migration implies a focus on consistent schema evolution.
- Modularization in the code (dividing authentication, workout tracking, graphing, and utilities) ensures maintainability.

##### Relevant Technologies and Frameworks
- Backend: Kotlin, Javalin, Flyway, jOOQ, and direct Postgres connectivity.
- Build/Deployment: Maven (via Maven Wrapper), Docker (Dockerfile, docker-compose.yml), and CI/CD pipelines (Travis CI, GitHub workflows).

##### Instructing the Principal Software Engineer
– Top-Level: “User/Browser”
– Next Level: “Frontend Application (React/TypeScript)” with annotations around its key modules (pages, components, services).
– Then: “Backend Service (Kotlin/Javalin)” with subdivided areas for routing, business logic, authentication, database access, and specialized components (like the Graph processing module).
– At the bottom: “Database (PostgreSQL)” as the persistent layer, with a side note for Flyway migrations.
- Labels to denote each critical file or directory group, drawing attention to the separation of modules (authentication, workout management, utilities, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["User/Browser"]:::external

    subgraph "Frontend Application (React/TypeScript)"
        FE1["Frontend Client"]:::frontend
        FE2["Pages"]:::frontend
        FE3["Components"]:::frontend
        FE4["Services"]:::frontend
    end

    A -->|"uses"| FE1
    FE1 -->|"renders"| FE2
    FE1 -->|"renders"| FE3
    FE1 -->|"renders"| FE4
    FE1 -->|"API calls"| BE

    subgraph "Backend Service (Kotlin/Javalin)"
        subgraph "Routing & Controllers"
            RC1["Routes"]:::backend
            RC2["Authentication Controller"]:::backend
            RC3["User Controller"]:::backend
            RC4["Workout Controller"]:::backend
            RC5["Graph Controller"]:::backend
        end
        subgraph "Business Logic & Services"
            BL1["Authentication Service"]:::backend
            BL2["User Service"]:::backend
            BL3["Workout Service"]:::backend
            BL4["Graph Service"]:::backend
        end
        subgraph "Database Access Layer"
            DAL1["DB Connection & Helper"]:::backend
            DAL2["jOOQ Modules"]:::backend
            DAL3["Flyway Migration (Kotlin)"]:::backend
            DAL4["Flyway Migrations (Resources)"]:::backend
        end
        RC1 -->|"calls"| RC2
        RC1 -->|"calls"| RC3
        RC1 -->|"calls"| RC4
        RC1 -->|"calls"| RC5
        RC2 -->|"uses"| BL1
        RC3 -->|"uses"| BL2
        RC4 -->|"uses"| BL3
        RC5 -->|"uses"| BL4
        BL1 -->|"accesses"| DAL1
        BL2 -->|"accesses"| DAL1
        BL3 -->|"accesses"| DAL1
        BL4 -->|"accesses"| DAL1
    end

    BE -->|"queries"| DB["PostgreSQL Database"]:::database
    DAL3 -->|"migrates"| DB
    DAL4 -->|"migrates"| DB

    subgraph "Backend Testing"
         T["Tests"]:::backend
    end
    BE -->|"testedBy"| T

    subgraph "Build/Deployment & CI/CD"
         M["Maven Build"]:::deployment
         D["Docker"]:::deployment
         CI["CI/CD Pipelines"]:::deployment
    end
    M -->|"builds"| FE1
    M -->|"builds"| BE
    D -->|"containerizes"| FE1
    D -->|"containerizes"| BE
    CI -->|"deploys"| BE
    CI -->|"deploys"| FE1

    %% Click Events
    click FE1 "https://github.com/aussieguy0/gym-buddy/tree/master/frontend"
    click FE2 "https://github.com/aussieguy0/gym-buddy/tree/master/frontend/src/pages"
    click FE3 "https://github.com/aussieguy0/gym-buddy/tree/master/frontend/src/components"
    click FE4 "https://github.com/aussieguy0/gym-buddy/tree/master/frontend/src/services"
    click BE "https://github.com/aussieguy0/gym-buddy/tree/master/backend"
    click RC1 "https://github.com/aussieguy0/gym-buddy/blob/master/backend/src/main/kotlin/dev/anthonybruno/gymbuddy/Routes.kt"
    click RC2 "https://github.com/aussieguy0/gym-buddy/blob/master/backend/src/main/kotlin/dev/anthonybruno/gymbuddy/auth/AuthenticationController.kt"
    click RC3 "https://github.com/aussieguy0/gym-buddy/blob/master/backend/src/main/kotlin/dev/anthonybruno/gymbuddy/user/UserController.kt"
    click RC4 "https://github.com/aussieguy0/gym-buddy/blob/master/backend/src/main/kotlin/dev/anthonybruno/gymbuddy/workout/WorkoutController.kt"
    click RC5 "https://github.com/aussieguy0/gym-buddy/blob/master/backend/src/main/kotlin/dev/anthonybruno/gymbuddy/graph/GraphController.kt"
    click BL1 "https://github.com/aussieguy0/gym-buddy/blob/master/backend/src/main/kotlin/dev/anthonybruno/gymbuddy/auth/AuthenticationService.kt"
    click BL2 "https://github.com/aussieguy0/gym-buddy/blob/master/backend/src/main/kotlin/dev/anthonybruno/gymbuddy/user/UserService.kt"
    click BL3 "https://github.com/aussieguy0/gym-buddy/blob/master/backend/src/main/kotlin/dev/anthonybruno/gymbuddy/workout/WorkoutService.kt"
    click BL4 "https://github.com/aussieguy0/gym-buddy/blob/master/backend/src/main/kotlin/dev/anthonybruno/gymbuddy/graph/GraphService.kt"
    click DAL1 "https://github.com/aussieguy0/gym-buddy/blob/master/backend/src/main/kotlin/dev/anthonybruno/gymbuddy/db/Database.kt"
    click DAL2 "https://github.com/aussieguy0/gym-buddy/tree/master/backend/src/main/kotlin/dev/anthonybruno/gymbuddy/db/jooq"
    click DAL3 "https://github.com/aussieguy0/gym-buddy/blob/master/backend/src/main/kotlin/db/migration/V6__MakeWorkoutsTimeZoneAware.kt"
    click DAL4 "https://github.com/aussieguy0/gym-buddy/tree/master/backend/src/main/resources/db/migration"
    click T "https://github.com/aussieguy0/gym-buddy/tree/master/backend/src/test"
    click M "https://github.com/aussieguy0/gym-buddy/blob/master/backend/pom.xml"
    click D "https://github.com/aussieguy0/gym-buddy/tree/master/Dockerfile"
    click CI "https://github.com/aussieguy0/gym-buddy/tree/master/.github/workflows"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef database fill:#ffcc99,stroke:#000,stroke-width:2px;
    classDef deployment fill:#d3d3d3,stroke:#000,stroke-width:2px;
    classDef external fill:#fffacd,stroke:#000,stroke-width:2px;
```
