# mm120-i/eecs-4314 architecture

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

- Interactive diagram: https://gitdiagram.com/mm120-i/eecs-4314
- Repository: https://github.com/mm120-i/eecs-4314

## Overview

##### Project Type and Purpose
- This is a full-stack web application centered on finance management. Its purpose is to allow users to track income and expenses, set budgets, analyze spending habits, and even perform receipt scanning and banking data integration.
- The README explicitly mentions features such as user authentication (using JWT), transaction tracking, receipt upload/analysis with Taggun, and Plaid for banking data integration.

##### File Structure and Architectural Implications
- The project is split into two major directories at the top level: “client” (for the frontend) and “server” (for the backend).
- The “client” folder contains directories like app/components, dashboard, and pages for login, register, and settings. This reflects a Next.js routing structure and component-based UI design.
- The “server” folder contains:
– A config directory (for environment and deployment settings).
– Controllers, Models, Routes (using Express), and Services (for integrations like Plaid, Taggun, geocoding, forecasting, and OpenAI) that collectively form the backend API logic.
– A dedicated “database” module for MongoDB connectivity.
- These explicit separations suggest a RESTful API backend environment and a client that consumes these endpoints.

##### Key Components
a. Frontend:
- Next.js client built using React, Tailwind CSS, and shadcn/ui.
- Components for authentication (login, signup), dashboard (with pages for transactions, settings, and reporting), and other UI elements (logos, buttons, tables).
b. Backend:
- API Server (Node.js + Express) that provides endpoints for authentication, transactions, receipt uploads, and the integration with banking data.
- Controllers that handle business logic (e.g., authController, transactionController, receiptController, userController).
- Routes mapping URLs to controller actions.
- Middleware for authentication (using JWT) and error handling.
- Services which encapsulate external integrations (Plaid for bank account linking, Taggun for receipt scanning, geocoding, openai for potential AI-driven features).
c. Database:
- MongoDB, interfaced via Mongoose models representing users, transactions, receipts, and perhaps even Plaid-related data.
d. External Services:
- Plaid API for dummy banking data.
- Taggun API for receipt scanning.
- OpenAI components and geocoding services to enhance user insights.

