# carlosquiroz25/proyecto_integrador_api architecture

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

## Overview

##### Main Components
- API Gateway / Controller Layer: Represented by the multiple controllers (e.g., AnswerController, AuthController, SurveyController, UserAdminController, UserStudentController, UserTeacherController) that expose REST endpoints.
- Service Layer: Contains the business logic and is divided by responsibilities (e.g., AuthService, UserService, SurveyService). Include both the service interfaces and their implementations.
- Data Access Layer: Represented by the repository interfaces (e.g., AnswerRepository, ProfileRepository, UserRepository). This layer handles persistence through Spring Data JPA.
- Domain / Model: The core business entities (User, Profile, Survey, Question, Answer) which dictate the domain logic.
- Security Layer: Covers authentication and authorization aspects such as JWT processing (JwtFilter, JwtUtil, SecurityConfig) and Spring Security configuration.
- External Components: Database (either MySQL or PostgreSQL, as well as any third-party integrations such as Swagger/OpenAPI for API documentation). Also consider external services (like Docker) and cloud deployment environment configuration.
- Infrastructure & Configuration: This includes configuration classes (CorsConfig, OpenApiConfig) and environment-specific files (.env, Dockerfile).

##### Relationships and Interactions
- The controllers pass requests to the service layer; these services then interact with the repository layer to perform CRUD operations on the database.
- Bidirectional interaction between Entities (Domain Models) and Repositories for persistence.
- Optionally, include how Swagger/OpenAPI is exposed to document and test the API.

##### Architectural Patterns and Principles
- Follow the layered architecture pattern: clearly separate controllers (presentation), services (business logic), repositories (data persistence) and models (domain).
- Use of dependency injection via Spring Boot.
- Stateless authentication mechanism via JWT.

