# bhagirihi/moneyexpensemobile architecture

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

- Interactive diagram: https://gitdiagram.com/bhagirihi/moneyexpensemobile
- Repository: https://github.com/bhagirihi/moneyexpensemobile

## Overview

##### Project Type & Purpose
- Type: Full‑stack mobile application (React Native + Expo)
- Purpose: Expense tracking and management (personal and shared), with real‑time collaboration and analytics.

##### Top‑Level Components
A. Mobile Client (React Native/Expo)
1. UI Layer
– src/components & src/screens
– Navigation: src/navigation/AppNavigator.js
2. State Management
– Context Providers: AuthContext, ThemeContext, AppSettingsContext
– Async Storage for local persistence
3. Service Layer
– Business services: expenseService, categoryService, dashboardService, etc.
– Real‑time sync: WebSocket via realTimeSync.js
4. Configuration
– supabase config: src/config/supabase.js
5. Utilities & Theming
– Formatters, toast utils, theme.js
B. Backend as a Service (Supabase)
1. Auth & User Profiles
2. PostgreSQL Database + Migrations (supabase/migrations)
3. Real‑time Postgres subscriptions
4. Storage (for receipts, profile pictures)
C. Third‑Party Integrations
– Google Sign‑In
– Calendar import
– Notification Service (push notifications)
D. DevOps/Infrastructure
– EAS / expo configuration (eas.json, app.json)
– CI/CD build scripts (APK_BUILD_GUIDE.md)

##### Relationships & Data Flow
1. User interacts with UI screens → triggers actions in Components
2. Components call Service Layer methods → these wrap REST or real‑time calls to Supabase
3. Supabase Auth module handles login/2FA → returns JWT
4. Supabase Postgres handles CRUD on expenses, categories, boards → real‑time updates stream back to client via WebSocket
5. Client persists some data locally in Async Storage (offline support)
6. NotificationService connects to FCM/APNs for push notifications
7. External integrations (Google, Calendar) invoked via service modules

##### Architectural Patterns & Principles
- Layered Architecture:
– Presentation (React Native UI)
– Application/Service layer
– Data layer (Supabase)
- Context API for global state – clear separation of concerns
- Service‑oriented modules (each domain area has its own service file)
- Real‑time eventing via WebSocket subscriptions (pub/sub)

