# oscararismendi/survey-backend architecture

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

- Interactive diagram: https://gitdiagram.com/oscararismendi/survey-backend
- Repository: https://github.com/oscararismendi/survey-backend

## Overview

##### Main Components
- Entry Point & Configuration: At the very top is the SurveyBackendApplication.java file which boots up the application. Also include the configuration files (application.properties and variants) and Maven scripts (pom.xml, mvnw).
- Controllers (API Layer): Represented by classes in the “infrastructure/controllers” directory (such as SurveyController.java and UserController.java). These components are responsible for handling incoming HTTP requests and mapping them to service calls.
- Application Services (Business Logic Layer): Classes like SurveyService, IUserService, and UserDetailServiceImpl in the “application/services” folder encapsulate business rules and logic.
- Domain Layer (Data/Entity Models): This includes entity classes (like Survey, Question, UserEntity, Role, etc.) located under “domain/entity” and the associated DTOs in “domain/entity/dto”. This layer models the core data of surveys, questions, users, permissions, etc.
- Repository Layer (Data Access): Found under “infrastructure/repositories” for users, surveys, and roles. These classes (for example, SurveyRepository and UserRepository) manage persistence and are typically interfaces or adapters that connect to a database.
- Security Components: The “security” package, which contains the SpringSecurityConfig and the JWT token validator (JwtTokenValidator), plus utility classes like JwtUtils, manage authentication/authorization via JWT.
- Utilities & Support: Include anything that aids in operations, like the “utils” package, and possibly the SQL import file for database initialization (import.sql).

- Controllers then invoke Application Services to process business logic.
- Application Services interact with Repositories to fetch, store, or update entities in the database.
- Domain Entities are shared between Services and Repositories as the data model.
- Security components (configured via SpringSecurityConfig) intercept incoming requests. They validate JWT tokens using JwtTokenValidator and JwtUtils before allowing the request to reach controllers.

##### Architectural Patterns & Design Principles
- Layered Architecture: Emphasize the separation between presentation (controllers), business logic (services), data (repositories and domain), and security.
- Dependency Inversion: Controllers depend on services, not directly on repositories, ensuring modularity.
- RESTful API design: The controllers serve as endpoints to expose the survey functionalities.
- Security Best Practices: Use JWT for stateless security and authentication, as seen in the security package.

