# jgmacedo/chacomsenhorbackend architecture

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

- Interactive diagram: https://gitdiagram.com/jgmacedo/chacomsenhorbackend
- Repository: https://github.com/jgmacedo/chacomsenhorbackend

## Overview

##### Project Type and Purpose
- This is a Java full-stack back-end application built with Spring Boot, providing REST APIs to manage various domain objects (users, Bible verses, devotionals) along with scheduling functionalities and AI service testing.
- The README clearly highlights key features, API endpoints, and both development/test and production aspects (e.g., database configuration, Maven build scripts).

##### Main Components
a. Spring Boot Application Bootstrapping:
- ChaComOSenhorApplication.java as the entry point.
b. Controllers (API Layer):
- Controllers such as AdminController and AuthenticationController.
- These handle incoming HTTP requests, mapping various endpoints (/admin/users, /admin/get_all_bible_verses, etc.) to service calls.
c. Services (Business Logic Layer):
- Service classes (BibleVerseService, DevotionalService, AuthenticationService, AiService, and others) that encapsulate core business logic.
d. Domain (Model Layer):
- Domain objects like User, BibleVerse, Devotional, and corresponding DTOs (Data Transfer Objects).
e. Repositories (Data Access Layer):
- Repositories (BibleVerseRepository, DevotionalRepository, UserRepository) that act as the interface between services and the SQL database.
f. Infrastructure / Security:
- Security package components (SecurityConfig, SecurityFilter, TokenService) which handle authentication and token management.
g. Database & Migrations:
- SQL database as an external component.
- That schema and migration files (located in src/main/resources/db/migration) are used to manage database schema versioning.
h. Testing:
- Test package (src/test) that contains unit tests like AiServiceTest and ContextLoadTest.

##### Relationships and Interactions
- The REST API (Controllers) receives client requests and delegates them to the Services.
- Services contain the business logic and call the Repositories to interact with the database.
- The Domain layer objects and DTOs are used both by the controllers for input/output and internally by services/repositories.
- The Security layer intercepts incoming API calls, validating tokens and enforcing access control.
- Optionally, include external integrations like scheduling features and AI service tests to indicate asynchronous or specialized processing.

##### Architectural Patterns and Design Principles
- The project clearly follows a layered architecture (Controller, Service, Repository) common in Spring Boot applications.
- Separation of concerns is evident – domain models are kept isolated from business logic and persistence.
- Make note of RESTful design patterns for API endpoints as well as use of Maven for dependency management, and SQL-based migrations that ensure database versioning.

- Use clear labels for each component: Name controllers, services, and repositories explicitly.
- From the client (or “API Consumer”) to Controllers.
- From Controllers to Services.
- From Services to Repositories.
- From Repositories to the Database.
- A side connection from the API layer to a Security module.
- Optionally, include annotations that mention the key frameworks (Spring Boot for the application, Maven for builds, SQL for database migration) and technologies.

