# namanxdev/fin-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/namanxdev/fin-tracker
- Repository: https://github.com/namanxdev/fin-tracker

## Overview

##### Main Components
- Frontend: Built with React, Tailwind CSS, and various libraries (Recharts for charts, Zustand for state management, React Hook Form & Zod for validation, Framer Motion for animations). The directory structure shows that the frontend is organized into pages (e.g., Dashboard, Auth, Budget, Expenses, Income, Profile, Settings) and many specific UI components. This layer is responsible for rendering the user interface, handling authentication (login/register pages), and displaying interactive charts/analytics.
- Backend: Developed with Express.js. It contains clear areas for configuration (database configurations in db.js and passport.js), controllers (budgetController, expenseController, financialOverviewController, incomeController, userController), middleware (authentication and validation), models (Mongoose schemas for Budget, Expense, Income, and User), and routes that bind REST endpoints to controllers. The backend provides RESTful APIs, handles authentication (JWT, Google OAuth through Passport.js), applies security measures (Helmet, rate limiting), and processes error handling.
- Database: Although not explicitly visible as a separate directory, the usage of MongoDB via Mongoose is clearly part of the backend configuration (see the db.js file). This is where all user data, transactions, budgets, incomes, and expenses are stored.
- External Services: Note that the project integrates Google OAuth for user authentication and might depend on external charting libraries or notification services in the frontend.

##### Architectural Patterns and Design Principles
- Separation of concerns: Clearly delineate responsibilities between the frontend (UI/UX and state management) and backend (business logic, authentication, database operations).
- RESTful API design: Indicate that the backend exposes endpoints using routes (as seen in the Routes folder), which are consumed by the frontend.
- Security measures: Note the use of middleware like auth.js and the integration of Passport.js for secure authentication, as well as Helmet and rate limiting.
- Project using MVC-like patterns on the backend, grouping controllers, models, and routes.

##### Final Touch
- Legends or notes if necessary to explain abbreviations or specific libraries (like Zustand, Recharts, etc.) to ensure clarity for every viewer.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        FE["React Frontend"]:::frontend
        FE_Dashboard["Dashboard Page"]:::frontend
        FE_Auth["Auth (Login/Register)"]:::frontend
        FE_Budget["Budget Page"]:::frontend
        FE_Expenses["Expenses Page"]:::frontend
        FE_Income["Income Page"]:::frontend
        FE_Profile["Profile/Settings"]:::frontend
        FE_API["API Service"]:::frontend
        FE_Store["State Management"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        BE["Express Backend"]:::backend
        BE_Config["Configuration"]:::backend
        BE_Routes["Routes"]:::backend
        BE_Middleware["Middleware"]:::backend
        BE_Controllers["Controllers"]:::backend
        BE_Error["Error Handler Utility"]:::backend
        BE_OAuth["Google OAuth"]:::external
    end

    %% Data Layer
    subgraph "Data Layer"
        DB["MongoDB Database\n(Mongoose ORM)"]:::database
    end

    %% Relationships - Presentation to Backend
    FE_API -->|"API_Calls"| BE_Routes
    FE -->|"uses_state"| FE_Store

    %% Relationships - Internal Application Layer
    BE -->|"loads_config"| BE_Config
    BE_Routes -->|"Auth_Validation"| BE_Middleware
    BE_Middleware -->|"Request_Processing"| BE_Controllers
    BE_Controllers -->|"CRUD_operations"| DB
    BE_Routes -->|"Error_Handling"| BE_Error
    BE_Config -->|"OAuth_via_Passport"| BE_OAuth

    %% Click Events for Frontend Components
    click FE "https://github.com/namanxdev/fin-tracker/tree/main/Frontend/src"
    click FE_Dashboard "https://github.com/namanxdev/fin-tracker/blob/main/Frontend/src/pages/Dashboard/DashboardPage.jsx"
    click FE_Auth "https://github.com/namanxdev/fin-tracker/blob/main/Frontend/src/pages/Auth/LoginPage.jsx"
    click FE_Budget "https://github.com/namanxdev/fin-tracker/blob/main/Frontend/src/pages/BudgetPage.jsx"
    click FE_Expenses "https://github.com/namanxdev/fin-tracker/blob/main/Frontend/src/pages/ExpensesPage.jsx"
    click FE_Income "https://github.com/namanxdev/fin-tracker/blob/main/Frontend/src/pages/IncomePage.jsx"
    click FE_Profile "https://github.com/namanxdev/fin-tracker/blob/main/Frontend/src/pages/ProfilePage.jsx"
    click FE_API "https://github.com/namanxdev/fin-tracker/blob/main/Frontend/src/Services/Api.js"
    click FE_Store "https://github.com/namanxdev/fin-tracker/tree/main/Frontend/src/store"

    %% Click Events for Backend Components
    click BE "https://github.com/namanxdev/fin-tracker/blob/main/Backend/src/index.js"
    click BE_Config "https://github.com/namanxdev/fin-tracker/blob/main/Backend/src/Config/db.js"
    click BE_Controllers "https://github.com/namanxdev/fin-tracker/blob/main/Backend/src/Controllers/budgetController.js"
    click BE_Middleware "https://github.com/namanxdev/fin-tracker/blob/main/Backend/src/Middleware/auth.js"
    click BE_Routes "https://github.com/namanxdev/fin-tracker/blob/main/Backend/src/Routes/budgetRoutes.js"
    click BE_Error "https://github.com/namanxdev/fin-tracker/blob/main/Backend/src/utils/ErrorHandler.js"

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