# shendrii/money-wise architecture

> Architecture diagram of the GitHub repository shendrii/money-wise, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shendrii/money-wise
- Repository: https://github.com/shendrii/money-wise

## Overview

##### Main Components

A. Frontend Layer:
- Next.js Application (Client-Side)
- Pages: Expenses and Savings sections
- Components: Navigation, Auth, and UI elements
- Client-Side State Management (Context API)
- UI Framework (likely Material-UI or similar based on Dialog components)

B. Backend Layer:
- Next.js API Routes (Server-Side)
- Firebase Services
- Authentication
- Firestore (Database)

**┌─────────────────────────────────────────────────────────┐**
- Client Browser                         │
- ┬───────────────────────────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Next.js Application                    │
- ┌───────────────────┐      ┌────────────────────────┐ │
- Pages         │      │     Components         │ │
- Home (/)      ←┼─────→│  - Navbar             │ │
- Expenses      │      │  - AuthButton         │ │
- Savings       │      │  - NavDrawer          │ │
- ┘      └────────────────────────┘ │
- ↕                           ↕                 │
- ┌───────────────────┐      ┌────────────────────────┐ │
- Context API      │      │     Services           │ │
- AuthContext    │←────→│  - expenseService      │ │
- ┘      └────────────────────────┘ │
- ┬───────────────────────────────┘
- ↕
**┌────────────────────────────────────────────────────────┐**
- Firebase Services                      │
- ┌─────────────────┐        ┌──────────────────┐    │
- Authentication │        │    Firestore     │    │
- ┘        └──────────────────┘    │
- ┘

##### Key Elements to Highlight

a. Application Architecture:
- Next.js app router structure with (pages) directory
- Component hierarchy
- Authentication flow through Firebase
- Data flow for expense and savings management

b. Data Flow:
- User authentication process
- CRUD operations for expenses
- State management using Context API
- Service layer interaction with Firebase

##### Implementation Details to Note

- How the AuthContext provides authentication state to the application
- How the ExpenseService interfaces with Firebase
- Demonstrate the routing structure using Next.js 13+ app directory
- Role of global styles and configuration files

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Browser"]
        Browser["Web Browser"]
    end

    subgraph NextApp["Next.js Application"]
        subgraph Pages["Pages Layer"]
            Home["Home Page"]
            Expenses["Expenses Page"]
            Savings["Savings Page"]
            Layout["Root Layout"]
        end

        subgraph Components["Component Layer"]
            ClientLayout["Client Layout"]
            Navbar["Navigation Bar"]
            AuthButton["Auth Button"]
            NavDrawer["Nav Drawer"]
            ExpenseDialog["Expense Dialog"]
            ExpenseFilters["Expense Filters"]
            DeleteDialog["Delete Confirm Dialog"]
        end

        subgraph State["State Management"]
            AuthContext["Auth Context"]
        end

        subgraph Services["Services Layer"]
            ExpenseService["Expense Service"]
            FirebaseConfig["Firebase Config"]
        end

        subgraph Types["Type Definitions"]
            ExpenseTypes["Expense Types"]
        end
    end

    subgraph Firebase["Firebase Services"]
        Auth["Authentication"]
        Firestore["Firestore Database"]
    end

    %% Connections
    Browser --> Home
    Home --> Layout
    Expenses --> Layout
    Savings --> Layout
    Layout --> ClientLayout
    ClientLayout --> Navbar
    ClientLayout --> AuthButton
    Navbar --> NavDrawer
    Expenses --> ExpenseDialog
    Expenses --> ExpenseFilters
    Expenses --> DeleteDialog
    
    AuthContext --> AuthButton
    AuthContext --> ClientLayout
    AuthContext --> Auth
    
    ExpenseService --> Firestore
    ExpenseService --> ExpenseTypes
    FirebaseConfig --> Auth
    FirebaseConfig --> Firestore

    %% Click events
    click Home "https://github.com/Shendrii/Money-Wise/blob/main/app/page.tsx"
    click Expenses "https://github.com/Shendrii/Money-Wise/blob/main/app/(pages)/expenses/page.tsx"
    click Savings "https://github.com/Shendrii/Money-Wise/blob/main/app/(pages)/savings/page.tsx"
    click Navbar "https://github.com/Shendrii/Money-Wise/blob/main/app/components/Navbar.tsx"
    click NavDrawer "https://github.com/Shendrii/Money-Wise/blob/main/app/components/NavDrawer.tsx"
    click AuthButton "https://github.com/Shendrii/Money-Wise/blob/main/app/components/AuthButton.tsx"
    click ExpenseDialog "https://github.com/Shendrii/Money-Wise/blob/main/app/(pages)/expenses/components/ExpenseDialog.tsx"
    click ExpenseFilters "https://github.com/Shendrii/Money-Wise/blob/main/app/(pages)/expenses/components/ExpenseFilters.tsx"
    click DeleteDialog "https://github.com/Shendrii/Money-Wise/blob/main/app/(pages)/expenses/components/DeleteConfirmDialog.tsx"
    click AuthContext "https://github.com/Shendrii/Money-Wise/blob/main/app/context/AuthContext.tsx"
    click FirebaseConfig "https://github.com/Shendrii/Money-Wise/blob/main/app/firebase/firebase.ts"
    click ExpenseService "https://github.com/Shendrii/Money-Wise/blob/main/app/services/expenseService.ts"
    click ClientLayout "https://github.com/Shendrii/Money-Wise/blob/main/app/components/ClientLayout.tsx"
    click ExpenseTypes "https://github.com/Shendrii/Money-Wise/blob/main/app/types/expense.ts"
    click Layout "https://github.com/Shendrii/Money-Wise/blob/main/app/layout.tsx"

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef browser fill:#ddd,stroke:#333
    classDef page fill:#b4d9fb,stroke:#333
    classDef component fill:#95dab6,stroke:#333
    classDef state fill:#ffd7b5,stroke:#333
    classDef service fill:#e9d5fd,stroke:#333
    classDef firebase fill:#ffb380,stroke:#333
    classDef types fill:#d4d4d4,stroke:#333

    class Browser browser
    class Home,Expenses,Savings,Layout page
    class ClientLayout,Navbar,AuthButton,NavDrawer,ExpenseDialog,ExpenseFilters,DeleteDialog component
    class AuthContext state
    class ExpenseService,FirebaseConfig service
    class Auth,Firestore firebase
    class ExpenseTypes types
```
