# harsh-porwal424/expensetracker architecture

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

- Interactive diagram: https://gitdiagram.com/harsh-porwal424/expensetracker
- Repository: https://github.com/harsh-porwal424/expensetracker

## Overview

##### Main Components
- Frontend: Built with React 18, Vite, and TailwindCSS. The file tree shows a detailed directory structure for components, services, tests, and configuration (e.g., vite.config.js, tailwind.config.js). This component provides user interfaces for expense management, user authentication, and dashboards.
- Backend: Built with Node.js and Express, integrated with MongoDB (deduced from model files). This component handles API routing, controllers for categories, transactions, and user services, and JWT authentication middleware.
- Database: Although not directly visible in the file tree, the README indicates usage of MongoDB. Represent this external component as the persistent data store.
- Monitoring Tools: Prometheus and Grafana are used to capture metrics (request count, gauges, and histograms) as shown in the backend/monitering directory and prometheus.yml. This component monitors API metrics and system behavior.
- CI/CD Pipeline: Defined in the README (GitHub Actions workflows in .github/workflows and Dockerfiles in both frontend and backend). This pipeline automates building, testing, and container deployment. For deployment, Docker Compose orchestration is used (backend/docker-compose.yml) to stand up backend, Prometheus, and Grafana containers.
- Cloud Infrastructure: In production, the frontend is hosted on Vercel, and backend services are deployed on AWS EC2 as per the README.

##### Relationships & Interactions
- The Frontend connects to the Backend via RESTful API endpoints (e.g., /api/v1/users, /api/v1/transactions) for user authentication, transaction management, and category services.
- The Backend communicates with the MongoDB database for data persistence.
- The Backend publishes key metrics (HTTP request counters, active users gauge, etc.) to Prometheus.
- Prometheus aggregates metrics and provides them to Grafana, which then displays monitoring dashboards.
- The CI/CD pipeline automates building and deployment. Include components such as GitHub Actions for continuous integration and Docker Compose for orchestration.
- Containerization interlinks all services with clearly defined ports (backend: 8000, Prometheus: 9090, Grafana: 3001).

##### Important Architectural Patterns & Design Principles
- Layered Architecture: Separation between frontend and backend, with clear API contracts.
- Containerization: Use of Docker and Docker Compose facilitates deployment consistency across environments.
- Microservice/Modular Approach: Even though it’s a monolith by structure, the separation of concerns into controllers, middleware, models, and services signifies modular design.
- CI/CD Integration: GitHub Actions pipelines show an automated delivery system that builds, tests, and deploys code.
- Observability: Integrated Prometheus and Grafana monitoring ensures proactive performance tracking.

##### Relevant Technologies & Frameworks
- Frontend: React 18, Vite, TailwindCSS.
- Backend: Node.js, Express, MongoDB, JWT, Bcrypt.
- Monitoring: Prometheus and Grafana.
- Containerization & DevOps: Docker, Docker Compose, GitHub Actions.
- Testing: Jest, React Testing Library (from test directories).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        CI["GitHub Actions & Docker Compose"]:::ci
    end

    %% Deployment Targets (Cloud Infrastructure)
    subgraph "Cloud Infrastructure"
        FCloud["Vercel (Frontend)"]:::cloud
        BCloud["AWS EC2 (Backend)"]:::cloud
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Frontend (React/Vite/TailwindCSS)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE["Backend API (Node.js/Express)"]:::backend
        DB["MongoDB (Database)"]:::db
        %% Monitoring Tools as a separate subgraph in Backend Layer
        subgraph "Monitoring Tools"
            Prom["Prometheus (9090)"]:::monitor
            Graf["Grafana (3001)"]:::monitor
        end
    end

    %% Connections from CI/CD to containers
    CI -->|"builds"| FE
    CI -->|"builds"| BE

    %% Deployment connections
    FE -->|"deployed on"| FCloud
    BE -->|"deployed on"| BCloud

    %% Application interactions
    FE -->|"REST_API"| BE
    BE -->|"read/write"| DB
    BE -->|"publishes"| Prom
    Prom -->|"scrapes/aggregates"| Graf

    %% Click Events
    click FE "https://github.com/harsh-porwal424/expensetracker/tree/main/frontend/"
    click BE "https://github.com/harsh-porwal424/expensetracker/tree/main/backend/"
    click Prom "https://github.com/harsh-porwal424/expensetracker/tree/main/backend/monitering/"
    click CI "https://github.com/harsh-porwal424/expensetracker/tree/main/.github/workflows/"

    %% Styles
    classDef frontend fill:#a3d5ff,stroke:#333,stroke-width:2px;
    classDef backend fill:#f7c5cc,stroke:#333,stroke-width:2px;
    classDef db fill:#ffffba,stroke:#333,stroke-width:2px;
    classDef ci fill:#d5f4e6,stroke:#333,stroke-width:2px;
    classDef monitor fill:#fefbd8,stroke:#333,stroke-width:2px;
    classDef cloud fill:#d1ffd1,stroke:#333,stroke-width:2px;
```
