# 10jonathan93/income-expense-app architecture

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

- Interactive diagram: https://gitdiagram.com/10jonathan93/income-expense-app
- Repository: https://github.com/10jonathan93/income-expense-app

## Overview

##### Main Components
- Frontend Client UI:
- This is the React layer built using TypeScript and bundled by Vite.
- It includes the primary entry point (index.html, main.tsx) and the App.tsx component.
- UI Components:
- There are separate directories for “expense”, “income”, “financial-status”, “routes”, and “styles”. Each one represents a grouping of components focused on specific functionality (e.g., ExpenseForm, ListExpense, ModalAddExpense, along with similar components for income).
- The “routes” directory contains the routing components (Home, Expense, Income, SeeExpenseList, SeeIncomeList) which help define navigation within the application.
- State Management:
- Managed through a context (IncomeOrExpenseContext.tsx) and a custom hook (useIncomeOrExpense.ts) to share state regarding incomes and expenses across components.
- Custom Hooks:
- Several hooks (such as useAddExpenseModal, useAddIncomeModal, useEditExpenseModal, useEditIncomeModal) encapsulate modal management logic for add/edit actions.
- Utilities:
- The “utils” folder includes helper functions like localStorage management.
- Configuration & Build:
- Vite configuration (vite.config.ts) and various tsconfig files denote how TypeScript is being used.
- ESLint configuration (eslint.config.js) establishes coding standards, which is particularly useful for a production application.

##### Understanding Relationships and Interactions
- The main App component (in App.tsx) serves as the central hub that routes to various pages (Home, Expense, Income, etc.) through the components in the “routes” directory.
- Each page component (for example, Expense.tsx) integrates several sub-components:
- Components to display expenses/income.
- Form components and modals for adding/editing data.
- Totals and status components to display financial summaries (e.g., TotalExpense, TotalIncome, TotalFinancialStatus).
- The React Context (IncomeOrExpenseContext) connects with consumer components across the application through the use of the custom hook (useIncomeOrExpense) so that state changes (like adding or editing an expense/income) are propagated and rendered appropriately.
- Custom hooks around managing modal state for add/edit actions ensure a cleaner UX and state isolation.

