# joel-x-x/prueba-tecnica-shenzhen architecture

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

- Interactive diagram: https://gitdiagram.com/joel-x-x/prueba-tecnica-shenzhen
- Repository: https://github.com/joel-x-x/prueba-tecnica-shenzhen

## Overview

##### Main Components
- Frontend (Angular 19):
- Modular architecture with separate modules such as AdminModule, AuthModule, and PublicModule.
- Components like login, registration, post listing, and administrative interfaces (user and post management).
- Integration aspects like the HTTP interceptors for JWT handling and state management (NgRx or Signals).

- Backend (Spring Boot 3.2.6):
- Major layers according to the Clean Architecture principles: the Controller layer, Service layer, and Repository/Data Access layer.
- Controllers: AuthController, PostController, and UserController.
- Domain layer that contains entities and DTOs for users, posts, roles, and auditing.
- Infrastructure components such as SecurityConfiguration, SwaggerConfiguration, JWT components (JwtAuthenticationFilter, JwtService), and exception handling (ErrorHandler).
- Mention integration with Hibernate (JPA) and use of migration scripts (under resources/db/migration).

- Database (SQL Server):
- How the backend communicates with the SQL Server using Hibernate JPA and JDBC drivers.

- Auxiliary/Integration Components:
- Docker & Docker Compose:
- Docker containers for running the backend and SQL Server.
- Docker-compose setup that orchestrates these containers.
- Documentation and Testing:
- Swagger UI (available at http://localhost:8080/swagger-ui.html) for API documentation.
- Postman collection and unit/integration tests for various modules.

##### Relationships and Interactions
- Frontend-to-Backend:
- JWT authentication flow: authentication request → backend issues token → token stored on frontend → subsequent requests include the token.

- Backend-to-Database:
- That backend services interact with the SQL Server through JPA repositories.

- External Dependencies:
- Where necessary, note supporting services such as Docker for environment orchestration and SQL Server CLI for database management.

##### Architectural Patterns & Design Principles
- Clean Architecture / Layered Architecture:
- Distinct layers (Controller, Service, Repository, Domain, and Infrastructure).
- Usage of DTOs and entity separation to decouple data representation.

- Security & Token-based Authentication:
- JWT and Spring Security as key design elements, highlighting filters (JwtAuthenticationFilter) and security configurations.

- Modularization in Frontend:
- Lazy loading and modular structure (Admin, Auth, Public) in Angular, which aids in scalability and maintainability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Angular 19)"
        FE1["Admin Module"]:::frontend
        FE2["Auth Module"]:::frontend
        FE3["Public Module"]:::frontend
        FE4["HTTP Interceptor (JWT Handling)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Spring Boot 3.2.6)"
        BE1["Main Application Entry Point"]:::backend

        subgraph "Controllers"
            BE2["Auth Controller"]:::backend
            BE3["Post Controller"]:::backend
            BE4["User Controller"]:::backend
        end

        subgraph "Services"
            BE5["Auth Service"]:::backend
            BE6["Post Service"]:::backend
            BE7["User Service"]:::backend
        end

        subgraph "Repositories/Data Access"
            BE8["UserRepository"]:::backend
            BE9["PostRepository"]:::backend
            BE10["RoleRepository"]:::backend
        end

        subgraph "Domain Layer"
            BE11["Users & DTOs"]:::backend
            BE12["Posts & DTOs"]:::backend
            BE13["Roles & DTOs"]:::backend
            BE14["Auditing"]:::backend
        end

        subgraph "Security & Configuration"
            BE15["Security Configuration"]:::backend
            BE16["Swagger Configuration"]:::backend
            BE17["JWT Authentication Filter"]:::backend
            BE18["JWT Service"]:::backend
            BE19["User Security Configuration"]:::backend
            BE20["Error Handler"]:::backend
        end
    end

    %% Database Layer
    subgraph "Database (SQL Server)"
        DB1["SQL Server Database"]:::database
        DB2["Migration Scripts"]:::database
    end

    %% Auxiliary & Integration
    subgraph "Auxiliary & Integration"
        AUX1["Docker Compose Setup"]:::auxiliary
        AUX2["Backend Dockerfile"]:::auxiliary
        AUX3["Postman Collection"]:::auxiliary
        AUX4["Swagger UI Documentation"]:::auxiliary
        AUX5["Unit/Integration Tests"]:::auxiliary
    end

    %% Relationships between Frontend and Backend
    FE2 -->|"calls"| BE2
    FE1 -->|"calls"| BE4
    FE3 -->|"calls"| BE3
    FE4 -->|"authRequest"| BE2

    %% Interactions within Backend (Controllers to Services)
    BE2 -->|"calls"| BE5
    BE3 -->|"calls"| BE6
    BE4 -->|"calls"| BE7

    %% Services to Repositories
    BE5 -->|"calls"| BE8
    BE5 -->|"calls"| BE10
    BE6 -->|"calls"| BE9
    BE7 -->|"calls"| BE8

    %% Repositories to Database
    BE8 -->|"reads/writes"| DB1
    BE9 -->|"reads/writes"| DB1
    BE10 -->|"reads/writes"| DB1

    %% Security Components interactions
    BE17 -->|"filters"| BE2
    BE18 -->|"providesToken"| BE5
    BE20 --- BE2
    BE20 --- BE3
    BE20 --- BE4

    %% Swagger Documentation integration
    BE16 -->|"exposes"| AUX4

    %% Docker and Deployment Connections
    AUX1 -->|"orchestrates"| BE1
    AUX1 -->|"orchestrates"| DB1
    AUX2 -->|"builds"| BE1

    %% Auxiliary Testing
    AUX5 -->|"tests Backend"| BE1

    %% Class Definitions for Coloring
    classDef frontend fill:#cce5ff,stroke:#007bff,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef auxiliary fill:#f8d7da,stroke:#dc3545,stroke-width:2px;

    %% Click Events for Frontend Components
    click FE1 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/front/src/app/admin/admin.module.ts"
    click FE2 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/front/src/app/auth/auth.module.ts"
    click FE3 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/front/src/app/public/public.module.ts"
    click FE4 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/front/src/app/auth/interceptor/auth.interceptor.ts"

    %% Click Events for Backend Components
    click BE1 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/BackApplication.java"
    click BE2 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/controller/auth/AuthController.java"
    click BE3 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/controller/post/PostController.java"
    click BE4 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/controller/user/UserController.java"
    click BE5 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/service/auth/AuthService.java"
    click BE6 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/service/post/PostService.java"
    click BE7 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/service/user/UserService.java"
    click BE8 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/infrastructure/repository/UserRepository.java"
    click BE9 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/infrastructure/repository/PostRepository.java"
    click BE10 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/infrastructure/repository/RoleRepository.java"
    click BE11 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/tree/main/back/src/main/java/com/back/domain/user/"
    click BE12 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/tree/main/back/src/main/java/com/back/domain/post/"
    click BE13 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/tree/main/back/src/main/java/com/back/domain/role/"
    click BE14 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/domain/audit/Audit.java"
    click BE15 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/infrastructure/configuration/SecurityConfiguration.java"
    click BE16 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/infrastructure/configuration/SwaggerConfiguration.java"
    click BE17 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/infrastructure/jwt/JwtAuthenticationFilter.java"
    click BE18 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/infrastructure/jwt/JwtService.java"
    click BE19 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/infrastructure/configuration/UserSecurityConfiguration.java"
    click BE20 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/back/src/main/java/com/back/infrastructure/exception/ErrorHandler.java"

    %% Click Events for Database and Auxiliary Components
    click DB2 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/tree/main/back/src/main/resources/db/migration/"
    click AUX2 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/tree/main/back/Dockerfile"
    click AUX1 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/docker-compose.yml"
    click AUX3 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/blob/main/docs/Shenzhen.postman_collection.json"
    click AUX5 "https://github.com/joel-x-x/prueba-tecnica-shenzhen/tree/main/back/src/test/java/com/back/"
```
