# ronyjoseph2412/finance-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/ronyjoseph2412/finance-tracker
- Repository: https://github.com/ronyjoseph2412/finance-tracker

## Overview

##### Main Components
- Frontend Client:
- Pages: Located in the “src/app” directory, these include pages for Dashboard, Expenses, Investments, Login, Signup, and Profile.
- UI Components: Many are located under “src/Components.” They include specialized modules such as Budget Plannar, Calendar, DashboardComponents, Transactions, Modals, etc.
- Assets & Styling: Assets are under “src/Assets” and style modules (CSS) accompany many of the components.
- Global layout and the font provider located in “src/app/layout.tsx” and “src/lib/Provider.tsx.”

- Server/API Back-End:
- API endpoints: Found in both “src/app/api” and “src/Utils/server/api.” These include endpoints for account management (login, logout, register, verify), user financials (budgeting, investments, savings, transactions updates), and other middleware and utilities for request handling (error handling, JWT middleware, token verification).
- Supporting utilities: In “src/Utils/server” and “src/app/api” directories, which handle database connections, authentication, and repository patterns for user data.

- Data Management & Business Logic:
- State Management: Redux-like state management appears to be configured in “src/lib” (e.g., counterSlice, popupSlice, transactionsSlice, userSlice) and custom hooks (like useTransactions) that aid in managing client application state.
- Services: There are several services (in “src/services”) handling operations like adding expenses, creating budgets, verifying authentication, and getting user financial data.

##### Relationships/Interactions
- The Frontend UI communicates with the backend API endpoints via HTTP calls (likely using fetch or Axios) to retrieve/update user data.
- Routing is managed by Next.js “app” directory. Pages under “src/app” interconnect with client components and layout definitions.
- API endpoints are organized by functionalities such as account handling and user financials, which link to server utilities that manage database interactions and authentication.
- Global state management ensures that components reflect data fetched from backend services and updates after user actions.
- Utility functions (located in “src/Utils”) support all layers by processing data, handling dates, and formatting currency details.

##### Architectural Patterns & Technologies
- Next.js Full-Stack Structure: Employed for its file-system based routing for pages and API endpoints.
- Component-based UI: Modular UI components grouped by functionality (BudgetPlannar, Navbar, Calendar, etc.) to facilitate reuse and maintainability.
- Separation of Concerns: Distinct separation between presentation (components/pages), business logic (services and utilities), and data persistence (API endpoints and server-side scripts).
- Middleware and Security: Use of JWT and token verification indicates secure API design.
- State Management: Redux or Redux-like patterns using slices and custom hooks, which organize local and global state as part of the client app.

##### Final Recommendations for the Principal Software Engineer
- Drill down into each major area, mapping out all interactions, such as how the components make service calls and how the API processes these calls.

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Frontend
  subgraph "Frontend"
    subgraph "Pages"
      DashboardPage["Dashboard Page"]
      ExpensesPage["Expenses Page"]
      InvestmentsPage["Investments Page"]
      ProfilePage["Profile Page"]
      LoginPage["Login Page"]
      SignupPage["Signup Page"]
    end
    subgraph "UI Components"
      BudgetPlanner["Budget Planner Component"]
      CalendarComponent["Calendar Component"]
      DashboardComponents["Dashboard Components"]
      Transactions["Transactions Component"]
    end
    GlobalAssets["Assets & Global Layout"]
  end

  %% API Back-End
  subgraph "API Back-End"
    subgraph "Account Management Endpoints"
      LoginAPI["Account Login API"]
      LogoutAPI["Account Logout API"]
      RegisterAPI["Account Register API"]
      VerifyAPI["Account Verify API"]
    end
    subgraph "User Financials Endpoints"
      BudgetEndpoint["Budget Endpoint"]
      InvestmentsEndpoint["Investments Endpoint"]
      SavingsEndpoint["Savings Endpoint"]
      UpdateTransactionsEndpoint["Update Transactions Endpoint"]
      FinancialsRouter["Overall Financials API"]
    end
    subgraph "General API & Middleware"
      APIUtils["API Handler & Middleware"]
    end
  end

  %% State Management & Business Services
  subgraph "State Management & Services"
    GlobalStore["Global Store & Slices"]
    Hooks["Custom Hooks"]
    Services["Business Services"]
  end

  %% Interactions between Frontend and API/State Layers
  %% Pages rendering UI and interacting with Global Store & API
  DashboardPage -- "Renders UI" --> DashboardComponents
  ExpensesPage -- "Renders UI" --> Transactions
  InvestmentsPage -- "Renders UI" --> DashboardComponents
  ProfilePage -- "Renders Profile UI" --> GlobalAssets

  DashboardPage -- "Fetch Financial Data" --> FinancialsRouter
  ExpensesPage -- "Submit Expense" --> UpdateTransactionsEndpoint
  InvestmentsPage -- "Fetch Investments" --> InvestmentsEndpoint
  ProfilePage -- "Fetch Profile Info" --> FinancialsRouter
  LoginPage -- "Submit Credentials" --> LoginAPI
  SignupPage -- "Submit Registration" --> RegisterAPI

  %% Frontend UI Components interacting with Services & Global Store
  BudgetPlanner -- "Uses Service" --> Services
  CalendarComponent -- "Uses Service" --> Services
  DashboardComponents -- "Uses Service" --> Services
  Transactions -- "Uses Service" --> Services

  BudgetPlanner -- "Update State" --> GlobalStore
  CalendarComponent -- "Update State" --> GlobalStore
  DashboardComponents -- "Update State" --> GlobalStore
  Transactions -- "Update State" --> GlobalStore

  %% Services calling API utilities
  Services -- "Calls API" --> APIUtils

  %% API Endpoints behind middleware
  LoginAPI -- "Uses Middleware" --> APIUtils
  LogoutAPI -- "Uses Middleware" --> APIUtils
  RegisterAPI -- "Uses Middleware" --> APIUtils
  VerifyAPI -- "Uses Middleware" --> APIUtils

  APIUtils -- "Handles" --> BudgetEndpoint
  APIUtils -- "Handles" --> InvestmentsEndpoint
  APIUtils -- "Handles" --> SavingsEndpoint
  APIUtils -- "Handles" --> UpdateTransactionsEndpoint

  %% Global Store linked with Custom Hooks
  GlobalStore -- "Provides State" --> Hooks

  %% Legend (not connected)
  subgraph "Legend"
    L1["Frontend Components (Blue)"]
    L2["API Back-End (Green)"]
    L3["State & Services (Pink)"]
  end

  classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
  classDef api fill:#d4edda,stroke:#155724,stroke-width:2px;
  classDef state fill:#f8d7da,stroke:#721c24,stroke-width:2px;

  class DashboardPage,ExpensesPage,InvestmentsPage,ProfilePage,LoginPage,SignupPage,BudgetPlanner,CalendarComponent,DashboardComponents,Transactions,GlobalAssets frontend;
  class LoginAPI,LogoutAPI,RegisterAPI,VerifyAPI,BudgetEndpoint,InvestmentsEndpoint,SavingsEndpoint,UpdateTransactionsEndpoint,FinancialsRouter,APIUtils api;
  class GlobalStore,Hooks,Services state;

