# contre95/expense-mate architecture

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

- Interactive diagram: https://gitdiagram.com/contre95/expense-mate
- Repository: https://github.com/contre95/expense-mate

## Overview

##### Main Components Identification

The project follows a clean architecture pattern with clear separation of concerns. The main components to represent are:

a) Presentation Layer:
- Web UI (Fiber + HTMX)
- Telegram Bot Interface
- REST API

b) Application Layer:
- Analyzing Module
- Managing Module
- Querying Module
- Tracking Module
- Health Module

c) Domain Layer:
- Expense Domain
- Rules Domain
- Users Domain

d) Infrastructure Layer (Gateways):
- Storage (SQL and JSON)
- Logger
- Password Hasher

##### Specific Components Detail

Frontend Section:
- Web UI components (dashboard, expenses, settings, importers)
- HTMX integration points
- Static assets and views

Application Services:
- Four main modules (analyzing, managing, querying, tracking)
- Their interaction with the domain layer

Storage Layer:
- Both SQL (expenses, rules) and JSON (users) storage
- Database schema relationships

##### Integration Points

- N26 CSV import workflow
- Telegram bot command flow
- API endpoints

##### Additional Elements

Include:
- Configuration components (.env, air.toml)
- External service connections (Telegram API)
- Security layer (password hashing)

- The clean architecture pattern
- The dual interface nature (Web + Telegram)
- The flexible storage engine design (SQL/SQLite + JSON)
- The rule-based categorization system

This project particularly requires emphasis on:

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef presentation fill:#3498db,color:white
    classDef application fill:#2ecc71,color:white
    classDef domain fill:#f1c40f,color:black
    classDef infrastructure fill:#95a5a6,color:white
    classDef storage fill:#34495e,color:white

    %% Presentation Layer
    subgraph Presentation
        WebUI["🌐 Web UI"]
        TelegramBot["🤖 Telegram Bot"]
        RestAPI["🌐 REST API"]
        
        subgraph WebViews
            Dashboard["📊 Dashboard"]
            Expenses["💰 Expenses"]
            Settings["⚙️ Settings"]
            Importers["📥 Importers"]
        end
        
        StaticAssets["📁 Static Assets"]
        CSS["🎨 CSS"]
        JS["📜 JavaScript"]
    end

    %% Application Layer
    subgraph Application
        Analyzing["📊 Analyzing Service"]
        Managing["⚙️ Managing Service"]
        Querying["🔍 Querying Service"]
        Tracking["📝 Tracking Service"]
        Health["💓 Health Service"]
    end

    %% Domain Layer
    subgraph Domain
        ExpenseDomain["💰 Expense Domain"]
        RulesDomain["📋 Rules Domain"]
        UsersDomain["👤 Users Domain"]
    end

    %% Infrastructure Layer
    subgraph Infrastructure
        SQLStorage["💾 SQL Storage"]
        JSONStorage["📄 JSON Storage"]
        Logger["📝 Logger"]
        PasswordHasher["🔒 Password Hasher"]
    end

    %% Relationships
    WebUI --> RestAPI
    TelegramBot --> RestAPI
    RestAPI --> |API Calls| Application
    
    WebViews --> WebUI
    StaticAssets --> WebUI
    CSS --> StaticAssets
    JS --> StaticAssets
    
    Analyzing --> ExpenseDomain
    Managing --> ExpenseDomain
    Querying --> ExpenseDomain
    Tracking --> ExpenseDomain
    
    ExpenseDomain --> RulesDomain
    ExpenseDomain --> UsersDomain
    
    ExpenseDomain --> SQLStorage
    RulesDomain --> SQLStorage
    UsersDomain --> JSONStorage
    
    Application --> Logger
    Application --> PasswordHasher

    %% Styles Application
    class WebUI,TelegramBot,RestAPI presentation
    class Analyzing,Managing,Querying,Tracking,Health application
    class ExpenseDomain,RulesDomain,UsersDomain domain
    class SQLStorage,JSONStorage,Logger,PasswordHasher infrastructure

    %% Click Events
    click WebUI "https://github.com/contre95/expense-mate/tree/main/pkg/presenters/rest/ui/"
    click TelegramBot "https://github.com/contre95/expense-mate/tree/main/pkg/presenters/telegram/"
    click RestAPI "https://github.com/contre95/expense-mate/tree/main/pkg/presenters/rest/api/"
    
    click Analyzing "https://github.com/contre95/expense-mate/tree/main/pkg/app/analyzing/"
    click Managing "https://github.com/contre95/expense-mate/tree/main/pkg/app/managing/"
    click Querying "https://github.com/contre95/expense-mate/tree/main/pkg/app/querying/"
    click Tracking "https://github.com/contre95/expense-mate/tree/main/pkg/app/tracking/"
    click Health "https://github.com/contre95/expense-mate/tree/main/pkg/app/health/"
    
    click ExpenseDomain "https://github.com/contre95/expense-mate/blob/main/pkg/domain/expense/expense.go"
    click RulesDomain "https://github.com/contre95/expense-mate/blob/main/pkg/domain/expense/rules.go"
    click UsersDomain "https://github.com/contre95/expense-mate/blob/main/pkg/domain/expense/users.go"
    
    click SQLStorage "https://github.com/contre95/expense-mate/tree/main/pkg/gateways/storage/sqlstorage/"
    click JSONStorage "https://github.com/contre95/expense-mate/tree/main/pkg/gateways/storage/jsonstorage/"
    click Logger "https://github.com/contre95/expense-mate/tree/main/pkg/gateways/logger/"
    click PasswordHasher "https://github.com/contre95/expense-mate/tree/main/pkg/gateways/hasher/"
    
    click Dashboard "https://github.com/contre95/expense-mate/tree/main/views/sections/dashboard/"
    click Expenses "https://github.com/contre95/expense-mate/tree/main/views/sections/expenses/"
    click Settings "https://github.com/contre95/expense-mate/tree/main/views/sections/settings/"
    click Importers "https://github.com/contre95/expense-mate/tree/main/views/sections/importers/"
    
    click StaticAssets "https://github.com/contre95/expense-mate/tree/main/public/assets/"
    click CSS "https://github.com/contre95/expense-mate/tree/main/public/assets/css/"
    click JS "https://github.com/contre95/expense-mate/tree/main/public/assets/js/"
```
