# laysaalves/eventcode-api architecture

> Architecture diagram of the GitHub repository laysaalves/eventcode-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/laysaalves/eventcode-api
- Repository: https://github.com/laysaalves/eventcode-api

## Overview

##### Project Type and Purpose
- This is a backend REST API built with Java 21 and Spring Boot. It provides endpoints to manage events, subscriptions, and users.
- It incorporates a layered architecture with clear separations between presentation (controllers), domain (business logic and entities), and infrastructure (repositories, DTOs, and exception handling).
- It uses Docker to orchestrate the environment (including MySQL for data persistence) and provides API documentation via OpenAPI/Swagger.

##### Analyzing the File Structure
- Top-level directories include:
- The Maven configuration files (pom.xml, mvnw, etc.) and Docker files (docker-compose.yml), which illustrate the deployment and build processes.
- The “src/main/java/dev/layseiras/EventCode” package is divided into several sub-packages:
◦ core (contains entities, enums, and services) – representing domain/business logic.
◦ docs – managing API documentation setup (e.g., SwaggerConfig).
◦ infra – covering DTOs, exception handling, controllers (the presentation layer), and repositories for data access.
- The “src/test” directories contain the unit and integration tests validating the functionality of these components.

a. Main Components:
- API Consumer/Client: External systems or front-end clients consuming the REST API.
- Presentation Layer: REST Controllers (EventController, SubscriptionController) handling HTTP requests.
- Application/Domain Layer:
- Core business logic (services like EventService and SubscriptionService) that process requests.
- Domain Entities (Event, Subscription, User) and enumerated types (EventType).
- Infrastructure Layer:
- Repository components (EventRepo, SubscriptionRepo, UserRepo) for data persistence.
- DTOs used for data transfer in interactions.
- Exception handling for error management.
- Database: MySQL (as indicated in the README and Docker Compose configuration).
- API Documentation: Swagger/OpenAPI configuration for mapping and displaying API routes.
- Deployment and Build Tools: Maven for building the application and Docker for containerizing the application and database.

b. Relationships and Interactions:
- From the Domain Layer, indicate calls to the Infrastructure Layer (repositories) for data access operations.
- Responses in the reverse direction – with processed data flowing back from the database through repositories, then services, and finally to the controllers for output.
- Interactions for API documentation: the Swagger configuration should be depicted as interfacing with the Presentation Layer, accessible via a specific URL.
- On the infrastructure side, represent Docker’s role in starting both the API service and the MySQL container.

c. Architectural Patterns and Technologies:
- Layered approach (Presentation, Domain, Infrastructure) reflecting the separation of concerns.
- Use of REST architectural style for communication.
- Technologies such as Java 21, Spring Boot/Spring Data (for business logic and database interactions), Maven (build), MySQL (database), and Docker (deployment environment).
- That OpenAPI/Swagger is used for automatic API documentation.

- Rectangles for service components and controllers.
- Docker component is depicted to show how it orchestrates the runtime environment (both the application and the database).

- API Consumer (client, mobile app, or web front-end) making HTTP requests.
- REST Controllers (EventController and SubscriptionController) to receive and route these requests.
- Domain layer:
- Services (EventService, SubscriptionService) implementing business logic.
- Domain Entities (Event, Subscription, User) and enums (EventType) representing core data.
- Infrastructure layer:
- Repositories (EventRepo, SubscriptionRepo, UserRepo) interacting with MySQL.
- DTOs for error messages and responses.
- Exception handlers to manage business exceptions.
- External integrations:
- Docker environment showing the MySQL container and Docker Compose setup.
- Swagger/OpenAPI interface for interacting with and documenting the API.
- Build/Deployment: Maven as the build tool, ensuring the compilation and packaging of the Spring Boot application.