click DashboardPage "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/dashboard/page.tsx"
click DashboardPage "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/Pages/Dashboard/DashboardPage.tsx"
click ExpensesPage "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/expenses/page.tsx"
click ExpensesPage "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/Pages/ExpensesPage/ExpensesPage.tsx"
click InvestmentsPage "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/investments/page.tsx"
click InvestmentsPage "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/Pages/Investments/InvestementsPage.tsx"
click ProfilePage "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/profile/page.tsx"
click ProfilePage "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/Pages/ProfilePage/ProfilePage.tsx"
click LoginPage "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/login/page.tsx"
click SignupPage "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/signup/Signup.tsx"
click BudgetPlanner "https://github.com/ronyjoseph2412/finance-tracker/tree/master/src/Components/BudgetPlannar/"
click CalendarComponent "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/Components/Calendar/TrackingCalendar.tsx"
click DashboardComponents "https://github.com/ronyjoseph2412/finance-tracker/tree/master/src/Components/DashboardComponents/UpperSection/"
click Transactions "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/Components/Transactions/Transactions.tsx"
click Transactions "https://github.com/ronyjoseph2412/finance-tracker/tree/master/src/Components/DashboardTransactionsList/"
click GlobalAssets "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/layout.tsx"
click GlobalAssets "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/globals.css"
click GlobalAssets "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/lib/Provider.tsx"
click LoginAPI "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/api/account/login/route.ts"
click LogoutAPI "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/api/account/logout/route.ts"
click RegisterAPI "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/api/account/register/route.ts"
click VerifyAPI "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/api/account/verify/route.ts"
click BudgetEndpoint "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/api/userfinancials/budget/[type]/route.ts"
click BudgetEndpoint "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/api/userfinancials/budget/invest/[id]/route.ts"
click InvestmentsEndpoint "https://github.com/ronyjoseph2412/finance-tracker/tree/master/src/app/api/userfinancials/investments/"
click InvestmentsEndpoint "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/api/userfinancials/investments/[id]/route.ts"
click SavingsEndpoint "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/api/userfinancials/savings/[savingsType]/route.ts"
click SavingsEndpoint "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/api/userfinancials/savings/route.ts"
click UpdateTransactionsEndpoint "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/api/userfinancials/update/[transactionType]/route.ts"
click FinancialsRouter "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/app/api/userfinancials/route.ts"
click APIUtils "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/Utils/server/api/api-handler.ts"
click APIUtils "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/Utils/server/api/error-handler.ts"
click APIUtils "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/Utils/server/api/jwt-middleware.ts"
click APIUtils "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/Utils/server/api/validate-middleware.ts"
click APIUtils "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/Utils/server/verifyTokenwithAuth.ts"
click GlobalStore "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/lib/counterSlice.ts"
click GlobalStore "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/lib/popupSlice.ts"
click GlobalStore "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/lib/transactionsSlice.ts"
click GlobalStore "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/lib/userSlice.ts"
click Hooks "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/lib/hooks/useTransactions.ts"
click Services "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/services/addExpense.ts"
click Services "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/services/createNewBudget.ts"
click Services "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/services/getUserBudgets.ts"
click Services "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/services/getUserData.ts"
click Services "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/services/getUserFinancials.ts"
click Services "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/services/setBudget.ts"
click Services "https://github.com/ronyjoseph2412/finance-tracker/blob/master/src/services/verifyAuth.ts"
```