##### Detailed Representation
- You might group the domain sub-directories (bible_verse, devotional, user) under a single “Domain Model” section to reduce clutter, but note each module’s specific DTOs and responsibilities.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Client
    Client["API Consumer"]:::external

    %% Entry Point
    subgraph "Entry Point"
        E1["ChaComOSenhorApplication (Entry Point)"]:::entry
    end

    %% API Layer - Controllers
    subgraph "API Layer - Controllers"
        C1["AdminController (API)"]:::controller
        C2["AuthenticationController (API)"]:::controller
    end

    %% Business Logic - Services
    subgraph "Business Logic - Services"
        S1["BibleVerseService"]:::service
        S2["DevotionalService"]:::service
        S3["AuthenticationService"]:::service
        S4["AiService"]:::service
        S5["ApiResponseParserService"]:::service
        S6["ResponseBuilderService"]:::service
    end

    %% Domain Model
    subgraph "Domain Model"
        D1["BibleVerse Domain/DTOs"]:::domain
        D2["Devotional Domain/DTOs"]:::domain
        D3["User Domain/DTOs"]:::domain
    end

    %% Data Access - Repositories
    subgraph "Data Access - Repositories"
        R1["BibleVerseRepository"]:::repo
        R2["DevotionalRepository"]:::repo
        R3["UserRepository"]:::repo
    end

    %% Security Layer
    subgraph "Security Layer"
        Sec1["SecurityConfig"]:::security
        Sec2["SecurityFilter"]:::security
        Sec3["TokenService"]:::security
    end

    %% Database & Migrations
    subgraph "Database & Migrations"
        DB["SQL Database & Migrations"]:::db
    end

    %% Testing
    subgraph "Testing"
        T1["AiServiceTest"]:::test
        T2["ContextLoadTest"]:::test
    end

    %% Connections
    Client -->|"secured"| Sec1
    Sec1 --> C1
    Sec1 --> C2

    E1 --> C1
    E1 --> C2

    C1 -->|"calls"| S1
    C1 -->|"calls"| S2
    C2 -->|"calls"| S3
    C2 -->|"calls"| S4

    S1 -->|"uses"| D1
    S2 -->|"uses"| D2
    S3 -->|"uses"| D3

    S1 --> R1
    S2 --> R2
    S3 --> R3

    R1 --> DB
    R2 --> DB
    R3 --> DB

    %% Additional Service Utilities (internal orchestration)
    S5 --> S6

    %% Testing connections
    T1 --> S4
    T2 --> E1

    %% Styles
    classDef entry fill:#FFEEAD,stroke:#D48B00,stroke-width:2px;
    classDef controller fill:#D0E6A5,stroke:#6E8B3D,stroke-width:2px;
    classDef service fill:#BEE9EB,stroke:#2E9CCA,stroke-width:2px;
    classDef domain fill:#F3B0C3,stroke:#AE3A5F,stroke-width:2px;
    classDef repo fill:#C3CDE6,stroke:#3457AC,stroke-width:2px;
    classDef security fill:#E0C3FC,stroke:#8A50B8,stroke-width:2px;
    classDef db fill:#FFEFD5,stroke:#D2691E,stroke-width:2px;
    classDef test fill:#D3D3D3,stroke:#808080,stroke-width:2px;
    classDef external fill:#E8F6F3,stroke:#00796B,stroke-width:2px;

    %% Click Events
    click E1 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/main/java/joao/ChaComOSenhor/ChaComOSenhorApplication.java"
    click C1 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/main/java/joao/ChaComOSenhor/controllers/AdminController.java"
    click C2 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/main/java/joao/ChaComOSenhor/controllers/AuthenticationController.java"
    click S1 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/main/java/joao/ChaComOSenhor/services/BibleVerseService.java"
    click S2 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/main/java/joao/ChaComOSenhor/services/DevotionalService.java"
    click S3 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/main/java/joao/ChaComOSenhor/services/AuthenticationService.java"
    click S4 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/main/java/joao/ChaComOSenhor/services/AiService.java"
    click S5 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/main/java/joao/ChaComOSenhor/services/ApiResponseParserService.java"
    click S6 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/main/java/joao/ChaComOSenhor/services/ResponseBuilderService.java"
    click D1 "https://github.com/jgmacedo/chacomsenhorbackend/tree/main/src/main/java/joao/ChaComOSenhor/domain/bible_verse/"
    click D2 "https://github.com/jgmacedo/chacomsenhorbackend/tree/main/src/main/java/joao/ChaComOSenhor/domain/devotional/"
    click D3 "https://github.com/jgmacedo/chacomsenhorbackend/tree/main/src/main/java/joao/ChaComOSenhor/domain/user/"
    click R1 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/main/java/joao/ChaComOSenhor/repositories/BibleVerseRepository.java"
    click R2 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/main/java/joao/ChaComOSenhor/repositories/DevotionalRepository.java"
    click R3 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/main/java/joao/ChaComOSenhor/repositories/UserRepository.java"
    click Sec1 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/main/java/joao/ChaComOSenhor/infra/security/SecurityConfig.java"
    click Sec2 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/main/java/joao/ChaComOSenhor/infra/security/SecurityFilter.java"
    click Sec3 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/main/java/joao/ChaComOSenhor/infra/security/TokenService.java"
    click DB "https://github.com/jgmacedo/chacomsenhorbackend/tree/main/src/main/resources/db/migration/"
    click T1 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/test/java/joao/ChaComOSenhor/services/AiServiceTest.java"
    click T2 "https://github.com/jgmacedo/chacomsenhorbackend/blob/main/src/test/java/joao/ChaComOSenhor/services/ContextLoadTest.java"
```