##### Architectural Patterns
- Component-Based Architecture:
- Every UI logic piece (list, form, modal) is its own component, making the UI modular and reusable.
- Separation of Concerns:
- UI rendering (in components) is separated from business logic (in hooks and context) and from data persistence (localStorage utility).
- Declarative Routing:
- The “routes” directory provides a clear map of the application’s navigation, a common pattern in React single-page applications.
- Use of a Modern Build Toolchain:
- Vite is handling the rapid development workflow along with Hot Module Replacement (HMR), as indicated in the README.
- Type Safety:
- The project leverages TypeScript, and the presence of tsconfig files along with type definitions in “types” ensures that the architecture is enforceable at compile time.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Client UI Layer
    subgraph "Frontend Client UI"
        EIndex["index.html"]:::ui
        MTSX["main.tsx"]:::ui
        AppTSX["App.tsx"]:::ui
    end
    EIndex --> MTSX
    MTSX --> AppTSX

    %% Routing Layer
    subgraph "Routing Components"
        Home["Home.tsx"]:::route
        ExpenseRoute["Expense.tsx"]:::route
        IncomeRoute["Income.tsx"]:::route
        SeeExpense["SeeExpenseList.tsx"]:::route
        SeeIncome["SeeIncomeList.tsx"]:::route
    end
    AppTSX --> Home
    AppTSX --> ExpenseRoute
    AppTSX --> IncomeRoute
    AppTSX --> SeeExpense
    AppTSX --> SeeIncome

    %% UI Components Layer
    subgraph "UI Components"
        ExpUI["Expense UI Components"]:::ui
        IncUI["Income UI Components"]:::ui
        FinStatus["Financial Status (TotalFinancialStatus.tsx)"]:::ui
        Styles["Styling Resources"]:::ui
    end
    %% Connect routes to corresponding UI components
    ExpenseRoute --> ExpUI
    SeeExpense --> ExpUI
    IncomeRoute --> IncUI
    SeeIncome --> IncUI
    Home --> FinStatus

    %% State Management and Custom Hooks
    subgraph "State Management"
        StateMgr["IncomeOrExpense Context & Hook"]:::state
    end
    %% Custom Hooks for modal management
    ModalHooks["Modal Management Hooks"]:::hook

    %% Utilities
    LocalStorage["Local Storage Utility"]:::util

    %% Build/Development Environment
    subgraph "Configuration & Build"
        ViteConfig["vite.config.ts"]:::config
        ESLint["eslint.config.js"]:::config
        TSApp["tsconfig.app.json"]:::config
        TSMain["tsconfig.json"]:::config
        TSNode["tsconfig.node.json"]:::config
    end
    BuildEnv["Build/Development Environment (Vite, React, TypeScript, ESLint)"]:::config

    %% Connecting State Management and UI
    ExpUI -->|"uses state"| StateMgr
    IncUI -->|"uses state"| StateMgr
    FinStatus -->|"displays state"| StateMgr
    %% Custom hooks feed UI components for modal management
    ExpUI -->|"modal control"| ModalHooks
    IncUI -->|"modal control"| ModalHooks
    %% State management persists data via local storage
    StateMgr -->|"persists data"| LocalStorage

    %% Styling supports UI components
    ExpUI --> Styles
    IncUI --> Styles

    %% Build environment supports the Frontend Client UI
    BuildEnv --> AppTSX
    ViteConfig -.-> BuildEnv
    ESLint -.-> BuildEnv
    TSApp -.-> BuildEnv
    TSMain -.-> BuildEnv
    TSNode -.-> BuildEnv

    %% Click Events
    click EIndex "https://github.com/10jonathan93/income-expense-app/blob/main/index.html"
    click MTSX "https://github.com/10jonathan93/income-expense-app/blob/main/src/main.tsx"
    click AppTSX "https://github.com/10jonathan93/income-expense-app/blob/main/src/App.tsx"
    click ExpUI "https://github.com/10jonathan93/income-expense-app/tree/main/src/components/expense"
    click IncUI "https://github.com/10jonathan93/income-expense-app/tree/main/src/components/income"
    click FinStatus "https://github.com/10jonathan93/income-expense-app/blob/main/src/components/financial-status/TotalFinancialStatus.tsx"
    click Home "https://github.com/10jonathan93/income-expense-app/tree/main/src/components/routes"
    click ExpenseRoute "https://github.com/10jonathan93/income-expense-app/tree/main/src/components/routes"
    click IncomeRoute "https://github.com/10jonathan93/income-expense-app/tree/main/src/components/routes"
    click SeeExpense "https://github.com/10jonathan93/income-expense-app/tree/main/src/components/routes"
    click SeeIncome "https://github.com/10jonathan93/income-expense-app/tree/main/src/components/routes"
    click Styles "https://github.com/10jonathan93/income-expense-app/tree/main/src/components/styles"
    click StateMgr "https://github.com/10jonathan93/income-expense-app/blob/main/src/context/IncomeOrExpenseContext.tsx"
    click ModalHooks "https://github.com/10jonathan93/income-expense-app/tree/main/src/hooks"
    click LocalStorage "https://github.com/10jonathan93/income-expense-app/blob/main/src/utils/localStorage.ts"
    click ViteConfig "https://github.com/10jonathan93/income-expense-app/blob/main/vite.config.ts"
    click ESLint "https://github.com/10jonathan93/income-expense-app/blob/main/eslint.config.js"
    click TSApp "https://github.com/10jonathan93/income-expense-app/blob/main/tsconfig.app.json"
    click TSMain "https://github.com/10jonathan93/income-expense-app/blob/main/tsconfig.json"
    click TSNode "https://github.com/10jonathan93/income-expense-app/blob/main/tsconfig.node.json"
    click BuildEnv "https://github.com/10jonathan93/income-expense-app/blob/main/vite.config.ts"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#007bff,stroke-width:2px;
    classDef state fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef hook fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef util fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef config fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
    classDef route fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
