# asdhamidi/hisaab architecture

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

- Interactive diagram: https://gitdiagram.com/asdhamidi/hisaab
- Repository: https://github.com/asdhamidi/hisaab

## Overview

##### Project Type and Purpose
- Hisaab is a single‑page, React‑based front‑end application whose purpose is to let flatmates log, track, and settle shared expenses.
- It communicates with a remote RESTful API (hosted at https://hisaab-ashy.vercel.app/) for authentication and data persistence.

##### High‑Level Architecture Components
a. Client Browser
- Hosts the React SPA (public/index.html → src/index.js → App.js).
- Renders UI components, manages routing via React Router.
b. UI Component Layer
- Login/Register (Login.js)
- Navigation (Navbar.js)
- Expense Board (Board.js) & Editor (Editor.js)
- Summary (Summary.js) & OweDetails (OweDetails.js)
- Charts (Stats.js) via Canvas.js
- Activities feed (Activities.js)
- Pop‑up details (Popup.js)
c. API Handling Layer
- api‑handling.js: centralized Axios instance with baseURL and JWT interceptor.
d. Remote Backend Service
- Auth endpoints (/login, /register)
- Expense CRUD endpoints (/entries, /entries/:id)
- Summary, charts, and activity endpoints
e. Data Store (external, not in repo)
- Likely a database (MongoDB, PostgreSQL, etc.) behind the API

##### Relationships and Data Flows
- On user action (e.g., “Add Entry”), UI component calls api‑handling.js → Axios → remote API.
- JWT from localStorage is attached to every request (except login).
- API returns JSON payload → api‑handling resolves promise → component state updates → UI re‑renders.
- Navbar triggers CSV download by fetching month’s entries from the API.

##### Architectural Patterns and Design Principles
- Component‑Based Architecture: each feature is isolated in its own React component.
- Single Responsibility: api‑handling.js only handles HTTP concerns; UI components manage view logic.
- Token‑Based Authentication: JWT in localStorage + Axios interceptor.
- RESTful Integration: standard CRUD and aggregate endpoints.
- Unidirectional Data Flow: data flows from API → state → props → view.

##### Elements
- Component labels (e.g., Login, Board, Stats).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph Browser/Client
        subgraph ReactSPA
            Public["public/index.html"]:::ui
            Index["src/index.js"]:::ui
            App["src/App.js\n(Router)"]:::ui
            Login["Login/Register"]:::ui
            Navbar["Navbar"]:::ui
            Board["Board"]:::ui
            Editor["Editor"]:::ui
            Summary["Summary"]:::ui
            OweDetails["OweDetails"]:::ui
            Stats["Stats (Charts)"]:::ui
            Activities["Activities"]:::ui
            Popup["Pop-up Details"]:::ui
        end
    end

    API["Axios Instance\n(baseURL + JWT interceptor)"]:::api

    subgraph "Hisaab Backend API"
        Auth["/login, /register"]:::external
        Entries["/entries, /entries/:id"]:::external
        SummaryEP["/summary"]:::external
        ChartsEP["/charts"]:::external
        ActivitiesEP["/activities"]:::external
    end

    DB[(Database)]:::db

    %% Requests
    Login -->|"POST /login"| API
    Login -->|"POST /register"| API
    Navbar -->|"GET /entries?month=…"| API
    Board -->|"GET /entries"| API
    Editor -->|"POST /entries"| API
    Editor -->|"PUT /entries/:id"| API
    Summary -->|"GET /summary"| API
    Stats -->|"GET /charts"| API
    Activities -->|"GET /activities"| API
    Popup -->|"GET /entries/:id"| API

    %% API to Backend
    API -->|"auth requests"| Auth
    API -->|"entries requests"| Entries
    API -->|"summary"| SummaryEP
    API -->|"charts"| ChartsEP
    API -->|"activities"| ActivitiesEP

    %% Responses
    Auth -->|response| API
    Entries -->|response| API
    SummaryEP -->|response| API
    ChartsEP -->|response| API
    ActivitiesEP -->|response| API

    %% API to UI
    API -->|JSON payload| Board
    API -->|JSON payload| Summary
    API -->|JSON payload| Stats
    API -->|JSON payload| Activities
    API -->|JSON payload| Popup

    %% Backend persistence
    Auth --> DB
    Entries --> DB
    SummaryEP --> DB
    ChartsEP --> DB
    ActivitiesEP --> DB

    %% Click Events
    click Public "https://github.com/asdhamidi/hisaab/blob/main/public/index.html"
    click Index "https://github.com/asdhamidi/hisaab/blob/main/src/index.js"
    click App "https://github.com/asdhamidi/hisaab/blob/main/src/App.js"
    click API "https://github.com/asdhamidi/hisaab/blob/main/src/components/api-handling.js"
    click Login "https://github.com/asdhamidi/hisaab/blob/main/src/components/login.js"
    click Navbar "https://github.com/asdhamidi/hisaab/blob/main/src/components/navbar.js"
    click Board "https://github.com/asdhamidi/hisaab/blob/main/src/components/board.js"
    click Editor "https://github.com/asdhamidi/hisaab/blob/main/src/components/editor.js"
    click Summary "https://github.com/asdhamidi/hisaab/blob/main/src/components/summary.js"
    click OweDetails "https://github.com/asdhamidi/hisaab/blob/main/src/components/owe-details.js"
    click Stats "https://github.com/asdhamidi/hisaab/blob/main/src/components/stats.js"
    click Activities "https://github.com/asdhamidi/hisaab/blob/main/src/components/activities.js"
    click Popup "https://github.com/asdhamidi/hisaab/blob/main/src/components/pop-up.js"

    %% Styles
    classDef ui fill:#AEDFF7,stroke:#0366d6,stroke-width:1px
    classDef api fill:#CFF7AE,stroke:#2e7d32,stroke-width:1px
    classDef external fill:#FFD5A6,stroke:#d84315,stroke-width:1px
    classDef db fill:#e0e0e0,stroke:#607d8b,stroke-width:1px
```