##### Technologies, Frameworks, and Tools
- Java and Spring Boot are central to the project.
- Maven is used for build and dependency management.
- JWT is used for security (with supporting classes like JwtTokenValidator and JwtUtils).
- Database connectivity (likely using Spring Data JPA) through Repository interfaces.
- Testing framework is visible (JUnit tests under src/test).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client Request
    Client["Client Request"]:::external

    %% Entry Point & Configuration
    subgraph "Entry Point & Configuration"
        EP["SurveyBackendApplication.java"]:::entrypoint
        POM["pom.xml"]:::config
        AP["application.properties"]:::config
        APDEV["application-dev.properties"]:::config
        APPDN["application-pdn.properties"]:::config
        MSG["messages.properties"]:::config
        IMP["import.sql"]:::config
    end

    %% Security Components
    subgraph "Security Components"
        SSC["SpringSecurityConfig"]:::security
        JWTTV["JwtTokenValidator"]:::security
        JWTU["JwtUtils"]:::security
    end

    %% API Layer (Controllers)
    subgraph "API Layer (Controllers)"
        SCtrl["SurveyController"]:::controller
        UC["UserController"]:::controller
        CTDTO["Controller DTOs"]:::controller
    end

    %% Business Logic (Application Services)
    subgraph "Business Logic (Application Services)"
        SS["SurveyService"]:::service
        ISvc["IUserService"]:::service
        UDS["UserDetailServiceImpl"]:::service
    end

    %% Data Layer
    subgraph "Data Layer"
        subgraph "Domain"
            DM1["Domain Entities"]:::domain
            DM2["Domain DTOs"]:::domain
        end
        subgraph "Repositories"
            SR["SurveyRepository"]:::repository
            UR["UserRepository"]:::repository
            RR["RoleRepository"]:::repository
            UA["UserAdapter"]:::repository
        end
    end

    %% Relationships
    Client -->|"hits"| SSC
    EP -->|"bootstraps"| SSC
    SSC -->|"secures"| SCtrl
    SSC -->|"secures"| UC
    SSC --> JWTTV
    SSC --> JWTU

    SCtrl -->|"calls"| SS
    UC -->|"calls"| ISvc
    UC -->|"calls"| UDS
    %% Optional connection from controllers to DTOs for request/response mapping
    SCtrl --> CTDTO
    UC --> CTDTO

    SS -->|"executes"| SR
    ISvc -->|"executes"| UR
    UDS -->|"executes"| UR

    %% Services work with Domain Models
    SS -->|"manipulates"| DM1
    ISvc --> DM1
    UDS --> DM1

    %% Domain connects to Repositories
    DM1 -->|"persisted by"| SR
    DM1 -->|"persisted by"| UR
    DM1 -->|"persisted by"| RR
    DM1 -->|"persisted by"| UA

    %% Connect Domain DTOs with Domain Entities
    DM2 ---|"derived from"| DM1

    %% Configuration supports entire application startup
    POM --- EP
    AP --- EP
    APDEV --- EP
    APPDN --- EP
    MSG --- EP
    IMP --- EP

    %% Click Events
    click EP "https://github.com/oscararismendi/survey-backend/blob/main/src/main/java/com/survey_app/survey_backend/SurveyBackendApplication.java"
    click POM "https://github.com/oscararismendi/survey-backend/blob/main/pom.xml"
    click AP "https://github.com/oscararismendi/survey-backend/blob/main/src/main/resources/application.properties"
    click APDEV "https://github.com/oscararismendi/survey-backend/blob/main/src/main/resources/application-dev.properties"
    click APPDN "https://github.com/oscararismendi/survey-backend/blob/main/src/main/resources/application-pdn.properties"
    click MSG "https://github.com/oscararismendi/survey-backend/blob/main/src/main/resources/messages.properties"
    click IMP "https://github.com/oscararismendi/survey-backend/blob/main/src/main/resources/import.sql"

    click SCtrl "https://github.com/oscararismendi/survey-backend/blob/main/src/main/java/com/survey_app/survey_backend/infrastructure/controllers/SurveyController.java"
    click UC "https://github.com/oscararismendi/survey-backend/blob/main/src/main/java/com/survey_app/survey_backend/infrastructure/controllers/UserController.java"
    click CTDTO "https://github.com/oscararismendi/survey-backend/tree/main/src/main/java/com/survey_app/survey_backend/infrastructure/controllers/dto"

    click SS "https://github.com/oscararismendi/survey-backend/blob/main/src/main/java/com/survey_app/survey_backend/application/services/SurveyService.java"
    click ISvc "https://github.com/oscararismendi/survey-backend/blob/main/src/main/java/com/survey_app/survey_backend/application/services/IUserService.java"
    click UDS "https://github.com/oscararismendi/survey-backend/blob/main/src/main/java/com/survey_app/survey_backend/application/services/UserDetailServiceImpl.java"

    click DM1 "https://github.com/oscararismendi/survey-backend/tree/main/src/main/java/com/survey_app/survey_backend/domain/entity"
    click DM2 "https://github.com/oscararismendi/survey-backend/tree/main/src/main/java/com/survey_app/survey_backend/domain/entity/dto"

    click SR "https://github.com/oscararismendi/survey-backend/blob/main/src/main/java/com/survey_app/survey_backend/infrastructure/repositories/survey/SurveyRepository.java"
    click UR "https://github.com/oscararismendi/survey-backend/blob/main/src/main/java/com/survey_app/survey_backend/infrastructure/repositories/user/UserRepository.java"
    click RR "https://github.com/oscararismendi/survey-backend/blob/main/src/main/java/com/survey_app/survey_backend/infrastructure/repositories/role/RoleRepository.java"
    click UA "https://github.com/oscararismendi/survey-backend/blob/main/src/main/java/com/survey_app/survey_backend/infrastructure/repositories/user/UserAdapter.java"

    click SSC "https://github.com/oscararismendi/survey-backend/blob/main/src/main/java/com/survey_app/survey_backend/security/SpringSecurityConfig.java"
    click JWTTV "https://github.com/oscararismendi/survey-backend/blob/main/src/main/java/com/survey_app/survey_backend/security/filter/JwtTokenValidator.java"
    click JWTU "https://github.com/oscararismendi/survey-backend/blob/main/src/main/java/com/survey_app/survey_backend/utils/JwtUtils.java"

    %% Styles
    classDef external fill:#EFEFEF,stroke:#444,stroke-width:2px;
    classDef entrypoint fill:#FFDEAD,stroke:#8B4513,stroke-width:2px;
    classDef config fill:#E0FFFF,stroke:#008B8B,stroke-width:2px;
    classDef security fill:#FFC0CB,stroke:#FF1493,stroke-width:2px;
    classDef controller fill:#98FB98,stroke:#2E8B57,stroke-width:2px;
    classDef service fill:#DDA0DD,stroke:#9932CC,stroke-width:2px;
    classDef domain fill:#FFFACD,stroke:#DAA520,stroke-width:2px;
    classDef repository fill:#B0E0E6,stroke:#4682B4,stroke-width:2px;
```
