# jdvpl/tu-change architecture

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

- Interactive diagram: https://gitdiagram.com/jdvpl/tu-change
- Repository: https://github.com/jdvpl/tu-change

## Overview

##### High-Level Architecture Components

- Frontend (React/Vite Application)
- Backend (NestJS Application)
- Database (PostgreSQL)
- Docker Container Environment

##### Detailed Component Breakdown

Frontend Layer:
- Modules (Students, Grades)
- Shared Components
- Services Layer (API Service)
- Router
- Core Components

Backend Layer:
- Controllers (Students Controller)
- Use Cases Layer
- Repository Layer
- Guards (API Key Authentication)
- Exception Handlers
- Prisma ORM Layer

Database Layer:
- PostgreSQL Database container
- Prisma schema relationships

##### Specific Implementation Details

Frontend Section:
- Modular structure (students, grades)
- Presentation/core/shared architecture
- API service layer

Backend Section:
- Clean architecture approach with:
- Application layer (use-cases)
- Repository layer
- Service layer (controllers)
- Entity definitions

##### Additional Elements

Include:
- Docker container boundaries
- Environment configuration flow
- API Key authentication flow
- Database migration path

##### Architectural Patterns to Highlight

- Clean Architecture in backend
- Module-based architecture in frontend
- Repository pattern
- DTO pattern
- Guard pattern for API security

##### Notes Section

Notes about:
- Environment setup requirements
- Database seeding process
- API key generation
- Future improvements (parent information, unique student codes)

Key Considerations:

##### Maintain Clean Architecture visibility
- Clear separation between layers
- Dependency direction
- Use case implementations

##### Security Flow
- API key validation path
- Where guards are implemented

##### Data Flow
- Student creation/retrieval flow
- Grade management flow
- Frontend-Backend communication

##### Infrastructure
- Docker container relationships
- Database connection pool
- Environment configuration

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Docker["Docker Environment"]
        direction TB
        Frontend["Frontend Container"]
        Backend["Backend Container"]
        DB[(PostgreSQL Database)]
        
        click Docker "https://github.com/jdvpl/tu-change/blob/main/docker-compose.yml"
        click Backend "https://github.com/jdvpl/tu-change/tree/main/back-end/dockerfile"
    end

    subgraph FrontendLayer["Frontend Layer (React/Vite)"]
        direction TB
        Router["Router"]:::frontend
        ModulesLayer["Modules Layer"]:::frontend
        SharedComponents["Shared Components"]:::frontend
        ApiService["API Service"]:::frontend
        CoreComponents["Core Components"]:::frontend
        
        subgraph Modules
            StudentsModule["Students Module"]:::frontend
            GradesModule["Grades Module"]:::frontend
        end
        
        click Router "https://github.com/jdvpl/tu-change/blob/main/front-end/src/shared/router/router.tsx"
        click ModulesLayer "https://github.com/jdvpl/tu-change/tree/main/front-end/src/modules/"
        click SharedComponents "https://github.com/jdvpl/tu-change/tree/main/front-end/src/shared/components/"
        click ApiService "https://github.com/jdvpl/tu-change/blob/main/front-end/src/services/ApiService.ts"
        click CoreComponents "https://github.com/jdvpl/tu-change/tree/main/front-end/src/modules/students/core/"
        click StudentsModule "https://github.com/jdvpl/tu-change/tree/main/front-end/src/modules/students/"
        click GradesModule "https://github.com/jdvpl/tu-change/tree/main/front-end/src/modules/grades/"
    end

    subgraph BackendLayer["Backend Layer (NestJS)"]
        direction TB
        ApiKeyGuard{"API Key Guard"}:::security
        ExceptionHandler["Exception Handler"]:::backend
        
        subgraph Controllers
            StudentsController["Students Controller"]:::backend
        end
        
        subgraph Domain
            UseCases["Use Cases Layer"]:::backend
            Repository["Repository Layer"]:::backend
            StudentEntity["Student Entity"]:::backend
            DTOs["DTO Definitions"]:::backend
        end
        
        PrismaORM["Prisma ORM Layer"]:::database
        
        click ApiKeyGuard "https://github.com/jdvpl/tu-change/blob/main/back-end/src/guards/api-key.guard.ts"
        click ExceptionHandler "https://github.com/jdvpl/tu-change/blob/main/back-end/src/handlers/exception-handler/exception-dhandler.ts"
        click StudentsController "https://github.com/jdvpl/tu-change/blob/main/back-end/src/students/services/controller/students.controller.ts"
        click UseCases "https://github.com/jdvpl/tu-change/tree/main/back-end/src/students/application/use-cases/"
        click Repository "https://github.com/jdvpl/tu-change/tree/main/back-end/src/students/repository/"
        click StudentEntity "https://github.com/jdvpl/tu-change/blob/main/back-end/src/students/repository/entities/student.entity.ts"
        click DTOs "https://github.com/jdvpl/tu-change/tree/main/back-end/src/students/services/dto/"
        click PrismaORM "https://github.com/jdvpl/tu-change/blob/main/back-end/prisma/schema.prisma"
    end

    %% Relationships
    Router --> ModulesLayer
    ModulesLayer --> SharedComponents
    ModulesLayer --> ApiService
    ModulesLayer --> CoreComponents
    
    ApiService ==> ApiKeyGuard
    ApiKeyGuard ==> StudentsController
    StudentsController --> UseCases
    UseCases --> Repository
    Repository --> StudentEntity
    Repository -.-> PrismaORM
    PrismaORM -.-> DB
    
    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    
    %% Legend
    subgraph Legend
        Frontend_["Frontend Component"]:::frontend
        Backend_["Backend Component"]:::backend
        Database_["Database Component"]:::database
        Security_["Security Component"]:::security
    end
```
