# georgesklavos/personal-trainer-server2 architecture

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

- Interactive diagram: https://gitdiagram.com/georgesklavos/personal-trainer-server2
- Repository: https://github.com/georgesklavos/personal-trainer-server2

## Overview

##### Project type and purpose
- This is a NestJS–TypeScript monolithic REST API backend for a fitness/training management system.
- It exposes endpoints for user/admin/client/trainer workflows, handles authentication/authorization (JWT & local), sends e-mails, processes payments, and persists data via TypeORM.

##### File structure
- Top-level files: nest-cli.json, ormconfig.ts (TypeORM config), package.json, tsconfig.json.
- src/ is organized into feature folders (auth, users, clients, trainers, payments, email, messages, etc.), each with its own module, controller, service, DTOs, and specs.
- Cross-cutting concerns: src/guards (role-based authorization), src/pipes (DTO validation), src/filters (exception handling), src/middleware (request logging), migrations/ & seeds/ (DB schema and initial data).
- Entities directory holds all TypeORM @Entity definitions that map to database tables.

##### Inspect README for insights
- Confirms standard NestJS starter with a modular structure.

##### Main components
a. API Gateway / HTTP Server
– NestJS application bootstrap (main.ts + app.module).
– Middleware → Pipes → Guards → Controllers.
b. Authentication subsystem
– local.strategy, jwt.strategy, local-auth.guard, jwt-auth.guard.
– DTOs for login and user info.
– User-management: users, auth, roles, login-information, reset-password.
– Client workflows: clients, days, macros, exercises, how-you-feel.
– Trainer workflows: trainers, programs, videos.
– Admin & support: admin, support, mutual.
– Communication: email (templates + SMTP), messages (chat DTOs).
– Payments: payments + verifyPayment DTO.
– Translations & helper data: translations, helper-tables.
d. Data layer
– TypeORM Repositories under the hood of each service.
– Database server (e.g., PostgreSQL) hosting all entities.
– Migrations and seed scripts.
e. External services
– Email provider (SMTP or API).
– Payment gateway (e.g., Stripe).
– Potential push notifications / chat service if applicable.

##### Relationships and interactions
– Client (mobile/web) → HTTP → NestJS HTTP server.
– HTTP server processing chain: Middleware → Pipe → Guard → Controller → Service → TypeORM Repository → DB.
– Services → external calls (SMTP, payment API).
– Auth module issuing JWTs consumed by Guards in other modules.
- Inter-module service injections (e.g., auth.service used by users.service).

