# iharshmehta/spendwise architecture

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

- Interactive diagram: https://gitdiagram.com/iharshmehta/spendwise
- Repository: https://github.com/iharshmehta/spendwise

## Overview

##### Project Type and Purpose
- SpendWise is a full-stack financial management application that lets users manage expenses and split bills.
- The frontend is built with Angular, as seen from directories like "src/app", "angular.json", and various Angular component files.
- The backend, built with Node/Express, is organized under the "server" folder with controllers, models, routes, and middlewares.

##### File Structure
- Top-Level Components:
- Frontend (Angular): Located in the "src" folder and managed with Angular CLI (angular.json, tsconfig files). Components such as landing-page, spend-container, and split-container are visible.
- Backend (Node/Express): Contains server.js, a separate "server" folder with subdirectories for configs, controllers (spendController.js, splitController.js), models (spendModel.js), routes, and middleware (errorHandler.js).
- Configuration Files:
- Both frontend and backend have package.json files for dependency management.
- The "server/.env" file indicates environment-based configuration.
- "dbConnection.js" under server/configs suggests a database connection layer.

a. Main Components:
- App Shell (app.component.ts, app.config.ts, app.routes.ts)
- Specific feature components: landing-page, spend-container, and split-container.
- Models in the Angular app (spend-data.model.ts)
- Node/Express Backend: Represent as another major container that includes:
- Server Entry Points: server.ts and server/server.js.
- Controllers: spendController.js and splitController.js which handle business logic.
- Routes: Mapping endpoints to controllers (spendRoutes.js and splitRoutes.js).
- Models: e.g., spendModel.js that interface with the database.
- Middleware: e.g., errorHandler.js for global error processing.
- Database Connection: Configured by dbConnection.js (this module likely connects to a database such as MongoDB or MySQL, inferred by the structure).
- Database (External Component): Although not explicitly listed, the presence of dbConnection.js implies there is an underlying database. Represent this as a separate component that the backend connects to.
- External Services: If any exist (or potential future integrations), include placeholders.

b. Relationships and Data Flows:
- Controllers interact with models to perform CRUD operations on the database.
- Middleware (errorHandler.js) should be depicted as intercepting requests/responses in the backend pipeline.
- The dbConnection module shows how controllers/models can access the database.

c. Architectural Patterns and Design Principles:
- MVC (Model-View-Controller) Pattern: Evident on the backend with controllers, models, and routes.
- Separation of Concerns: Clearly separate frontend UI components from backend logic and data handling.
- Modular Design: Both frontend and backend are modular. Angular components and services are separated, and the backend directories further modularize controllers, middleware, and configuration.

d. Technologies and Frameworks:
- Angular Framework (Frontend)
- Node.js/Express (Backend)
- (Implied) A database system connected via "dbConnection.js" (e.g., MongoDB/Mysql – further investigation might be needed)
- Environment configuration (.env) and possibly other middleware that ensures robust error handling

##### Final Recommendations
- Data flow: Clearly indicate how data moves from the frontend via HTTP requests to the backend, gets processed, and eventually stored or retrieved from the database.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Angular Frontend"
        A1["App Shell (app.component.ts, app.routes.ts, app.config.ts)"]:::frontend
        A2["Landing Page Component"]:::frontend
        A3["Spend Container Component"]:::frontend
        A4["Split Container Component"]:::frontend
        A5["Spend Data Model"]:::frontend
    end

    subgraph "Node/Express Backend"
        B1["Server Entry Point (server.ts)"]:::backend
        B2["Server Starter (server/server.js)"]:::backend

        subgraph "API Layer"
            R1["Spend Routes"]:::backend
            R2["Split Routes"]:::backend
        end

        subgraph "Business Logic"
            C1["Spend Controller"]:::backend
            C2["Split Controller"]:::backend
        end

        subgraph "Data Layer"
            M1["Spend Model"]:::backend
            DBC["DB Connection (dbConnection.js)"]:::backend
        end

        B3["Middleware (errorHandler.js)"]:::backend
        B4["Environment Config (.env)"]:::backend
    end

    Database["Database"]:::database

    %% Relationships between Frontend and Backend
    A1 -->|"HTTP Requests"| R1
    A2 -->|"HTTP Calls"| R1
    A3 -->|"HTTP Calls"| R1
    A4 -->|"HTTP Calls"| R2
    A5 -->|"Data Binding"| A1

    %% Relationships within Backend
    R1 -->|"Calls"| C1
    R2 -->|"Calls"| C2
    C1 -->|"Uses"| M1
    C2 -->|"Uses"| M1
    M1 -->|"CRUD Ops"| Database
    B1 --> B2
    DBC -.-> M1
    B3 -.-> C1
    B3 -.-> C2

    %% Click Events for Angular Frontend
    click A1 "https://github.com/iharshmehta/spendwise/blob/master/src/app/app.component.ts"
    click A2 "https://github.com/iharshmehta/spendwise/tree/master/src/app/components/landing-page/"
    click A3 "https://github.com/iharshmehta/spendwise/tree/master/src/app/components/spend-container/"
    click A4 "https://github.com/iharshmehta/spendwise/tree/master/src/app/components/split-container/"
    click A5 "https://github.com/iharshmehta/spendwise/blob/master/src/app/models/spend-data.model.ts"

    %% Click Events for Node/Express Backend
    click B1 "https://github.com/iharshmehta/spendwise/blob/master/server.ts"
    click B2 "https://github.com/iharshmehta/spendwise/blob/master/server/server.js"
    click R1 "https://github.com/iharshmehta/spendwise/blob/master/server/routes/spendRoutes.js"
    click R2 "https://github.com/iharshmehta/spendwise/blob/master/server/routes/splitRoutes.js"
    click C1 "https://github.com/iharshmehta/spendwise/blob/master/server/controllers/spendController.js"
    click C2 "https://github.com/iharshmehta/spendwise/blob/master/server/controllers/splitController.js"
    click M1 "https://github.com/iharshmehta/spendwise/blob/master/server/models/spendModel.js"
    click B3 "https://github.com/iharshmehta/spendwise/blob/master/server/middleware/errorHandler.js"
    click DBC "https://github.com/iharshmehta/spendwise/blob/master/server/configs/dbConnection.js"
    click B4 "https://github.com/iharshmehta/spendwise/blob/master/server/.env"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
