# maximusf/wallet-watch architecture

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

- Interactive diagram: https://gitdiagram.com/maximusf/wallet-watch
- Repository: https://github.com/maximusf/wallet-watch

## Overview

##### Project type and purpose
- Wallet-Watch is a Java-based, command-line personal budget manager. It’s a monolithic, layered application with a CLI “UI,” a service layer, a DAO (data access) layer, a domain (models) layer, and a MySQL database backend.

##### File structure
- Top-level folders:
- bin/ (compiled .class files)
- lib/ (MySQL connector jar)
- db/ (schema & reset scripts)
- src/ (source code, subdivided into dao, models, services, util, test)
- planning/ (flowchart PDF)
- Key files:
- Main.java: application entrypoint
- dao/*.java: CRUD operations for Transaction, Income, Expense
- services/*.java: business rules, validation, error handling
- models/*.java: domain objects, inheritance (Transaction → Income/Expense)
- util/Environment.java & PrintBuilder.java: config loader & console formatting

##### README for architectural insights
- Confirms layered OOP design: inheritance, encapsulation, abstraction in service/DAO layers, PrintBuilder for output formatting, MySQL for persistence.
- No external web or microservice components, but a clear separation of concerns and a console UI.

##### Components
a. User / CLI (Main + PrintBuilder)
b. Service Layer (ExpenseService, IncomeService, Transaction orchestration)
c. DAO Layer (ExpenseDAO, IncomeDAO, TransactionDAO)
d. Domain Models (Transaction ← Income, Expense)
e. Utilities (Environment, PrintBuilder)
f. Database (MySQL with schema.sql, reset_db.sql)
g. External library (mysql-connector-j)

##### Relationships & Data Flow
- User types commands → Main invokes PrintBuilder → Main calls appropriate Service
- Service enforces rules & validation → calls DAO
- DAO executes SQL queries on MySQL → returns data models
- Service may transform models → PrintBuilder formats & prints results
- Environment utility reads DB connection settings → DAO uses them

##### Architectural patterns & principles
- Layered Architecture: UI → Service → DAO → Database
- Inheritance/Polymorphism: Transaction base class, Income/Expense subclasses
- DAO Pattern for persistence
- Single Responsibility: each package has a clear role
- Abstraction: Service/DAO interfaces hide implementation details from Main

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI and Utilities Layer
    subgraph "UI & Utilities Layer"
        direction TB
        User["User / CLI"]:::ui
        Main["Main"]:::ui
        PrintBuilder["PrintBuilder"]:::ui
        Environment["Environment"]:::ui
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        ExpenseService["ExpenseService"]:::service
        IncomeService["IncomeService"]:::service
    end

    %% DAO Layer
    subgraph "DAO Layer"
        direction TB
        ExpenseDAO["ExpenseDAO"]:::dao
        IncomeDAO["IncomeDAO"]:::dao
        TransactionDAO["TransactionDAO"]:::dao
    end

    %% Domain Models Layer
    subgraph "Domain Models"
        direction TB
        Transaction["Transaction"]:::model
        Expense["Expense"]:::model
        Income["Income"]:::model
    end

    %% Database Layer
    subgraph "Database"
        direction TB
        MySQL["MySQL Database"]:::db
        Schema["schema.sql"]:::db
        Reset["reset_db.sql"]:::db
    end

    %% External Library
    ExternalLib["mysql-connector-j-9.1.0.jar"]:::ext

    %% Connections
    User -->|"runs"| Main
    Main -->|"loadConfig()"| Environment
    Main -->|"formatOutput()"| PrintBuilder
    Main -->|"invokeService()"| ExpenseService
    Main -->|"invokeService()"| IncomeService

    ExpenseService -->|"validate() / business rules"| ExpenseDAO
    IncomeService -->|"validate() / business rules"| IncomeDAO

    ExpenseDAO -->|"use Env settings"| Environment
    IncomeDAO -->|"use Env settings"| Environment
    TransactionDAO -->|"use Env settings"| Environment

    ExpenseDAO -->|"executeQuery()"| MySQL
    IncomeDAO -->|"executeQuery()"| MySQL
    TransactionDAO -->|"executeQuery()"| MySQL

    ExpenseDAO -->|"models"| Expense
    IncomeDAO -->|"models"| Income
    TransactionDAO -->|"models"| Transaction

    ExpenseService -->|"returns models"| Expense
    IncomeService -->|"returns models"| Income

    PrintBuilder -->|"formats models"| Expense
    PrintBuilder -->|"formats models"| Income

    ExternalLib ---|connects| MySQL

    Schema --> MySQL
    Reset --> MySQL

    %% Inheritance
    Transaction -->|extends| Expense
    Transaction -->|extends| Income

    %% Click Events
    click Main "https://github.com/maximusf/wallet-watch/blob/main/src/Main.java"
    click PrintBuilder "https://github.com/maximusf/wallet-watch/blob/main/src/util/PrintBuilder.java"
    click Environment "https://github.com/maximusf/wallet-watch/blob/main/src/util/Environment.java"
    click ExpenseService "https://github.com/maximusf/wallet-watch/blob/main/src/services/ExpenseService.java"
    click IncomeService "https://github.com/maximusf/wallet-watch/blob/main/src/services/IncomeService.java"
    click ExpenseDAO "https://github.com/maximusf/wallet-watch/blob/main/src/dao/ExpenseDAO.java"
    click IncomeDAO "https://github.com/maximusf/wallet-watch/blob/main/src/dao/IncomeDAO.java"
    click TransactionDAO "https://github.com/maximusf/wallet-watch/blob/main/src/dao/TransactionDAO.java"
    click Transaction "https://github.com/maximusf/wallet-watch/blob/main/src/models/Transaction.java"
    click Expense "https://github.com/maximusf/wallet-watch/blob/main/src/models/Expense.java"
    click Income "https://github.com/maximusf/wallet-watch/blob/main/src/models/Income.java"
    click Schema "https://github.com/maximusf/wallet-watch/blob/main/db/schema.sql"
    click Reset "https://github.com/maximusf/wallet-watch/blob/main/db/reset_db.sql"
    click ExternalLib "https://github.com/maximusf/wallet-watch/blob/main/lib/mysql-connector-j-9.1.0.jar"

    %% Styles
    classDef ui fill:#E3F2FD,stroke:#2196F3,color:#0D47A1
    classDef service fill:#E8F5E9,stroke:#388E3C,color:#1B5E20
    classDef dao fill:#FFF3E0,stroke:#F57C00,color:#E65100
    classDef model fill:#F3E5F5,stroke:#8E24AA,color:#4A148C
    classDef db fill:#ECEFF1,stroke:#607D8B,color:#263238
    classDef ext fill:#FFEBEE,stroke:#D32F2F,color:#B71C1C
```