##### Extra Details to Consider
- Mention integration with Swagger/OpenAPI for API documentation and testing.
- Environmental configuration aspects (like .env configuration for database and JWT secrets).
- That the project supports role-based interactions (ADMIN, STUDENT, TEACHER) by showing that some controllers and services cater to specific roles. These roles could be illustrated as sub-components or labeled areas within the “Security” domain.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client"
        C1("Client (API Consumer)"):::client
    end

    %% Security Layer
    subgraph "Security (Authentication & Authorization)"
        S1("JwtFilter"):::security
        S2("JwtUtil"):::security
        S3("SecurityConfig"):::security
    end

    %% Controllers (API Gateway Layer)
    subgraph "Controllers (REST Endpoints)"
        CT1("AnswerController"):::controller
        CT2("AuthController"):::controller
        CT3("SurveyController"):::controller
        CT4("UserAdminController"):::controller
        CT5("UserStudentController"):::controller
        CT6("UserTeacherController"):::controller
        CT7("HomeController"):::controller
    end

    %% Services (Business Logic)
    subgraph "Services (Business Logic)"
        SV1("AnswerService"):::service
        SV2("AuthService"):::service
        SV3("SurveyService"):::service
        SV4("UserAdminService"):::service
        SV5("UserService"):::service
        SV6("UserStudentService"):::service
        subgraph "Service Implementations"
            SI1("AuthServiceImpl"):::serviceImpl
            SI2("UserAdminServiceImpl"):::serviceImpl
            SI3("UserStudentServiceImpl"):::serviceImpl
        end
    end

    %% Data Access Layer
    subgraph "Repositories (Data Persistence)"
        R1("AnswerRepository"):::repository
        R2("ProfileRepository"):::repository
        R3("QuestionRepository"):::repository
        R4("SurveyRepository"):::repository
        R5("UserRepository"):::repository
    end

    %% Domain Models
    subgraph "Domain Models"
        D1("Answer"):::domain
        D2("Profile"):::domain
        D3("Question"):::domain
        D4("QuestionType"):::domain
        D5("Survey"):::domain
        D6("User"):::domain
    end

    %% Infrastructure & Configuration
    subgraph "Configurations & Deployment"
        IC1("CorsConfig"):::infra
        IC2("OpenApiConfig"):::infra
        IC3("DataLoader"):::infra
        IC4("application.properties"):::infra
        IC5("Dockerfile"):::infra
    end

    %% External Components
    subgraph "External & Deployment"
        EX1("Swagger/OpenAPI Documentation"):::external
        EX2("Docker & Cloud Deployment"):::external
    end

    %% Data Flow Connections
    C1 -->|"Request"| S1
    S1 -->|"ValidatedRequest"| CT2
    S1 --> CT7

    %% Controllers to Services examples
    CT2 -->|"calls"| SV2
    CT3 -->|"calls"| SV3
    CT5 -->|"calls"| SV6

    %% Services to Service Implementations
    SV2 --> SI1
    SV4 --> SI2
    SV6 --> SI3

    %% Services to Repositories
    SI1 -->|"fetches"| R5
    SV3 --> R4

    %% Repositories to Domain Models (bidirectional arrow to indicate persistence)
    R5 <-->|"maps to"| D6
    R4 <--> D5

    %% Controllers expose API documentation via Swagger
    CT2 ---|"documents"| EX1

    %% Deployment connections
    IC5 -->|"containerized by"| EX2

    %% Styles
    classDef client fill:#FDEBD0,stroke:#333,stroke-width:2px;
    classDef controller fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef service fill:#D5F5E3,stroke:#333,stroke-width:2px;
    classDef serviceImpl fill:#ABEBC6,stroke:#333,stroke-width:2px;
    classDef repository fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef domain fill:#FADBD8,stroke:#333,stroke-width:2px;
    classDef security fill:#D6EAF8,stroke:#333,stroke-width:2px;
    classDef infra fill:#F2D7D5,stroke:#333,stroke-width:2px;
    classDef external fill:#E8DAEF,stroke:#333,stroke-width:2px;

    %% Click Events for Controllers
    click CT1 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/controller/AnswerController.java"
    click CT2 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/controller/AuthController.java"
    click CT3 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/controller/SurveyController.java"
    click CT4 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/controller/UserAdminController.java"
    click CT5 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/controller/UserStudentController.java"
    click CT6 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/controller/UserTeacherController.java"
    click CT7 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/controller/HomeController.java"

    %% Click Events for Services (Interfaces)
    click SV1 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/service/AnswerService.java"
    click SV2 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/service/AuthService.java"
    click SV3 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/service/SurveyService.java"
    click SV4 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/service/UserAdminService.java"
    click SV5 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/service/UserService.java"
    click SV6 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/service/UserStudentService.java"

    %% Click Events for Service Implementations
    click SI1 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/service/impl/AuthServiceImpl.java"
    click SI2 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/service/impl/UserAdminServiceImpl.java"
    click SI3 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/service/impl/UserStudentServiceImpl.java"

    %% Click Events for Repositories
    click R1 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/repository/AnswerRepository.java"
    click R2 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/repository/ProfileRepository.java"
    click R3 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/repository/QuestionRepository.java"
    click R4 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/repository/SurveyRepository.java"
    click R5 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/repository/UserRepository.java"

    %% Click Events for Domain Models
    click D1 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/model/Answer.java"
    click D2 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/model/Profile.java"
    click D3 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/model/Question.java"
    click D4 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/model/QuestionType.java"
    click D5 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/model/Survey.java"
    click D6 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/model/User.java"

    %% Click Events for Security
    click S1 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/security/JwtFilter.java"
    click S2 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/security/JwtUtil.java"
    click S3 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/config/SecurityConfig.java"

    %% Click Events for Infrastructure & Configuration
    click IC1 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/config/CorsConfig.java"
    click IC2 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/config/OpenApiConfig.java"
    click IC3 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/java/com/cesde/proyecto_integrador/config/data/DataLoader.java"
    click IC4 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/src/main/resources/application.properties"
    click IC5 "https://github.com/carlosquiroz25/proyecto_integrador_api/tree/main/Dockerfile"

    %% Click Events for External Components
    click EX1 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/docs/Exportar json OpenAPI.md"
    click EX2 "https://github.com/carlosquiroz25/proyecto_integrador_api/blob/main/docs/docker-configuracion.md"
```