##### Technologies & Frameworks
– React Native + Expo (App.js, index.js)
– React Navigation
– Context API + Async Storage
– Supabase JS client (src/config/supabase.js)
– WebSockets for real‑time sync
– Local assets/fonts, theming engine (src/theme/theme.js)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Mobile App"
        subgraph "UI Layer"
            Screens["Screens"]:::ui
            Components["Components"]:::ui
            Navigator["AppNavigator"]:::ui
        end
        subgraph "State Management"
            AuthCtx["AuthContext"]:::logic
            ThemeCtx["ThemeContext"]:::logic
            SettingsCtx["AppSettingsContext"]:::logic
            AsyncStore["Async Storage"]:::data
        end
        subgraph "Service Layer"
            ExpenseSvc["expenseService"]:::logic
            CategorySvc["categoryService"]:::logic
            DashboardSvc["dashboardService"]:::logic
            BoardSvc["expenseBoardService"]:::logic
            AnalysisSvc["analysisService"]:::logic
            AnalyticsSvc["analyticsService"]:::logic
            NotificationSvc["notificationService"]:::logic
            RealTimeSync["realTimeSync"]:::logic
            SupabaseSvc["supabaseService"]:::logic
            TripSvc["tripService"]:::logic
        end
        subgraph "Config & Utils"
            SupabaseConfig["supabase.js"]:::data
            Formatters["formatters.js"]:::logic
            Toast["toast.js"]:::logic
            ThemeFile["theme.js"]:::logic
        end
    end

    subgraph "Supabase Services"
        AuthModule["Auth & Profiles"]:::data
        Postgres["PostgreSQL DB"]:::data
        Migrations["Migrations"]:::data
        Storage["Storage (receipts/pics)"]:::data
    end

    subgraph "External Integrations"
        Google["Google Sign-In"]:::external
        Calendar["Calendar API"]:::external
        FCM["FCM/APNs"]:::external
    end

    subgraph "DevOps/Infra"
        AppJSON["app.json"]:::external
        EAS["eas.json"]:::external
        BuildGuide["APK_BUILD_GUIDE.md"]:::external
    end

    subgraph "Dev Tools"
        GenExpenses["generate_expenses.py"]:::external
        MergedDB["merged_database.sql"]:::external
    end

    Screens -->|"user events"| ExpenseSvc
    Screens -->|"user events"| CategorySvc
    Screens -->|"user events"| DashboardSvc
    Screens -->|"user events"| BoardSvc

    ExpenseSvc -->|"REST API (JSON)"| SupabaseSvc
    CategorySvc -->|"REST API (JSON)"| SupabaseSvc
    DashboardSvc -->|"REST API (JSON)"| SupabaseSvc
    BoardSvc -->|"REST API (JSON)"| SupabaseSvc
    AnalysisSvc -->|"REST API (JSON)"| SupabaseSvc
    AnalyticsSvc -->|"REST API (JSON)"| SupabaseSvc
    TripSvc -->|"REST API (JSON)"| SupabaseSvc

    RealTimeSync -->|"WebSocket"| SupabaseSvc
    SupabaseSvc -->|"WebSocket"| RealTimeSync

    ExpenseSvc <-->|"cache"| AsyncStore
    CategorySvc <-->|"cache"| AsyncStore

    NotificationSvc -->|"push"| FCM

    SupabaseSvc -->|"JWT"| AuthCtx
    AuthCtx -->|"login/register"| SupabaseSvc

    ExpenseSvc -->|"OAuth"| Google
    TripSvc -->|"import"| Calendar

    SupabaseSvc --> AuthModule
    SupabaseSvc --> Postgres
    SupabaseSvc --> Storage
    Postgres --> RealTimeSync

    classDef ui fill:#D0E6FF,stroke:#0366d6,stroke-width:1px
    classDef logic fill:#DFFFD0,stroke:#228B22,stroke-width:1px
    classDef data fill:#FFE5B4,stroke:#FF8C00,stroke-width:1px
    classDef external fill:#E6E6FA,stroke:#800080,stroke-width:1px

    click Screens "https://github.com/bhagirihi/moneyexpensemobile/tree/main/src/screens"
    click Components "https://github.com/bhagirihi/moneyexpensemobile/tree/main/src/components"
    click Navigator "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/navigation/AppNavigator.js"
    click AuthCtx "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/context/AuthContext.js"
    click ThemeCtx "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/context/ThemeContext.js"
    click SettingsCtx "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/context/AppSettingsContext.js"
    click ExpenseSvc "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/services/expenseService.js"
    click CategorySvc "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/services/categoryService.js"
    click DashboardSvc "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/services/dashboardService.js"
    click BoardSvc "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/services/expenseBoardService.js"
    click AnalysisSvc "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/services/analysisService.js"
    click AnalyticsSvc "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/services/analyticsService.js"
    click NotificationSvc "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/services/notificationService.js"
    click RealTimeSync "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/services/realTimeSync.js"
    click SupabaseSvc "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/services/supabaseService.js"
    click TripSvc "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/services/tripService.js"
    click SupabaseConfig "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/config/supabase.js"
    click Formatters "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/utils/formatters.js"
    click Toast "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/utils/toast.js"
    click ThemeFile "https://github.com/bhagirihi/moneyexpensemobile/blob/main/src/theme/theme.js"
    click Migrations "https://github.com/bhagirihi/moneyexpensemobile/tree/main/supabase/migrations"
    click AppJSON "https://github.com/bhagirihi/moneyexpensemobile/blob/main/app.json"
    click EAS "https://github.com/bhagirihi/moneyexpensemobile/blob/main/eas.json"
    click BuildGuide "https://github.com/bhagirihi/moneyexpensemobile/blob/main/APK_BUILD_GUIDE.md"
    click GenExpenses "https://github.com/bhagirihi/moneyexpensemobile/blob/main/generate_expenses.py"
    click MergedDB "https://github.com/bhagirihi/moneyexpensemobile/blob/main/merged_database.sql"
```
