# marceloaaps/forumhub-challenge-alura architecture

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

- Interactive diagram: https://gitdiagram.com/marceloaaps/forumhub-challenge-alura
- Repository: https://github.com/marceloaaps/forumhub-challenge-alura

## Overview

##### Project Overview
- Recognize that this project is a back-end REST API for a forum application built with Java 17, Spring Boot 3, and several supporting libraries (Hibernate, Spring Data JPA, Spring Security, JWT, Flyway, MapStruct, etc.).
- The API supports functionalities such as creating users, topics, and responses, as well as handling authentication/authorization in a stateless manner.

##### Main Architectural Layers and Components
- Presentation Layer:
- Controllers: Located under src/main/java/com/marcelospring/forumhub/presentation/controllers. These handle HTTP requests (e.g., LoginController, TopicoController, RespostaController, UsuarioController).
- DTOs: Under presentation/dtos, these objects represent the input and output models for API endpoints.
- Application (Use Case) Layer:
- Use Cases: In src/main/java/com/marcelospring/forumhub/core/use_cases. They encapsulate business logic for various operations (e.g., creating topics/users, updating responses, etc.). Each sub-package (curso, topico, usuario, resposta) groups related business actions.
- Exception Handling for Use Cases: In core/use_cases/exceptions.
- Domain Layer:
- Entities: Found under core/domain/entities. These represent core domain objects such as Curso, Perfil, Resposta, Topico, and Usuario.
- Repository Interfaces: In core/domain/repositories. They define contract-based interactions with the persistence layer.
- Infrastructure Layer:
- Persistence and Database Migrations: Configurations and SQL migration files (using Flyway) are under src/main/resources/db/migration for versioned database changes.
- Mappers: Under infra/mappers using MapStruct to convert domain objects and DTOs.
- Exception Handlers and Global Error Management: In infra/exceptions.
- Security: Components under infra/security (SecurityConfigurations, SecurityFilter, and services such as TokenService, AuthenticationService, PasswordEncoder) that handle JWT-based authentication in a stateless manner.
- Configuration and Bootstrap:
- The main application class (ForumhubApplication.java) and additional configuration classes (e.g., DataLoaderConfig) start the application.
- Maven’s pom.xml and accompanying maven wrapper files handle builds.

##### Relationships and Interactions
- Data Flow:
- Controllers delegate processing to corresponding Use Case classes, each orchestrating business logic.
- Use Cases interact with Domain Repositories to persist or retrieve Entities.
- Mappers translate Entities to DTOs (and vice versa) for external communication.
- Security Interceptors (JWT related) are applied before controllers to validate requests.
- Database Integration:
- MySQL database as an external component with Flyway migrations handling schema evolution.

##### Architectural Patterns and Principles
- Clean Architecture & Domain Driven Design (DDD): Illustrate the separation between layers (presentation, application, domain, infrastructure). Emphasize dependency inversion (for instance, Domain doesn’t depend on infrastructure implementations).
- Single Responsibility: Each component, from controllers to mappers, is responsible for a well-defined part of the workflow.
- Stateless Authentication: Indicate the JWT-based security flow that ensures every request carries a token.
- Soft Delete: Mention that some domain entities use “soft delete” strategies (managed in use cases and repositories).

##### Final Suggestions
- Verify that the final design visually separates concerns as per Clean Architecture — ensuring that changes in, for example, the infrastructure (security, mappers, migrations) do not impact the core domain logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        A1("Controllers (Login, Topico, Resposta, Usuario)"):::presentation
        A2("DTOs"):::presentation
    end

    subgraph "Application Layer"
        B1("Use Cases"):::application
        B2("Use Case Exceptions"):::application
    end

    subgraph "Domain Layer"
        C1("Domain Entities"):::domain
        C2("Repository Interfaces"):::domain
    end

    subgraph "Infrastructure Layer"
        D1("Database Migrations"):::infrastructure
        D2("Mappers"):::infrastructure
        D3("Global Exception Handlers"):::infrastructure
        D4("Security Configurations & Filters"):::infrastructure
        D5("Security Services"):::infrastructure
    end

    subgraph "Configuration & Bootstrap"
        E1("Main Application"):::configuration
        E2("DataLoader Config"):::configuration
    end

    F("MySQL Database"):::external
    G("Client"):::external

    %% Data Flow
    G -- "HTTPRequest" --> A1
    D4 -- "ValidateJWT" --> A1
    D4 -- "Uses" --> D5
    A1 -- "Delegates" --> B1
    B1 -- "Handles" --> B2
    B1 -- "Persists" --> C2
    C2 -- "CRUD" --> F
    A1 -- "Maps" <--> D2
    A1 -- "Converts" <--> A2
    A1 -- "ErrorHandling" --> D3
    E1 -- "Bootstraps" --> E2

    %% Click Events
    click A1 "https://github.com/marceloaaps/forumhub-challenge-alura/tree/main/src/main/java/com/marcelospring/forumhub/presentation/controllers"
    click A2 "https://github.com/marceloaaps/forumhub-challenge-alura/tree/main/src/main/java/com/marcelospring/forumhub/presentation/dtos"
    click B1 "https://github.com/marceloaaps/forumhub-challenge-alura/tree/main/src/main/java/com/marcelospring/forumhub/core/use_cases"
    click B2 "https://github.com/marceloaaps/forumhub-challenge-alura/tree/main/src/main/java/com/marcelospring/forumhub/core/use_cases/exceptions"
    click C1 "https://github.com/marceloaaps/forumhub-challenge-alura/tree/main/src/main/java/com/marcelospring/forumhub/core/domain/entities"
    click C2 "https://github.com/marceloaaps/forumhub-challenge-alura/tree/main/src/main/java/com/marcelospring/forumhub/core/domain/repositories"
    click D1 "https://github.com/marceloaaps/forumhub-challenge-alura/tree/main/src/main/resources/db/migration"
    click D2 "https://github.com/marceloaaps/forumhub-challenge-alura/tree/main/src/main/java/com/marcelospring/forumhub/infra/mappers"
    click D3 "https://github.com/marceloaaps/forumhub-challenge-alura/tree/main/src/main/java/com/marcelospring/forumhub/infra/exceptions"
    click D4 "https://github.com/marceloaaps/forumhub-challenge-alura/tree/main/src/main/java/com/marcelospring/forumhub/infra/security/configurations"
    click D5 "https://github.com/marceloaaps/forumhub-challenge-alura/tree/main/src/main/java/com/marcelospring/forumhub/infra/security/service"
    click E1 "https://github.com/marceloaaps/forumhub-challenge-alura/blob/main/src/main/java/com/marcelospring/forumhub/ForumhubApplication.java"
    click E2 "https://github.com/marceloaaps/forumhub-challenge-alura/blob/main/src/main/java/com/marcelospring/forumhub/config/DataLoaderConfig.java"

    %% Styles
    classDef presentation fill:#F5A623,stroke:#333,stroke-width:2px;
    classDef application fill:#50E3C2,stroke:#333,stroke-width:2px;
    classDef domain fill:#B8E986,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#4A90E2,stroke:#333,stroke-width:2px;
    classDef configuration fill:#9013FE,stroke:#333,stroke-width:2px;
    classDef external fill:#cccccc,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
```