##### Final Advice
- Finally, double-check that every key component from the file tree and README is represented. This detailed separation into as many components as possible will aid in clear communication among the team.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Components
    APIConsumer["API Consumer"]:::external

    %% Presentation Layer
    subgraph "Presentation Layer"
        EController["EventController"]:::controller
        SController["SubscriptionController"]:::controller
    end

    %% Domain Layer
    subgraph "Domain Layer"
        EService["EventService"]:::service
        SService["SubscriptionService"]:::service
        subgraph "Domain Entities"
            EventEntity["Event"]:::entity
            SubscriptionEntity["Subscription"]:::entity
            UserEntity["User"]:::entity
            EType["EventType"]:::entity
        end
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        subgraph "Repository Layer"
            ERepo["EventRepo"]:::repo
            SRepo["SubscriptionRepo"]:::repo
            URepo["UserRepo"]:::repo
        end
        subgraph "Data Transfer Objects (DTOs)"
            ErrorDTO["ErrorMessage"]:::dto
            SubRankingDTO["SubscriptionRankingByuser"]:::dto
            SubRankingElementDTO["SubscriptionRankingElement"]:::dto
            SubResponseDTO["SubscriptionResponse"]:::dto
        end
        subgraph "Exception Handling"
            EventNotFound["EventNotFoundException"]:::exception
            SubscriptionConflict["SubscriptionConflictException"]:::exception
            UserIndicadorNotFound["UserIndicadorNotFoundException"]:::exception
        end
    end

    %% External Components
    MySQLDB["MySQL Database"]:::db
    SwaggerAPI["Swagger/OpenAPI (API Docs)"]:::swagger

    %% Deployment and Build Tools
    subgraph "Deployment & Build Tools"
        DockerNode["Docker Compose"]:::docker
        MavenNode["Maven Build Tools"]:::build
    end

    %% Data Flow Connections
    APIConsumer -->|"HTTPRequest"| EController
    APIConsumer -->|"HTTPRequest"| SController

    EController -->|"calls"| EService
    SController -->|"calls"| SService

    EService -->|"uses"| EventEntity
    SService -->|"uses"| SubscriptionEntity
    SService -->|"uses"| UserEntity
    EService -->|"uses"| EType

    EService -->|"queries"| ERepo
    SService -->|"queries"| SRepo

    ERepo -->|"reads/writes"| MySQLDB
    SRepo -->|"reads/writes"| MySQLDB
    URepo -->|"reads/writes"| MySQLDB

    %% API Documentation Connection
    EController -->|"documentedBy"| SwaggerAPI
    SController -->|"documentedBy"| SwaggerAPI

    %% Deployment/Build Connections
    MavenNode -->|"builds"| EController
    MavenNode -->|"builds"| EService
    DockerNode -->|"orchestrates"| EController
    DockerNode -->|"orchestrates"| MySQLDB

    %% Styles
    classDef external fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef controller fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef service fill:#a9dfbf,stroke:#333,stroke-width:2px;
    classDef entity fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef repo fill:#f5b7b1,stroke:#333,stroke-width:2px;
    classDef dto fill:#d2b4de,stroke:#333,stroke-width:2px;
    classDef exception fill:#f5cba7,stroke:#333,stroke-width:2px;
    classDef swagger fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef db fill:#82e0aa,stroke:#333,stroke-width:2px;
    classDef docker fill:#f7dc6f,stroke:#333,stroke-width:2px;
    classDef build fill:#d5f5e3,stroke:#333,stroke-width:2px;

    %% Click Events for REST Controllers
    click EController "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/infra/presentation/EventController.java"
    click SController "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/infra/presentation/SubscriptionController.java"

    %% Click Events for Business Services
    click EService "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/core/service/EventService.java"
    click SService "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/core/service/SubscriptionService.java"

    %% Click Events for Domain Entities and Enumerations
    click EventEntity "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/core/entities/Event.java"
    click SubscriptionEntity "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/core/entities/Subscription.java"
    click UserEntity "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/core/entities/User.java"
    click EType "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/core/enuns/EventType.java"

    %% Click Events for Repository/Data Access Layer
    click ERepo "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/infra/repository/EventRepo.java"
    click SRepo "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/infra/repository/SubscriptionRepo.java"
    click URepo "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/infra/repository/UserRepo.java"

    %% Click Events for Data Transfer Objects (DTOs)
    click ErrorDTO "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/infra/dtos/ErrorMessage.java"
    click SubRankingDTO "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/infra/dtos/SubscriptionRankingByuser.java"
    click SubRankingElementDTO "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/infra/dtos/SubscriptionRankingElement.java"
    click SubResponseDTO "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/infra/dtos/SubscriptionResponse.java"

    %% Click Events for Exception Handling
    click EventNotFound "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/infra/exception/EventNotFoundException.java"
    click SubscriptionConflict "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/infra/exception/SubscriptionConflictException.java"
    click UserIndicadorNotFound "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/infra/exception/UserIndicadorNotFoundException.java"

    %% Click Event for API Documentation
    click SwaggerAPI "https://github.com/laysaalves/eventcode-api/blob/main/src/main/java/dev/layseiras/EventCode/docs/SwaggerConfig.java"

    %% Click Event for Docker Deployment
    click DockerNode "https://github.com/laysaalves/eventcode-api/blob/main/docker-compose.yml"

    %% Click Event for Build Tools
    click MavenNode "https://github.com/laysaalves/eventcode-api/blob/main/pom.xml"
```
