# rashidinvincible/mini-expense-manager architecture

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

- Interactive diagram: https://gitdiagram.com/rashidinvincible/mini-expense-manager
- Repository: https://github.com/rashidinvincible/mini-expense-manager

## Overview

##### Project Type and Purpose
- This is a backend microservice (Spring Boot) for a “Mini Expense Manager.”
- Purpose: expose REST endpoints to create/list expenses, flag anomalies, bulk‐upload via CSV, and produce dashboard summaries.
- Technology stack: Java 17, Spring Boot, Spring Data JPA, PostgreSQL, Lombok, Maven.

##### File Structure
- Standard Maven layout with `pom.xml` and `src/main/java/com/example/expensemanager`.
- Layered packages:
- controller (ExpenseController)
- service (ExpenseService)
- repository (ExpenseRepository)
- model (Expense, DashboardSummary, etc.)
- Config in `src/main/resources/application.properties` pointing to PostgreSQL.
- Test suite under `src/test/java`.

##### Key README Insights
- Endpoints:
- POST /api/expenses (manual entry)
- GET /api/expenses (list)
- GET /api/expenses/anomalies (flagged)
- POST /api/expenses/upload-csv (bulk CSV)
- Rule-based categorization and anomaly logic live in ExpenseService.
- No frontend in this repo.

##### Main Components
a. Client (Postman, future React UI)
b. API Layer (Spring Boot REST Controllers)
c. Business Layer (ExpenseService)
d. Persistence Layer (ExpenseRepository via Spring Data JPA)
e. Database (PostgreSQL)
f. CSV Processor (part of ExpenseService)
g. Hardcoded Category-Mapping Rules (within Service)
h. Dashboard Generator (Service-provided summary DTO)

##### Relationships and Data Flow
- Client → HTTP call → Controller
- Controller forwards DTOs to Service
- Service applies rules, invokes Repository
- Repository CRUD queries → PostgreSQL
- Service retrieves raw data → computes anomalies & dashboard DTOs → Controller → Client
- CSV upload path: Controller receives file → Service parses CSV → calls Repository in batch

##### Architectural Patterns & Design Principles
- Layered (Controller → Service → Repository → Database)
- Single Spring Boot application (monolith)
- Separation of concerns: REST, business logic, persistence
- DTO & Entity distinction: models vs summaries (DashboardSummary)
- Rule engine (hardcoded) encapsulated in service for future extension

##### Elements
- Clear labels: component names, endpoint URIs
- Sub‐component details: CSV Parser, Anomaly Detector, Dashboard Calculator

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Client
    Client["Client (Postman / Future UI)"]:::external

    %% Spring Boot Application Boundary
    subgraph "Spring Boot Application"
        direction TB
        Application["ExpenseManagerApplication\n(Spring Boot Bootstrap)"]:::application
        Controller["ExpenseController\n(Spring MVC)"]:::controller
        Service["ExpenseService\n(Java 17, Business Logic)"]:::service

        subgraph "Service Internals"
            direction TB
            CSV["CSV Processor"]:::service
            Rules["Rule Engine\n(Category Mapping)"]:::service
            Anomaly["Anomaly Detector"]:::service
            Dashboard["Dashboard Calculator"]:::service
        end

        Repository["ExpenseRepository\n(Spring Data JPA)"]:::repository

        subgraph "Models"
            direction TB
            ExpenseEntity["Expense Entity"]:::model
            DashboardSummary["DashboardSummary DTO"]:::model
        end
    end

    %% Database
    DB["PostgreSQL"]:::db

    %% Test Suite (omitted in prod flow)
    Test["ExpenseManagerApplicationTests\n(Test Suite)"]:::test

    %% Build & Config
    Pom["pom.xml"]:::config
    Config["application.properties\n(DB Config)"]:::config

    %% Connections
    Client -->|"POST/GET endpoints"| Controller
    Controller -->|"invokes Service"| Service
    Service -->|"process CSV"| CSV
    Service -->|"apply rules"| Rules
    Service -->|"detect anomalies"| Anomaly
    Service -->|"compute summaries"| Dashboard
    Service -->|"save()/findAll()"| Repository
    Repository -->|"SQL queries"| DB
    Controller -.->|"tested by"| Test
    Application --> Controller
    Application --> Service
    Application --> Repository
    Application --> Config
    Application --> Pom

    %% Click Events
    click Controller "https://github.com/rashidinvincible/mini-expense-manager/blob/main/src/main/java/com/example/expensemanager/controller/ExpenseController.java"
    click Service "https://github.com/rashidinvincible/mini-expense-manager/blob/main/src/main/java/com/example/expensemanager/service/ExpenseService.java"
    click Repository "https://github.com/rashidinvincible/mini-expense-manager/blob/main/src/main/java/com/example/expensemanager/repository/ExpenseRepository.java"
    click ExpenseEntity "https://github.com/rashidinvincible/mini-expense-manager/blob/main/src/main/java/com/example/expensemanager/model/Expense.java"
    click DashboardSummary "https://github.com/rashidinvincible/mini-expense-manager/blob/main/src/main/java/com/example/expensemanager/model/DashboardSummary.java"
    click Application "https://github.com/rashidinvincible/mini-expense-manager/blob/main/src/main/java/com/example/expensemanager/ExpenseManagerApplication.java"
    click Config "https://github.com/rashidinvincible/mini-expense-manager/blob/main/src/main/resources/application.properties"
    click Pom "https://github.com/rashidinvincible/mini-expense-manager/blob/main/pom.xml"
    click Test "https://github.com/rashidinvincible/mini-expense-manager/blob/main/src/test/java/com/example/expensemanager/ExpenseManagerApplicationTests.java"

    %% Styles
    classDef external fill:#F2F2F2,stroke:#333,stroke-width:1px
    classDef controller fill:#AED6F1,stroke:#333,stroke-width:1px
    classDef service fill:#A9DFBF,stroke:#333,stroke-width:1px
    classDef repository fill:#76D7C4,stroke:#333,stroke-width:1px
    classDef db fill:#F5B041,stroke:#333,stroke-width:1px,shape:cylinder
    classDef test fill:#D5DBDB,stroke:#333,stroke-dasharray: 5 5
    classDef model fill:#E5E8E8,stroke:#333,stroke-width:1px
    classDef application fill:#D2B4DE,stroke:#333,stroke-width:1px
    classDef config fill:#E8DAEF,stroke:#333,stroke-width:1px
```
