# eatekha/myfinance architecture

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

- Interactive diagram: https://gitdiagram.com/eatekha/myfinance
- Repository: https://github.com/eatekha/myfinance

## Overview

##### Project type and purpose
- MyFinance is a full-stack, single-page personal finance application.
- Purpose: enable users to register/login, add income/expense entries, categorize them (leveraging a simple ML component), set budgets, and view charts/reports.

##### File structure
- Top level:
- public/index.html → hosts the front-end SPA
- src/api/… → client-side API wrappers for each backend endpoint
- src/backend/server.js + src/routes.js → Express server and route definitions
- src/backend/historyUserTransactions.js → business logic for retrieving transaction history
- src/backend/learning/… → lightweight ML classifier (dataset.json, keywords.json, categories.json) for auto-categorization
- src/backend/userTransactions.json → JSON file as the application’s data store
- No external database driver: persistence is file-based JSON.

##### README for architecture hints
- Features mention charts (pieChartAPI.js, transactionsChartAPI.js), summary tables (transactionTableAPI.js), and upload functionality (uploadAPI.js).
- The “learning” folder suggests a plug-in component that classifies transactions.

a. Main components:
1. User’s Browser (UI)
2. Front-end SPA (React or vanilla JS)
3. API layer (src/api/*.js)
4. Backend server (Express in src/backend/server.js + routes.js)
5. Business logic modules:
– historyUserTransactions.js
– learning module (dataset.json, keywords.json, categories.json)
6. Data store (userTransactions.json)
7. Optional: file‐upload handler (uploadAPI.js ↔ server upload route)

b. Relationships and data flow:
- The Browser UI invokes functions in src/api/*.js →
- These modules issue HTTP requests (GET/POST) to defined routes in server.js/routes.js →
- Express routes dispatch to business logic modules (historyUserTransactions, register/login handlers, ML classifier) →
- Logic reads/writes userTransactions.json and returns JSON responses →
- Front-end modules parse responses, update UI, render charts/reports.

c. Architectural patterns/design principles:
- Separation of concerns: UI ↔ API wrappers ↔ API routes ↔ business logic ↔ data store
- Plug-in ML component for categorization (located in src/backend/learning)
- File-based JSON persistence instead of an RDBMS/NoSQL database

d. Key technologies/frameworks:
- Front-end: React or JavaScript SPA (in public/index.html)
- HTTP API clients: src/api/*.js
- Backend: Node.js + Express (server.js, routes.js)
- ML: a custom classifier reading JSON datasets
- Data store: JSON files (userTransactions.json)

##### Detail
- That userTransactions.json stores all transactions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Front-end Layer"
        UI["Browser UI\n(public/index.html)"]:::frontend
        registerAPI["Register API Wrapper\n(src/api/registerAPI.js)"]:::api
        loginAPI["Login API Wrapper\n(src/api/loginAPI.js)"]:::api
        addAPI["Add Transaction API\n(src/api/addToDatabase.js)"]:::api
        insertAPI["Insert API\n(src/api/insertAPI.js)"]:::api
        summaryAPI["Summary API\n(src/api/summaryTransactionsAPI.js)"]:::api
        tableAPI["Transaction Table API\n(src/api/transactionTableAPI.js)"]:::api
        pieAPI["Pie Chart API\n(src/api/pieChartAPI.js)"]:::api
        txnChartAPI["Transactions Chart API\n(src/api/transactionsChartAPI.js)"]:::api
        uploadAPI["Upload API Wrapper\n(src/api/uploadAPI.js)"]:::api
        userInfoAPI["User Info API\n(src/api/getUsernameAPI.js)"]:::api
        projectsAPI["Projects API\n(src/api/totalProjectsAPI.js)"]:::api
    end

    subgraph "Backend Layer"
        server["Express Server\n(src/backend/server.js)"]:::backend
        routes["Route Definitions\n(src/routes.js)"]:::backend
        biz["Transaction History Module\n(src/backend/historyUserTransactions.js)"]:::backend
        uploadHandler["Upload Handler"]:::backend
        subgraph "ML Classifier Plugin"
            categories["categories.json"]:::ml
            dataset["dataset.json"]:::ml
            keywords["keywords.json"]:::ml
        end
    end

    dataStore["User Transactions Store\n(src/backend/userTransactions.json)"]:::persistence

    UI --> registerAPI
    UI --> loginAPI
    UI --> addAPI
    UI --> insertAPI
    UI --> summaryAPI
    UI --> tableAPI
    UI --> pieAPI
    UI --> txnChartAPI
    UI --> uploadAPI
    UI --> userInfoAPI
    UI --> projectsAPI

    registerAPI -->|"POST /register"| routes
    loginAPI -->|"POST /login"| routes
    addAPI -->|"POST /transactions"| routes
    insertAPI -->|"POST /transactions/insert"| routes
    summaryAPI -->|"GET /transactions/summary"| routes
    tableAPI -->|"GET /transactions"| routes
    pieAPI -->|"GET /charts/pie"| routes
    txnChartAPI -->|"GET /charts/transactions"| routes
    uploadAPI -->|"POST /upload"| routes
    userInfoAPI -->|"GET /user"| routes
    projectsAPI -->|"GET /projects/total"| routes

    routes --> server
    server --> biz
    server --> uploadHandler
    server --> categories
    server --> dataset
    server --> keywords

    biz --> dataStore
    uploadHandler --> dataStore
    categories --> dataStore
    dataset --> dataStore
    keywords --> dataStore

    click UI "https://github.com/eatekha/myfinance/blob/new-version/public/index.html"
    click registerAPI "https://github.com/eatekha/myfinance/blob/new-version/src/api/registerAPI.js"
    click loginAPI "https://github.com/eatekha/myfinance/blob/new-version/src/api/loginAPI.js"
    click addAPI "https://github.com/eatekha/myfinance/blob/new-version/src/api/addToDatabase.js"
    click insertAPI "https://github.com/eatekha/myfinance/blob/new-version/src/api/insertAPI.js"
    click summaryAPI "https://github.com/eatekha/myfinance/blob/new-version/src/api/summaryTransactionsAPI.js"
    click tableAPI "https://github.com/eatekha/myfinance/blob/new-version/src/api/transactionTableAPI.js"
    click pieAPI "https://github.com/eatekha/myfinance/blob/new-version/src/api/pieChartAPI.js"
    click txnChartAPI "https://github.com/eatekha/myfinance/blob/new-version/src/api/transactionsChartAPI.js"
    click uploadAPI "https://github.com/eatekha/myfinance/blob/new-version/src/api/uploadAPI.js"
    click userInfoAPI "https://github.com/eatekha/myfinance/blob/new-version/src/api/getUsernameAPI.js"
    click projectsAPI "https://github.com/eatekha/myfinance/blob/new-version/src/api/totalProjectsAPI.js"
    click server "https://github.com/eatekha/myfinance/blob/new-version/src/backend/server.js"
    click routes "https://github.com/eatekha/myfinance/blob/new-version/src/routes.js"
    click biz "https://github.com/eatekha/myfinance/blob/new-version/src/backend/historyUserTransactions.js"
    click categories "https://github.com/eatekha/myfinance/tree/new-version/src/backend/learning/"
    click dataset "https://github.com/eatekha/myfinance/tree/new-version/src/backend/learning/"
    click keywords "https://github.com/eatekha/myfinance/tree/new-version/src/backend/learning/"
    click dataStore "https://github.com/eatekha/myfinance/blob/new-version/src/backend/userTransactions.json"

    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef api fill:#d4edda,stroke:#155724,color:#155724
    classDef backend fill:#ffe5b4,stroke:#b5651d,color:#b5651d
    classDef persistence fill:#fff3cd,stroke:#856404,color:#856404
    classDef ml fill:#e2e3f3,stroke:#6f42c1,color:#6f42c1
```
