# 24heuresinsa/overrun-backend architecture

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

- Interactive diagram: https://gitdiagram.com/24heuresinsa/overrun-backend
- Repository: https://github.com/24heuresinsa/overrun-backend

## Overview

##### Main System Components

a) API Layer
- REST API endpoints (organized by domain as seen in /src/routes)
- Authentication & Authorization middleware
- Request/Response handling

b) Business Logic Layer
- Controllers (from /src/controllers)
- Middleware components (from /src/middlewares)
- Utility services (from /src/utils)

c) Data Layer
- Prisma ORM
- Database (likely PostgreSQL based on Prisma usage)

d) External Services Integration
- HelloAsso payment integration
- Email service (based on email templates)

##### Component Relationships

a) External Clients Layer (Top)
- Incoming HTTP requests
- Authentication flow

b) API Gateway Layer (Upper Middle)
- Routes by domain (athletes, races, teams, etc.)
- Middleware chain:
- Authentication
- Access Control
- Pagination
- Search
- Filter
- OrderBy

c) Business Logic Layer (Middle)
- Controllers for each domain
- Utility services
- Email handling system

d) Data Access Layer (Bottom)
- Prisma ORM
- Database with main entities
- Migrations handling

##### Specific Elements

a) Authentication Flow
- Login routes
- Admin invitations
- Token handling

b) Core Business Flows
- Race management
- Athlete registration
- Team handling
- Certificate processing

c) Integration Points
- HelloAsso payment processing
- Email notification system
- VA (Virtual Assistant?) integration

##### Key Architectural Patterns to Highlight

- RESTful API structure
- Middleware pipeline pattern
- Repository pattern (via Prisma)
- Service-based architecture for utilities
- Event-driven architecture for notifications

##### Technical Stack Indicators

Technologies:
- Node.js/Express.js
- Prisma ORM
- PostgreSQL
- Docker containerization
- TypeScript

Remember to highlight the scalability aspects enabled by the Docker configuration and the security measures implemented through the middleware layer.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "External Clients"
        CLIENT[Client Applications]
    end

    subgraph "API Gateway"
        API[API Entry Point]:::api
        click API "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/app.ts"
        
        subgraph "Authentication"
            AUTH[Authentication]:::middleware
            AC[Access Control]:::middleware
            LOGIN[Login Handler]:::api
            click AUTH "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/middlewares/authentication.ts"
            click AC "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/middlewares/accessControl.ts"
            click LOGIN "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/routes/login.ts"
        end
        
        subgraph "Middleware Pipeline"
            SEARCH[Search]:::middleware
            PAG[Pagination]:::middleware
            FILTER[Filter]:::middleware
            ORDER[OrderBy]:::middleware
            CLEAN[Body Cleaning]:::middleware
            click SEARCH "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/middlewares/search.ts"
            click PAG "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/middlewares/pagination.ts"
            click FILTER "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/middlewares/filter.ts"
            click ORDER "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/middlewares/orderBy.ts"
            click CLEAN "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/middlewares/cleanBody.ts"
        end
    end

    subgraph "Business Logic"
        subgraph "Core Controllers"
            RACE[Race Controller]:::controller
            ATH[Athlete Controller]:::controller
            TEAM[Team Controller]:::controller
            CERT[Certificate Controller]:::controller
            REG[Registration Controller]:::controller
            VA[VA Controller]:::controller
            ADMIN[Admin Controller]:::controller
            ADMINV[Admin Invitations]:::controller
            click RACE "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/controllers/races.ts"
            click ATH "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/controllers/athletes.ts"
            click TEAM "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/controllers/teams.ts"
            click CERT "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/controllers/certificates.ts"
            click REG "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/controllers/inscriptions.ts"
            click VA "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/controllers/VA.ts"
            click ADMIN "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/controllers/admins.ts"
            click ADMINV "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/controllers/adminInvitations.ts"
        end

        subgraph "Utility Services"
            JSON[Response Formatter]:::util
            TOKEN[Token Generator]:::util
            ERROR[Error Handler]:::util
            CREATEADMIN[Admin Creator]:::util
            click JSON "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/utils/jsonResponseFormater.ts"
            click TOKEN "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/utils/secureRandomToken.ts"
            click ERROR "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/utils/prismaErrors.ts"
            click CREATEADMIN "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/utils/createAdmin.ts"
        end
    end

    subgraph "External Services"
        HELLO[HelloAsso Payment]:::external
        EMAIL[Email Service]:::external
        EMAILT[Email Templates]:::external
        click HELLO "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/utils/helloassoProvider.ts"
        click EMAIL "https://github.com/24HeuresINSA/OverRun-backend/blob/main/src/utils/emails.ts"
        click EMAILT "https://github.com/24HeuresINSA/OverRun-backend/tree/main/src/utils/email_templates"
    end

    subgraph "Data Layer"
        PRISMA[Prisma ORM]:::database
        DB[(PostgreSQL)]:::database
        SCHEMA[Database Schema]:::database
        MIGRATIONS[Database Migrations]:::database
        click SCHEMA "https://github.com/24HeuresINSA/OverRun-backend/blob/main/prisma/schema.prisma"
        click MIGRATIONS "https://github.com/24HeuresINSA/OverRun-backend/tree/main/prisma/migrations"
    end

    %% Connections
    CLIENT --> API
    API --> AUTH
    AUTH --> AC
    AC --> LOGIN
    
    LOGIN --> |Auth Flow| MIDDLEWARE
    MIDDLEWARE[Middleware Chain] --> |Routes| CONTROLLERS
    
    MIDDLEWARE --- SEARCH
    MIDDLEWARE --- PAG
    MIDDLEWARE --- FILTER
    MIDDLEWARE --- ORDER
    MIDDLEWARE --- CLEAN
    
    CONTROLLERS --- RACE
    CONTROLLERS --- ATH
    CONTROLLERS --- TEAM
    CONTROLLERS --- CERT
    CONTROLLERS --- REG
    CONTROLLERS --- VA
    CONTROLLERS --- ADMIN
    CONTROLLERS --- ADMINV
    
    RACE & ATH & TEAM & CERT & REG & VA & ADMIN & ADMINV --> PRISMA
    PRISMA --> DB
    PRISMA --> SCHEMA
    PRISMA --> MIGRATIONS
    
    CONTROLLERS --> HELLO
    CONTROLLERS --> EMAIL
    EMAIL --> EMAILT
    
    %% Styling
    classDef api fill:#2196F3,stroke:#000,stroke-width:2px
    classDef middleware fill:#FFC107,stroke:#000,stroke-width:2px
    classDef controller fill:#4CAF50,stroke:#000,stroke-width:2px
    classDef util fill:#9C27B0,stroke:#000,stroke-width:2px
    classDef database fill:#607D8B,stroke:#000,stroke-width:2px
    classDef external fill:#E91E63,stroke:#000,stroke-width:2px
```
