# arllekws/saldinho architecture

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

- Interactive diagram: https://gitdiagram.com/arllekws/saldinho
- Repository: https://github.com/arllekws/saldinho

## Overview

##### Project Type and Purpose
- SALDINHO is a Java-based, object-oriented, layered (MVC-style) personal finance management application.
- It provides CRUD operations on financial entities (expenses, recipes/income, financial goals, users) with persistent storage via JDBC (MySQL/PostgreSQL).

##### High-Level Architectural Overview
SALDINHO follows a classic 3-layer architecture:
a. Presentation Layer (UI/Entry Point)
- src/Program/app/Main.java
- Responsible for reading user commands (console or GUI stub), invoking services.
b. Business Logic Layer (Services)
- src/Program/{Expense,Goal,Recipe,User}/*Service.java
- Enforces business rules, orchestrates operations on domain entities.
c. Data Access / Persistence Layer
- src/Program/Util/Conexao.java (JDBC connection factory)
- CRUD via Service classes using JDBC to interact with the database.
d. Domain Model (Entities)
- src/Entities/*.java (Expense, Recipe, FinancialGoal, User, Transacao)
- Encapsulate data attributes and domain methods.

##### Main Components
- Client / User Interface (CLI or future GUI)
- Main Application Entry (Main.java)
- Service Components (ExpenseService, GoalService, RecipeService, UserService)
- Domain Entities (models)
- Persistence Connector (Conexao)
- Relational Database (MySQL/PostgreSQL)

##### Relationships and Data Flow
- User → Main: issues commands.
- Main → [X]Service: triggers business operations.
- [X]Service ↔ Entities: manipulates domain objects.
- [X]Service → Conexao: opens connections, executes SQL.
- Conexao ↔ Database: reads/writes tables.
- Services return results/entities → Main → User.

##### Architectural Patterns & Principles
- Layered Architecture (Presentation → Business → Persistence).
- SOLID principles in service and entity classes (single responsibility, dependency inversion via Conexao).
- Test coverage via corresponding Test classes in each package (ExpenseTest, ServiceTest, etc.).

##### Technologies & Frameworks
- Java 11+ (or compatible)
- JDBC for database interaction
- MySQL/PostgreSQL (configurable via .env)
- JUnit for testing

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        User["User"]:::external
        Main["Main.java"]:::presentation
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        ExpenseService["ExpenseService"]:::service
        GoalService["GoalService"]:::service
        RecipeService["RecipeService"]:::service
        UserService["UserService"]:::service
    end

    %% Domain Model
    subgraph "Domain Model"
        Expense["Expense"]:::domain
        Recipe["Recipe"]:::domain
        FinancialGoal["FinancialGoal"]:::domain
        UserEntity["User"]:::domain
        Transacao["Transacao"]:::domain
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        Conexao["Conexao (JDBC Connection Pool/Fabric)"]:::util
        DB(("MySQL/PostgreSQL")):::database
    end

    %% Relationships
    User -->|"issues commands"| Main
    Main -->|"createExpense(), getAllExpenses()"| ExpenseService
    Main -->|"createGoal(), getAllGoals()"| GoalService
    Main -->|"createRecipe(), getAllRecipes()"| RecipeService
    Main -->|"createUser(), getUser()"| UserService

    ExpenseService -->|"manipulates"| Expense
    GoalService -->|"manipulates"| FinancialGoal
    RecipeService -->|"manipulates"| Recipe
    UserService -->|"manipulates"| UserEntity
    ExpenseService -->|"records transaction"| Transacao
    RecipeService -->|"records transaction"| Transacao
    UserService -->|"records transaction"| Transacao

    ExpenseService -->|"openConnection(), executeSQL()"| Conexao
    GoalService -->|"openConnection(), executeSQL()"| Conexao
    RecipeService -->|"openConnection(), executeSQL()"| Conexao
    UserService -->|"openConnection(), executeSQL()"| Conexao

    Conexao -->|"read/write tables"| DB

    %% Return Flows
    DB -->|<<returns ResultSet>>| Conexao
    Conexao -->|<<returns data>>| ExpenseService
    Conexao -->|<<returns data>>| GoalService
    Conexao -->|<<returns data>>| RecipeService
    Conexao -->|<<returns data>>| UserService
    ExpenseService -->|<<returns entities>>| Main
    GoalService -->|<<returns entities>>| Main
    RecipeService -->|<<returns entities>>| Main
    UserService -->|<<returns entities>>| Main
    Main -->|<<displays results>>| User

    %% Click Events
    click Main "https://github.com/arllekws/saldinho/blob/main/src/Program/app/Main.java"
    click ExpenseService "https://github.com/arllekws/saldinho/blob/main/src/Program/Expense/ExpenseService.java"
    click GoalService "https://github.com/arllekws/saldinho/blob/main/src/Program/Goal/GoalService.java"
    click RecipeService "https://github.com/arllekws/saldinho/blob/main/src/Program/Recipe/RecipeService.java"
    click UserService "https://github.com/arllekws/saldinho/blob/main/src/Program/User/UserService.java"
    click Conexao "https://github.com/arllekws/saldinho/blob/main/src/Program/Util/Conexao.java"
    click Expense "https://github.com/arllekws/saldinho/blob/main/src/Entities/Expense.java"
    click Recipe "https://github.com/arllekws/saldinho/blob/main/src/Entities/Recipe.java"
    click FinancialGoal "https://github.com/arllekws/saldinho/blob/main/src/Entities/FinancialGoal.java"
    click UserEntity "https://github.com/arllekws/saldinho/blob/main/src/Entities/User.java"
    click Transacao "https://github.com/arllekws/saldinho/blob/main/src/Transacao.java"

    %% Styles
    classDef presentation fill:#cce5ff,stroke:#005cbf,color:#005cbf,stroke-width:1px;
    classDef service fill:#d4edda,stroke:#155724,color:#155724,stroke-width:1px;
    classDef domain fill:#fff3cd,stroke:#856404,color:#856404,stroke-width:1px;
    classDef util fill:#e2e3e5,stroke:#6c757d,color:#6c757d,stroke-width:1px;
    classDef database fill:#ffe5b4,stroke:#ff8c00,color:#ff8c00,stroke-width:1px;
    classDef external fill:#f8d7da,stroke:#721c24,color:#721c24,stroke-width:1px;
```
