# jason-hn/cash-flow architecture

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

- Interactive diagram: https://gitdiagram.com/jason-hn/cash-flow
- Repository: https://github.com/jason-hn/cash-flow

## Overview

##### Project Type and Purpose
- The frontend is a React 18 single‑page app built with Vite and TailwindCSS. The backend is a Node.js/Express REST API using JWT authentication and MongoDB for persistence.

##### File Structure Analysis
- Top‑level split into two folders:
- client/ – React code, divided into src/components, src/pages, src/api (REST wrappers), src/store (state management via React Query), src/utils.
- server/ – Express server code, with middleware (auth), models (Mongoose schemas), utils/constants, and a single server.js entry.
- Config and build files: Vite, Tailwind, Netlify for frontend; npm scripts and .env for backend.
- No microservices or secondary backends – a monolithic API.

##### Key Insights from README
- Uses React Query on the client to fetch REST endpoints exposed by the Express server.
- MongoDB URI and JWT secret configured via environment variables.
- Frontend served either by Vite (dev) or deployed to Netlify; backend runs on Node/Express (port 3000) and connects to MongoDB (Atlas or local).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Entities
    Browser["User Browser"]:::external
    CDN["Netlify/CDN"]:::external
    MongoDB["MongoDB Atlas/Local"]:::external

    %% Frontend Zone
    subgraph "Frontend" 
        direction TB

        CDN -->|"Serves static assets"| StaticHost["client/index.html"]:::frontend
        click StaticHost "https://github.com/jason-hn/cash-flow/blob/main/client/index.html"

        StaticHost -->|"Loads SPA"| Entry["client/src/main.jsx"]:::frontend
        click Entry "https://github.com/jason-hn/cash-flow/blob/main/client/src/main.jsx"

        subgraph "Configuration"
            direction TB
            ViteConfig["vite.config.js"]:::frontend
            click ViteConfig "https://github.com/jason-hn/cash-flow/blob/main/client/vite.config.js"
            TailwindConfig["tailwind.config.js"]:::frontend
            click TailwindConfig "https://github.com/jason-hn/cash-flow/blob/main/client/tailwind.config.js"
        end

        subgraph "Pages (React Router)"
            direction TB
            DashboardPage["Dashboard.jsx"]:::frontend
            click DashboardPage "https://github.com/jason-hn/cash-flow/blob/main/client/src/pages/Dashboard.jsx"
            BudgetsPage["Budgets.jsx"]:::frontend
            click BudgetsPage "https://github.com/jason-hn/cash-flow/blob/main/client/src/pages/Budgets.jsx"
            TransactionsPage["Transactions.jsx"]:::frontend
            click TransactionsPage "https://github.com/jason-hn/cash-flow/blob/main/client/src/pages/Transactions.jsx"
            ReportsPage["Reports.jsx"]:::frontend
            click ReportsPage "https://github.com/jason-hn/cash-flow/blob/main/client/src/pages/Reports.jsx"
            SettingsPage["Settings.jsx"]:::frontend
            click SettingsPage "https://github.com/jason-hn/cash-flow/blob/main/client/src/pages/Settings.jsx"
            LoginPage["Login.jsx"]:::frontend
            click LoginPage "https://github.com/jason-hn/cash-flow/blob/main/client/src/pages/Login.jsx"
            SignupPage["Signup.jsx"]:::frontend
            click SignupPage "https://github.com/jason-hn/cash-flow/blob/main/client/src/pages/Signup.jsx"
        end

        subgraph "UI Components"
            direction TB
            subgraph "Layout"
                Navbar["Navbar.jsx"]:::frontend
                click Navbar "https://github.com/jason-hn/cash-flow/blob/main/client/src/components/layout/Navbar.jsx"
                Sidebar["Sidebar.jsx"]:::frontend
                click Sidebar "https://github.com/jason-hn/cash-flow/blob/main/client/src/components/layout/Sidebar.jsx"
            end
            ProtectedRoute["ProtectedRoute.jsx"]:::frontend
            click ProtectedRoute "https://github.com/jason-hn/cash-flow/blob/main/client/src/components/ProtectedRoute.jsx"

            subgraph "Budgets"
                BudgetCard["BudgetCard.jsx"]:::frontend
                click BudgetCard "https://github.com/jason-hn/cash-flow/blob/main/client/src/components/budgets/BudgetCard.jsx"
                BudgetModal["BudgetModal.jsx"]:::frontend
                click BudgetModal "https://github.com/jason-hn/cash-flow/blob/main/client/src/components/budgets/BudgetModal.jsx"
            end

            subgraph "Dashboard"
                ExpensesPieChart["ExpensesPieChart.jsx"]:::frontend
                click ExpensesPieChart "https://github.com/jason-hn/cash-flow/blob/main/client/src/components/dashboard/ExpensesPieChart.jsx"
                MonthlyTrendsChart["MonthlyTrendsChart.jsx"]:::frontend
                click MonthlyTrendsChart "https://github.com/jason-hn/cash-flow/blob/main/client/src/components/dashboard/MonthlyTrendsChart.jsx"
                SummaryCard["SummaryCard.jsx"]:::frontend
                click SummaryCard "https://github.com/jason-hn/cash-flow/blob/main/client/src/components/dashboard/SummaryCard.jsx"
                TransactionsTable["TransactionsTable.jsx"]:::frontend
                click TransactionsTable "https://github.com/jason-hn/cash-flow/blob/main/client/src/components/dashboard/TransactionsTable.jsx"
            end

            TransactionModal["TransactionModal.jsx"]:::frontend
            click TransactionModal "https://github.com/jason-hn/cash-flow/blob/main/client/src/components/transactions/TransactionModal.jsx"
            
            subgraph "Settings"
                CategoryManager["CategoryManager.jsx"]:::frontend
                click CategoryManager "https://github.com/jason-hn/cash-flow/blob/main/client/src/components/settings/CategoryManager.jsx"
                SettingsForm["SettingsForm.jsx"]:::frontend
                click SettingsForm "https://github.com/jason-hn/cash-flow/blob/main/client/src/components/settings/SettingsForm.jsx"
            end

            SkeletonLoader["Skeleton.jsx"]:::frontend
            click SkeletonLoader "https://github.com/jason-hn/cash-flow/blob/main/client/src/components/ui/Skeleton.jsx"
        end

        subgraph "API Layer"
            direction TB
            APIClient["api.js"]:::frontend
            click APIClient "https://github.com/jason-hn/cash-flow/blob/main/client/src/api/api.js"
            BudgetsAPI["budgets.js"]:::frontend
            click BudgetsAPI "https://github.com/jason-hn/cash-flow/blob/main/client/src/api/budgets.js"
            TransactionsAPI["transactions.js"]:::frontend
            click TransactionsAPI "https://github.com/jason-hn/cash-flow/blob/main/client/src/api/transactions.js"
        end

        subgraph "State Management"
            direction TB
            AuthStore["authStore.js"]:::frontend
            click AuthStore "https://github.com/jason-hn/cash-flow/blob/main/client/src/store/authStore.js"
            ReactQuery["React Query"]:::frontend
        end

        subgraph "Utilities"
            direction TB
            UtilsConstants["constants.js"]:::frontend
            click UtilsConstants "https://github.com/jason-hn/cash-flow/blob/main/client/src/utils/constants.js"
            UtilsError["error.js"]:::frontend
            click UtilsError "https://github.com/jason-hn/cash-flow/blob/main/client/src/utils/error.js"
        end
    end

    %% Backend Zone
    subgraph "Backend"
        direction TB
        ServerEntry["server/server.js"]:::backend
        click ServerEntry "https://github.com/jason-hn/cash-flow/blob/main/server/server.js"

        AuthMiddleware["auth.js"]:::backend
        click AuthMiddleware "https://github.com/jason-hn/cash-flow/blob/main/server/middleware/auth.js"

        subgraph "Controllers & Routes"
            direction TB
            UserRoutes["User Routes"]:::backend
            BudgetRoutes["Budget Routes"]:::backend
            TransactionRoutes["Transaction Routes"]:::backend
        end

        subgraph "Models (Mongoose)"
            direction TB
            UserModel["User.js"]:::backend
            click UserModel "https://github.com/jason-hn/cash-flow/blob/main/server/models/User.js"
            BudgetModel["Budget.js"]:::backend
            click BudgetModel "https://github.com/jason-hn/cash-flow/blob/main/server/models/Budget.js"
            TransactionModel["Transaction.js"]:::backend
            click TransactionModel "https://github.com/jason-hn/cash-flow/blob/main/server/models/Transaction.js"
        end

        UtilsConstantsServer["constants.js"]:::backend
        click UtilsConstantsServer "https://github.com/jason-hn/cash-flow/blob/main/server/utils/constants.js"
        PackageJSON["package.json"]:::backend
        click PackageJSON "https://github.com/jason-hn/cash-flow/blob/main/server/package.json"
    end

    %% Data Flows
    Browser -->|GET index.html| StaticHost
    Entry -->|Renders| DashboardPage
    DashboardPage -->|Uses| UIComponents((UI Components))
    UIComponents -->|Calls| APIClient
    APIClient -->|Fetches| BudgetsAPI
    APIClient -->|Fetches| TransactionsAPI
    APIClient -->|HTTP Requests| ServerEntry
    ServerEntry -->|uses| AuthMiddleware
    AuthMiddleware -->|protects| BudgetRoutes
    BudgetRoutes -->|invoke| BudgetModel
    BudgetModel -->|CRUD| MongoDB
    TransactionRoutes -->|invoke| TransactionModel
    TransactionModel -->|CRUD| MongoDB
    UserRoutes -->|invoke| UserModel
    UserModel -->|CRUD| MongoDB

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6,stroke-width:1px;
    classDef backend fill:#DFFFD0,stroke:#22863a,color:#22863a,stroke-width:1px;
    classDef external fill:#E0E0E0,stroke:#888888,color:#333333,stroke-width:1px;
```
