# pennamoro/back-lama architecture

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

- Interactive diagram: https://gitdiagram.com/pennamoro/back-lama
- Repository: https://github.com/pennamoro/back-lama

## Overview

##### Main Components
- Frontend (external): Although not part of this repository, the README reminds you to run the front-end from a separate repository (https://github.com/gealberti/Lama). Represent this externally and show its connection to the backend via APIs.
- Back-end Application: The core of this project, built using Java Spring. This component hosts:
a. Controllers (REST endpoints): e.g., AvaliacaoController, CategoriaController, EtapasController, etc.
b. Service Layer: Contains business logic (e.g., AvaliacaoService, CategoriaService, RegraAssociacaoService, etc.).
c. Repository/Data Access Layer: Handles database interaction (e.g., UsuarioRepository, ReceitaRepository, etc.), encapsulated via Spring Data JPA.
d. Model/Entity layer: Domain models representing the database structure (e.g., Usuario, Receita, Material, etc.).
e. DTOs: For transferring data between the client and server layers with data transformation.
f. Security: The SecurityConfig class indicates there is a security configuration (likely for authentication/authorization).
- Database: The project uses a PostgreSQL database. The “database” directory contains scripts and backup files to create and populate the database (Database.db and lama.bkp).
- Python Scripts: Under python-scripts, you have Jupyter notebooks and CSV files that were used to generate association rules. Although these are run separately, they integrate with the backend (likely through a service like RegraAssociacaoService) to enrich recommendation capabilities.

##### Relationships and Data Flow
- The REST Controllers receive HTTP requests (from the front-end or clients) and forward input to the corresponding Services.
- Services implement the business logic, which may involve calling methods on Repositories to fetch or persist data to Postgres.
- The Model/Entities map directly to database tables and database relations. Use UML-style aggregation/composition to show relationships if needed.
- DTOs act as intermediaries between the client data and internal domain objects.
- The Security layer ensures that the endpoints are appropriately secured.
- Python scripts perform data analysis independently; the results (like generated association rules) might be stored or accessed by the Java application (via RegraAssociacaoService) to enhance personalized recommendations.

##### Architectural Patterns and Technologies
- MVC Pattern: Clearly separate Controllers (presentation layer), Services (business logic), and Repositories/Models (data persistence).
- Dependency Injection and Repository Pattern: Standard in Spring applications.
- Use of Maven for project build and dependency management.
- PostgreSQL as the main database, with instructions and initial data scripts provided.
- Integration with external (Python-based) data analysis for recommendation rules.
- Technologies: Java Spring Boot, Maven, JDK 17, PostgreSQL, and Python (for data analysis).

##### Detailed Elements to be Included
- A detailed group for the Back-end Application that includes:
- Controllers (with individual controller names noted, if desired).
- Repository/Data Access Layer (annotate with key repository classes).
- Model/DTO layer (show that these serve as the representations/transfer objects).
- Security Configuration (to denote the interception of requests and handling of authentication/authorization).
- A separate section for “Python Scripts for Association Rule Mining” linked to the RegraAssociacaoService in the backend, indicating that data processing scripts contribute to generating recommendations.
- Client → Controller → Service → Repository → Database.
- Python Scripts → (data/rules output) → RegraAssociacaoService for recommendation logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["External Frontend Client"]:::external
    B["Security Configuration"]:::security
    C["Controllers (REST APIs)"]:::controller
    D["Service Layer (Business Logic)"]:::service
    E["Repositories (Data Access)"]:::repository
    F["PostgreSQL Database"]:::database
    G["Domain Models"]:::models
    H["Data Transfer Objects"]:::dto
    I["Python Scripts for Association Rule Mining"]:::python

    A -->|"sends request"| B
    B -->|"secures"| C
    C -->|"delegates to"| D
    D -->|"calls"| E
    E -->|"persists data to"| F
    D -->|"utilizes"| G
    D -->|"transforms via"| H
    I -->|"provides rules to"| D

    click C "https://github.com/pennamoro/back-lama/tree/master/src/main/java/com/example/backlama/controllers"
    click D "https://github.com/pennamoro/back-lama/tree/master/src/main/java/com/example/backlama/services"
    click E "https://github.com/pennamoro/back-lama/tree/master/src/main/java/com/example/backlama/repositories"
    click G "https://github.com/pennamoro/back-lama/tree/master/src/main/java/com/example/backlama/models"
    click H "https://github.com/pennamoro/back-lama/tree/master/src/main/java/com/example/backlama/dto"
    click B "https://github.com/pennamoro/back-lama/blob/master/src/main/java/com/example/backlama/security/SecurityConfig.java"
    click F "https://github.com/pennamoro/back-lama/tree/master/database"
    click I "https://github.com/pennamoro/back-lama/tree/master/python-scripts"

    classDef external fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef security fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef controller fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef service fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef repository fill:#f7d6bf,stroke:#333,stroke-width:2px;
    classDef database fill:#ffe6b3,stroke:#333,stroke-width:2px;
    classDef models fill:#ffe6e6,stroke:#333,stroke-width:2px;
    classDef dto fill:#e6ffe6,stroke:#333,stroke-width:2px;
    classDef python fill:#f0e68c,stroke:#333,stroke-width:2px;
```