##### Architectural patterns & design principles
- Modular decomposition: each feature is a Nest module.
- Layered architecture: Controllers (API), Services (business logic), Repositories (data access).
- Dependency Injection for loose coupling.
- DTO + Pipes for input validation.
- Guards for authorization.
- Exception Filters for error handling.
- Use of migrations and seeders for schema and initial data.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% API Gateway
    subgraph "API Gateway / HTTP Server"
        direction TB
        Main["main.ts"]:::core
        AppModule["AppModule (app.module.ts)"]:::core
        AppController["AppController (app.controller.ts)"]:::core
        AppService["AppService (app.service.ts)"]:::core
    end

    %% Authentication Subsystem
    subgraph "Authentication Subsystem"
        direction TB
        AuthModule["AuthModule"]:::auth
        AuthService["AuthService"]:::auth
        LocalStrategy["LocalStrategy"]:::auth
        JwtStrategy["JwtStrategy"]:::auth
        LocalGuard["LocalAuthGuard"]:::auth
        JwtGuard["JwtAuthGuard"]:::auth
        UserAuthDTO["UserAuthInfoDTO"]:::auth
    end

    %% User Management
    subgraph "User Management Module"
        direction TB
        UsersModule["UsersModule"]:::domain
        UsersController["UsersController"]:::domain
        UsersService["UsersService"]:::domain
    end

    %% Client Workflows
    subgraph "Client Workflows Module"
        direction TB
        ClientsModule["ClientsModule"]:::domain
        ClientsController["ClientsController"]:::domain
        ClientsService["ClientsService"]:::domain
    end

    %% Trainer Workflows
    subgraph "Trainer Workflows Module"
        direction TB
        TrainerModule["TrainerModule"]:::domain
        TrainerController["TrainerController"]:::domain
        TrainerService["TrainerService"]:::domain
        OwnerTrainerModule["OwnerTrainerModule"]:::domain
        OwnerTrainerController["OwnerTrainerController"]:::domain
        OwnerTrainerService["OwnerTrainerService"]:::domain
    end

    %% Admin & Support
    subgraph "Admin & Support Modules"
        direction TB
        AdminModule["AdminModule"]:::domain
        AdminController["AdminController"]:::domain
        AdminService["AdminService"]:::domain
        SupportModule["SupportModule"]:::domain
        SupportController["SupportController"]:::domain
        SupportService["SupportService"]:::domain
        MutualModule["MutualModule"]:::domain
        MutualController["MutualController"]:::domain
        MutualService["MutualService"]:::domain
    end

    %% Domain Feature Modules
    subgraph "Domain Feature Modules"
        direction TB
        DaysModule["DaysModule"]:::domain
        MacrosModule["MacrosModule"]:::domain
        ExercisesModule["ExercisesModule"]:::domain
        HowYouFeelModule["HowYouFeelModule"]:::domain
        MessagesModule["MessagesModule"]:::domain
        VideosModule["VideosModule"]:::domain
    end

    %% Communication / Email
    subgraph "Communication / Email Module"
        direction TB
        EmailModule["EmailModule"]:::integration
        EmailService["EmailService"]:::integration
        EmailTemplates["emailTemplates"]:::integration
    end

    %% Payments
    subgraph "Payments Module"
        direction TB
        PaymentsModule["PaymentsModule"]:::integration
        PaymentsService["PaymentsService"]:::integration
        VerifyPaymentDTO["VerifyPaymentDTO"]:::integration
    end

    %% Translations & Helper Data
    subgraph "Translations & Helper Data"
        direction TB
        TranslationsModule["TranslationsModule"]:::support
        HelperTablesModule["HelperTablesModule"]:::support
    end

    %% Cross-cutting Concerns
    subgraph "Cross-cutting Concerns"
        direction TB
        Guards["Guards"]:::crosscut
        Pipes["ValidateDTOsPipe"]:::crosscut
        Filters["ExceptionFilters"]:::crosscut
        Middleware["RequestsMiddleware"]:::crosscut
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Entities["Entities"]:::data
        Migrations["Migrations"]:::data
        Seeds["Seeds"]:::data
        Database[(PostgreSQL)]:::database
    end

    %% External Services
    subgraph "External Services"
        direction TB
        SMTP[("Email Provider (SMTP/API)")]:::external
        PaymentGateway[("Payment Gateway (Stripe)")]:::external
    end

    %% Flow arrows
    Client["Client (Mobile/Web)"]:::external -->|HTTP/JSON| Main
    Main --> Middleware --> Pipes --> Guards --> AppController
    AppController -->|calls| AppService
    AppService -->|uses| AuthService
    AppController -->|routes to| UsersController
    UsersController -->|uses| UsersService
    ClientsController -->|uses| ClientsService
    TrainerController -->|uses| TrainerService
    OwnerTrainerController -->|uses| OwnerTrainerService
    AdminController -->|uses| AdminService
    SupportController -->|uses| SupportService
    MutualController -->|uses| MutualService
    DaysModule -->|service uses repositories| Entities
    MacrosModule -->|service uses repositories| Entities
    ExercisesModule -->|service uses repositories| Entities
    HowYouFeelModule -->|service uses repositories| Entities
    MessagesModule -->|service uses repositories| Entities
    VideosModule -->|service uses repositories| Entities
    EmailService -->|SMTP| SMTP
    PaymentsService -->|API| PaymentGateway
    Entities -->|SQL| Database
    Migrations -->|run migrations| Database
    Seeds -->|seed data| Database

    %% Click events
    click Main "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/main.ts"
    click AppModule "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/app.module.ts"
    click AppController "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/app.controller.ts"
    click AppService "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/app.service.ts"
    click AuthModule "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/auth/auth.module.ts"
    click AuthService "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/auth/auth.service.ts"
    click LocalStrategy "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/auth/local.strategy.ts"
    click JwtStrategy "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/auth/jwt.strategy.ts"
    click LocalGuard "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/auth/local-auth.gaurd.ts"
    click JwtGuard "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/auth/jwt.auth.gaurd.ts"
    click UserAuthDTO "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/auth/userAuthInfo.dto.ts"
    click UsersModule "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/users/users.module.ts"
    click UsersController "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/users/users.controller.ts"
    click UsersService "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/users/users.service.ts"
    click ClientsModule "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/client/clients.module.ts"
    click ClientsController "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/client/clients.controller.ts"
    click ClientsService "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/client/clients.service.ts"
    click TrainerModule "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/trainer/trainer.module.ts"
    click TrainerController "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/trainer/trainer.controller.ts"
    click TrainerService "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/trainer/trainer.service.ts"
    click OwnerTrainerModule "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/owner-trainer/owner-trainer.module.ts"
    click OwnerTrainerController "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/owner-trainer/owner-trainer.controller.ts"
    click OwnerTrainerService "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/owner-trainer/owner-trainer.service.ts"
    click AdminModule "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/admin/admin.module.ts"
    click AdminController "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/admin/admin.controller.ts"
    click AdminService "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/admin/admin.service.ts"
    click SupportModule "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/support/support.module.ts"
    click SupportController "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/support/support.controller.ts"
    click SupportService "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/support/support.service.ts"
    click MutualModule "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/mutual/mutual.module.ts"
    click MutualController "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/mutual/mutual.controller.ts"
    click MutualService "https://github.com/georgesklavos/personal-trainer-server2/blob/master/src/mutual/mutual.service.ts"

    %% Styles
    classDef core fill:#f9f,stroke:#333,stroke-width:1px
    classDef auth fill:#bbf,stroke:#333,stroke-width:1px
    classDef domain fill:#bfb,stroke:#333,stroke-width:1px
    classDef integration fill:#ffb,stroke:#333,stroke-width:1px
    classDef support fill:#fdc,stroke:#333,stroke-width:1px
    classDef crosscut fill:#eef,stroke:#333,stroke-width:1px
    classDef data fill:#dfd,stroke:#333,stroke-width:1px
    classDef database fill:#ccc,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef external fill:#fdd,stroke:#333,stroke-width:1px,stroke-dasharray: 2 2
```
