# yeheskieltame/spend-save-analyze architecture

> Architecture diagram of the GitHub repository yeheskieltame/spend-save-analyze, 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/yeheskieltame/spend-save-analyze
- Repository: https://github.com/yeheskieltame/spend-save-analyze

## Overview

##### Main Components Identification

- Frontend Application:
– Built with React and TypeScript, with the entry point in src/main.tsx.
– Contains high-level components (src/App.tsx) that manage routing and layout.
– Comprises individual pages (located in src/pages) such as Dashboard, Analysis, Auth, Savings, and Settings.

- UI Components:
– Housed under src/components, these include both feature-specific components (such as HabitForm, FinancialSummary, SavingsList) and reusable UI elements (in src/components/ui).
– The UI library (shadcn-ui) is integrated here to ensure consistency and reusability throughout the app.

- State and Context Management:
– The application leverages React Context (e.g., AuthContext and FinancialContext in src/contexts) and custom hooks (in src/hooks) to manage application state and business logic.
– This layer connects user interactions in the UI components to the data and business rules.

- External Integrations and Services:
– Integration with Supabase is found in src/integrations/supabase, which handles client configuration and types.
– Business logic is further abstracted in services (e.g., financialService.ts) and utility libraries (src/lib and src/utils) that assist in formatting, data processing, or common operations.

##### Relationships and Interactions

– The entry point (main.tsx) renders the core App component (App.tsx), which sets up the routing system connecting various pages.
– Pages are composed of multiple smaller components that serve specific functionalities (e.g., habits tracking, financial summaries).
– UI components feed into contexts (like AuthContext and FinancialContext) via hooks that interact with services to fetch or process data.
– The Supabase integration module serves as the external bridge for data persistence and user authentication, with services wrapping around this integration layer.

##### Architectural Patterns and Design Principles

– Component-Based Architecture: The project is modular with a strict separation between the UI, business logic, state management, and external integrations.
– Separation of Concerns: By isolating contexts, hooks, services, and UI elements into distinct directories, changes in one rarely impact others, keeping the codebase clean and maintainable.
– Declarative and Reactive Design: Leveraging React patterns, the UI reflects state changes and prop drilling across contexts.
– Integration Abstraction: The Supabase client is abstracted out, making it easier to swap or modify backend services in the future.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE1["Entry Point (React, Vite, TS)"]:::frontend
        FE2["Core App Component (Routing)"]:::frontend
        FE3["Pages (Dashboard,Analysis,Auth,Savings,Settings)"]:::frontend
        subgraph "UI Components"
            FC["Feature-Specific Components"]:::frontend
            RU["Reusable UI Library Components"]:::frontend
        end
        FE5a["React Context (AuthContext,FinancialContext)"]:::state
        FE5b["Custom Hooks"]:::state
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        BS["Business Services (financialService)"]:::business
        UT["Utilities & Helpers (Lib & Utils)"]:::utility
    end

    %% External Services
    subgraph "External Services"
        EX["Supabase Integration"]:::integration
    end

    %% Connections in Frontend
    FE1 -->|"renders"| FE2
    FE2 -->|"setsRoutingTo"| FE3
    FE2 -->|"composes"| FC
    FE2 -->|"composes"| RU
    FE3 -->|"uses"| FC
    FE3 -->|"uses"| RU
    FC -->|"updates"| FE5a
    RU -->|"updates"| FE5b

    %% Connections between Layers
    FE5a -->|"calls"| BS
    FE5b -->|"calls"| BS
    UT -->|"supports"| BS
    BS -->|"invokes"| EX

    %% Click Events
    click FE1 "https://github.com/yeheskieltame/spend-save-analyze/blob/main/src/main.tsx"
    click FE2 "https://github.com/yeheskieltame/spend-save-analyze/blob/main/src/App.tsx"
    click FE3 "https://github.com/yeheskieltame/spend-save-analyze/tree/main/src/pages"
    click FC "https://github.com/yeheskieltame/spend-save-analyze/tree/main/src/components"
    click RU "https://github.com/yeheskieltame/spend-save-analyze/tree/main/src/components/ui"
    click FE5a "https://github.com/yeheskieltame/spend-save-analyze/tree/main/src/contexts"
    click FE5b "https://github.com/yeheskieltame/spend-save-analyze/tree/main/src/hooks"
    click BS "https://github.com/yeheskieltame/spend-save-analyze/blob/main/src/services/financialService.ts"
    click EX "https://github.com/yeheskieltame/spend-save-analyze/tree/main/src/integrations/supabase"
    click UT "https://github.com/yeheskieltame/spend-save-analyze/tree/main/src/lib"
    click UT "https://github.com/yeheskieltame/spend-save-analyze/tree/main/src/utils"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef state fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef business fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef utility fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef integration fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
```
