# divyanshrampal/expense-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/divyanshrampal/expense-tracker
- Repository: https://github.com/divyanshrampal/expense-tracker

## Overview

##### Main components of the system
- Frontend Client: The "client" folder holds all the React code including pages (e.g., HomePage, Login, Register), layout components (Header, Footer, Layout), and utility components (Spinner, Analytics). It also contains configuration files (like tailwind.config.js) and public assets.
- Backend Server: At the root, “server.js” provides the entry point to the Node.js/Express backend. The architecture follows the MVC pattern with distinct folders:
- controllers (business logic for transactions and users)
- models (Mongoose schemas for transactions and users)
- routes (defines API endpoints for transactions and users)
- config (database connection setup using MongoDB via Mongoose)
- Database: MongoDB, which is connected via Mongoose as inferred from configuration and model files.
- External Services: Dependencies include libraries like Express, Mongoose, Tailwind CSS, Ant Design, and React.

##### Relationships and interactions
- The Frontend (React) interacts with the Backend via RESTful API calls. For example, adding, updating, or deleting transactions will trigger API requests to corresponding routes (e.g., userRoute.js and transactionRoute.js).
- The Backend processes these requests with controllers and uses Mongoose models to perform CRUD operations on MongoDB.
- The connection between the Frontend and Backend is typically coordinated via a proxy or defined APIs endpoints, and the project setup (npm run dev) suggests concurrent running of both layers.

##### Important architectural patterns/design principles
- MVC Pattern: In the backend directory structure, models, views (not explicitly present since it is API-driven), and controllers separate data, business logic, and routing.
- Separation of concerns: Clearly separated client-side and server-side code.
- RESTful API Design: The routes, controllers, and models layer indicate a REST architecture.

##### Relevant technologies or frameworks
- Frontend: React, Tailwind CSS, Ant Design (for UI components)
- Backend: Node.js, Express.js, Mongoose (for managing MongoDB)
- Database: MongoDB

## Diagram (Mermaid)

```mermaid
graph TB
    %% Frontend
    subgraph "Frontend Client"
        FE1["Client Application (React)"]:::frontend
        subgraph "Pages"
            FE2["HomePage"]:::frontend
            FE3["Login"]:::frontend
            FE4["Register"]:::frontend
        end
        subgraph "Components & Assets"
            FE5["Layout (Header,Footer,Layout)"]:::frontend
            FE6["Utilities (Spinner,Analytics)"]:::frontend
            FE7["Configuration (tailwind.config.js)"]:::frontend
        end
    end

    %% Backend
    subgraph "Backend Server"
        BE1["Entry Point (server.js)"]:::backend
        subgraph "API Layer"
            subgraph "Routes"
                R1["Transaction Route (transactionRoute.js)"]:::backend
                R2["User Route (userRoute.js)"]:::backend
            end
            subgraph "Controllers"
                CTR1["Transaction Controller (transactionController.js)"]:::backend
                CTR2["User Controller (userController.js)"]:::backend
            end
            subgraph "Models"
                M1["Transaction Model (transactionModel.js)"]:::backend
                M2["User Model (userModel.js)"]:::backend
            end
        end
        BE5["DB Connection (config/connectDb.js)"]:::backend
    end

    %% Database External Node
    D1["MongoDB"]:::database

    %% Connections between Frontend and Backend
    FE1 -->|"REST_API_Calls"| BE1

    %% Internal Backend Flow
    R1 -->|"calls"| CTR1
    R2 -->|"calls"| CTR2
    CTR1 -->|"uses"| M1
    CTR2 -->|"uses"| M2
    BE5 -->|"connects_to"| D1

    %% Click Events for Frontend
    click FE1 "https://github.com/divyanshrampal/expense-tracker/tree/main/client"
    click FE2 "https://github.com/divyanshrampal/expense-tracker/tree/main/client/src/pages"
    click FE3 "https://github.com/divyanshrampal/expense-tracker/tree/main/client/src/pages"
    click FE4 "https://github.com/divyanshrampal/expense-tracker/tree/main/client/src/pages"
    click FE5 "https://github.com/divyanshrampal/expense-tracker/tree/main/client/src/components"
    click FE6 "https://github.com/divyanshrampal/expense-tracker/tree/main/client/src/components"
    click FE7 "https://github.com/divyanshrampal/expense-tracker/blob/main/client/tailwind.config.js"

    %% Click Events for Backend
    click BE1 "https://github.com/divyanshrampal/expense-tracker/blob/main/server.js"
    click BE5 "https://github.com/divyanshrampal/expense-tracker/blob/main/config/connectDb.js"
    click R1 "https://github.com/divyanshrampal/expense-tracker/blob/main/routes/transactionRoute.js"
    click R2 "https://github.com/divyanshrampal/expense-tracker/blob/main/routes/userRoute.js"
    click CTR1 "https://github.com/divyanshrampal/expense-tracker/blob/main/controllers/transactionController.js"
    click CTR2 "https://github.com/divyanshrampal/expense-tracker/blob/main/controllers/userController.js"
    click M1 "https://github.com/divyanshrampal/expense-tracker/blob/main/models/transactionModel.js"
    click M2 "https://github.com/divyanshrampal/expense-tracker/blob/main/models/userModel.js"

    %% Style Definitions
    classDef frontend fill:#D1E8FF,stroke:#1A73E8,stroke-width:2px;
    classDef backend fill:#D5F5E3,stroke:#2ECC71,stroke-width:2px;
    classDef database fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    
    %% Additional Styling for Subgraphs Labels (as notes)
    linkStyle default stroke:#333,stroke-width:1px;
    
    %% Ensure vertical orientation via TB direction (already declared using "graph TB")
```