##### Relationships & Data Flow
- The backend server, after validating requests (e.g., using JWT), interacts with the MongoDB database for data storage/retrieval.
- For specific functions:
– Transaction tracking and receipt scanning require calls from the frontend to dedicated backend endpoints, which in turn call the external Plaid or Taggun APIs.
– Data from the database might be aggregated or transformed by services (like spendingAggregator or forecastReceipt) before being sent back to the client for visualization.
– User actions triggering frontend events.
– Frontend API calls reaching the backend.
– Backend queries hitting the database.
– Backend communicating with external services.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    User["User"]:::external

    %% Frontend (Client)
    subgraph "Frontend (Client)"
        CF["Frontend Client (Next.js, React, Tailwind CSS)"]:::client

        subgraph "Authentication Components"
            AuthActions["Auth Actions & Session"]:::auth
            LoginForm["Login Form"]:::auth
            SignupForm["Signup Form"]:::auth
            LoginPage["Login Page"]:::auth
            RegisterPage["Register Page"]:::auth
        end

        subgraph "Dashboard UI Components"
            DashboardPages["Dashboard Pages & Layout"]:::dashboard
            DashboardComponents["Dashboard Navigation (NavLinks, Sidenav, TopNav)"]:::dashboard
            ForecastDisplay["Forecast Display"]:::dashboard
            MostDrainingSpends["Most Draining Spends"]:::dashboard
            SavingsAccount["Savings Account"]:::dashboard
            SpendingInsights["Spending Insights"]:::dashboard
            SpendvsIncome["Spend vs Income"]:::dashboard
            WeeklySpend["Weekly Spend"]:::dashboard
        end

        subgraph "Transaction & Receipt Components"
            TransactionComponents["Transaction Components"]:::transaction
            TransactionsData["Transactions Data"]:::transaction
            ReceiptsData["Receipts Data"]:::transaction
        end
    end

    %% Backend (Server)
    subgraph "Backend (Server)"
        BS["API Server (Node.js, Express)"]:::server
        Middleware["Middleware (JWT, Error Handling)"]:::middleware
        Routes["API Routes"]:::routes
        Controllers["Controllers"]:::controllers
        DB["Database Module (MongoDB)"]:::database
        Models["Models"]:::models
        Utility["Data Aggregation Utility"]:::utility

        subgraph "External Integration Services"
            Services["Services Layer"]:::services
            PlaidService["Plaid Service"]:::services
            TaggunService["Taggun Service"]:::services
            OpenAIService["OpenAI Service"]:::services
            GeocodingService["Geocoding Service"]:::services
            ForecastReceipt["Forecast Receipt Service"]:::services
            BetterDeals["Better Deals Service"]:::services
        end
    end

    %% External Services
    subgraph "External Services"
        PlaidAPI["Plaid API"]:::external
        TaggunAPI["Taggun API"]:::external
        OpenAIAPI["OpenAI API"]:::external
        GeocodingAPI["Geocoding API"]:::external
    end

    %% Connections between Frontend and Backend
    User -->|"initiates"| CF
    CF -->|"HTTP API calls"| BS

    %% Backend Internal Flow
    BS -->|"passes request"| Middleware
    Middleware -->|"routes request"| Routes
    Routes -->|"executes"| Controllers
    Controllers -->|"queries"| DB
    Controllers -->|"queries"| Models
    Controllers -->|"aggregates data"| Utility
    Controllers -->|"invokes"| Services

    %% External Integration Services Flow
    Services -->|"calls"| PlaidService
    Services -->|"calls"| TaggunService
    Services -->|"calls"| OpenAIService
    Services -->|"calls"| GeocodingService
    Services -->|"calls"| ForecastReceipt
    Services -->|"calls"| BetterDeals

    PlaidService -->|"API call"| PlaidAPI
    TaggunService -->|"API call"| TaggunAPI
    OpenAIService -->|"API call"| OpenAIAPI
    GeocodingService -->|"API call"| GeocodingAPI

    %% Click Events for Frontend Components
    click CF "https://github.com/mm120-i/eecs-4314/tree/main/client/app"
    click AuthActions "https://github.com/mm120-i/eecs-4314/tree/main/client/app/auth"
    click LoginForm "https://github.com/mm120-i/eecs-4314/blob/main/client/app/components/login-form.tsx"
    click SignupForm "https://github.com/mm120-i/eecs-4314/blob/main/client/app/components/signup-form.tsx"
    click LoginPage "https://github.com/mm120-i/eecs-4314/blob/main/client/app/login/page.tsx"
    click RegisterPage "https://github.com/mm120-i/eecs-4314/blob/main/client/app/register/page.tsx"
    click DashboardPages "https://github.com/mm120-i/eecs-4314/tree/main/client/app/dashboard"
    click DashboardComponents "https://github.com/mm120-i/eecs-4314/tree/main/client/app/components/dashboard"
    click ForecastDisplay "https://github.com/mm120-i/eecs-4314/blob/main/client/app/dashboard/ForecastDisplay.tsx"
    click MostDrainingSpends "https://github.com/mm120-i/eecs-4314/blob/main/client/app/dashboard/MostDrainingSpends.tsx"
    click SavingsAccount "https://github.com/mm120-i/eecs-4314/blob/main/client/app/dashboard/SavingsAccount.tsx"
    click SpendingInsights "https://github.com/mm120-i/eecs-4314/blob/main/client/app/dashboard/SpendingInsights.tsx"
    click SpendvsIncome "https://github.com/mm120-i/eecs-4314/blob/main/client/app/dashboard/SpendvsIncome.tsx"
    click WeeklySpend "https://github.com/mm120-i/eecs-4314/blob/main/client/app/dashboard/WeeklySpend.tsx"
    click TransactionComponents "https://github.com/mm120-i/eecs-4314/tree/main/client/app/components/transactions"
    click TransactionsData "https://github.com/mm120-i/eecs-4314/blob/main/client/app/data/transactions.ts"
    click ReceiptsData "https://github.com/mm120-i/eecs-4314/blob/main/client/app/data/receipts.ts"

    %% Click Events for Backend Components
    click BS "https://github.com/mm120-i/eecs-4314/blob/main/server/server.js"
    click Controllers "https://github.com/mm120-i/eecs-4314/tree/main/server/controllers"
    click Routes "https://github.com/mm120-i/eecs-4314/tree/main/server/routes"
    click Middleware "https://github.com/mm120-i/eecs-4314/blob/main/server/middleware/auth/jwt.js"
    click Services "https://github.com/mm120-i/eecs-4314/tree/main/server/services"
    click DB "https://github.com/mm120-i/eecs-4314/blob/main/server/database/mongodb.js"
    click Models "https://github.com/mm120-i/eecs-4314/tree/main/server/models"
    click Utility "https://github.com/mm120-i/eecs-4314/blob/main/server/utility/spendingAggregator.js"
    click PlaidService "https://github.com/mm120-i/eecs-4314/blob/main/server/services/plaid.js"
    click TaggunService "https://github.com/mm120-i/eecs-4314/blob/main/server/services/taggun.js"
    click OpenAIService "https://github.com/mm120-i/eecs-4314/blob/main/server/services/openai.js"
    click GeocodingService "https://github.com/mm120-i/eecs-4314/blob/main/server/services/geocoding.js"
    click ForecastReceipt "https://github.com/mm120-i/eecs-4314/blob/main/server/services/forecastReceipt.js"
    click BetterDeals "https://github.com/mm120-i/eecs-4314/blob/main/server/services/betterDeals.js"

    %% Styles
    classDef client fill:#AED6F1,stroke:#2980B9,stroke-width:2px;
    classDef auth fill:#ABEBC6,stroke:#27AE60,stroke-width:2px;
    classDef dashboard fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef transaction fill:#FADBD8,stroke:#E74C3C,stroke-width:2px;
    classDef server fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef controllers fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef routes fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef middleware fill:#D5F5E3,stroke:#239B56,stroke-width:2px;
    classDef services fill:#FDEDEC,stroke:#CB4335,stroke-width:2px;
    classDef database fill:#FCF3CF,stroke:#F39C12,stroke-width:2px;
    classDef models fill:#D6EAF8,stroke:#3498DB,stroke-width:2px;
    classDef utility fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef external fill:#F0B27A,stroke:#E67E22,stroke-width:2px;
```
