# ekrajghimire/hisabkitab architecture

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

- Interactive diagram: https://gitdiagram.com/ekrajghimire/hisabkitab
- Repository: https://github.com/ekrajghimire/hisabkitab

## Overview

##### Project type and purpose
- This is a cross-platform full-stack mobile/web/desktop application built with Flutter.
- Purpose: group expense management—track, split, and settle expenses in real time, with features like multi-currency support, offline mode, receipt scanning, analytics, and export.

##### High-level architecture components
a. Clients (Flutter apps running on Android, iOS, Web, Windows, macOS, Linux)
b. Presentation Layer (Flutter UI widgets organized by feature under lib/features)
c. State Management Layer (Provider/BLoC classes under lib/features/*/providers)
d. Domain & Business Logic (Models under lib/models, utility classes in lib/core/utils)
e. Service Layer (FirebaseService in lib/core/services)
f. Backend as a Service (Firebase Auth, Cloud Firestore, Cloud Storage, optional Cloud Functions)
g. External Services (e.g., currency-conversion API if used)

##### Relationships and data flows
- Users interact with the UI (screens under lib/features/*/screens).
- UI widgets dispatch actions or listen to State Management providers (lib/features/*/providers).
- Providers call Domain/Business Logic and Service Layer methods.
- FirebaseService functions encapsulate calls to Firebase SDKs:
– Authentication (sign-up, login, password reset)
– Firestore (read/write group, expense, user, settlement documents)
– Storage (upload/download receipt images)
- Data flows back: Firestore real-time streams update providers → UI reflects changes instantly, supporting offline persistence.
- For analytics, providers aggregate Firestore data, compute charts, and feed UI.
- Exports (CSV/PDF) are generated locally on the client, optionally using third-party Dart packages.

##### Architectural patterns and principles
- Feature-based folder structure (lib/features) for modularity and scalability.
- Separation of concerns: UI, state management, domain models, services.
- Provider (or Bloc) pattern for reactive state and dependency injection.
- Single source of truth in Firestore with real-time synchronization and offline support.
- Core utilities and theming in lib/core for reuse across features.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Platforms
    subgraph "Client Platforms"
        direction TB
        Android["Android"]:::client
        iOS["iOS"]:::client
        Web["Web"]:::client
        Linux["Linux"]:::client
        macOS["macOS"]:::client
        Windows["Windows"]:::client
    end

    %% Flutter Core
    subgraph "Flutter Engine & Renderer"
        direction TB
        FlutterCore["Flutter Engine & Renderer"]:::client
    end

    %% Presentation Layer
    subgraph "Presentation Layer (UI Widgets)" 
        direction TB
        AuthScreens["Auth Screens"]:::presentation
        DashboardScreens["Dashboard Screens"]:::presentation
        ExpensesScreens["Expenses Screens"]:::presentation
        ExpensesWidgets["Expenses Widgets"]:::presentation
        GroupsScreens["Groups Screens"]:::presentation
        AnalyticsScreens["Analytics Screens"]:::presentation
        ProfileScreens["Profile Screens"]:::presentation
    end

    %% State Management
    subgraph "State Management (Providers/BLoCs)"
        direction TB
        AuthProvider["Authentication Provider"]:::state
        ExpensesProvider["Expenses Provider"]:::state
        GroupsProvider["Groups Provider"]:::state
        ThemeProvider["Theme Settings Provider"]:::state
    end

    %% Domain & Business Logic
    subgraph "Domain & Business Logic"
        direction TB
        ExpenseModel["Expense Model"]:::domain
        GroupModel["Group Model"]:::domain
        SettlementModel["Settlement Model"]:::domain
        UserModel["User Model"]:::domain
        AppUtils["App Utilities"]:::domain
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        FirebaseService["FirebaseService"]:::service
    end

    %% Backend Services
    subgraph "Backend Services"
        direction TB
        AuthService["Firebase Auth"]:::backend
        FirestoreDB["Cloud Firestore"]:::backend
        StorageService["Cloud Storage"]:::backend
        Functions["Cloud Functions (optional)"]:::backend
        OfflineCache["Offline Cache"]:::backend
    end

    %% External API
    subgraph "External Services"
        direction TB
        CurrencyAPI["Currency Conversion API"]:::external
    end

    %% Connections
    Android -->|Launch| FlutterCore
    iOS -->|Launch| FlutterCore
    Web -->|Launch| FlutterCore
    Linux -->|Launch| FlutterCore
    macOS -->|Launch| FlutterCore
    Windows -->|Launch| FlutterCore

    FlutterCore -->|renders UI| AuthScreens
    FlutterCore -->|renders UI| DashboardScreens
    FlutterCore -->|renders UI| ExpensesScreens
    FlutterCore -->|renders UI| ExpensesWidgets
    FlutterCore -->|renders UI| GroupsScreens
    FlutterCore -->|renders UI| AnalyticsScreens
    FlutterCore -->|renders UI| ProfileScreens

    AuthScreens -->|dispatch action| AuthProvider
    DashboardScreens -->|listen| ExpensesProvider
    ExpensesScreens -->|dispatch action| ExpensesProvider
    ExpensesWidgets -->|listen| ExpensesProvider
    GroupsScreens -->|dispatch action| GroupsProvider
    AnalyticsScreens -->|dispatch action| ExpensesProvider
    ProfileScreens -->|dispatch action| ThemeProvider

    AuthProvider -->|uses| FirebaseService
    ExpensesProvider -->|uses| FirebaseService
    GroupsProvider -->|uses| FirebaseService
    ThemeProvider -->|uses| AppUtils

    FirebaseService -->|Auth SDK| AuthService
    FirebaseService -->|Firestore SDK| FirestoreDB
    FirebaseService -->|Storage SDK| StorageService
    FirebaseService -->|Functions SDK| Functions

    FirestoreDB -->|real-time streams| ExpensesProvider
    FirestoreDB -->|real-time streams| GroupsProvider
    FirestoreDB -->|real-time streams| AuthProvider

    FirestoreDB -->|caches offline| OfflineCache
    OfflineCache -->|sync when online| FirestoreDB

    ExpensesProvider -->|compute analytics| AnalyticsScreens
    ExpensesProvider -->|export CSV/PDF| AppUtils
    GroupsProvider -->|export CSV/PDF| AppUtils

    CurrencyAPI -.->|REST API| FirebaseService

    %% Click Events
    click Android "https://github.com/ekrajghimire/hisabkitab/tree/main/android/"
    click iOS "https://github.com/ekrajghimire/hisabkitab/tree/main/ios/"
    click Web "https://github.com/ekrajghimire/hisabkitab/tree/main/web/"
    click Linux "https://github.com/ekrajghimire/hisabkitab/tree/main/linux/"
    click macOS "https://github.com/ekrajghimire/hisabkitab/tree/main/macos/"
    click Windows "https://github.com/ekrajghimire/hisabkitab/tree/main/windows/"
    click AuthScreens "https://github.com/ekrajghimire/hisabkitab/tree/main/lib/features/auth/screens/"
    click DashboardScreens "https://github.com/ekrajghimire/hisabkitab/tree/main/lib/features/dashboard/screens/"
    click ExpensesScreens "https://github.com/ekrajghimire/hisabkitab/tree/main/lib/features/expenses/screens/"
    click ExpensesWidgets "https://github.com/ekrajghimire/hisabkitab/tree/main/lib/features/expenses/widgets/"
    click GroupsScreens "https://github.com/ekrajghimire/hisabkitab/tree/main/lib/features/groups/screens/"
    click AnalyticsScreens "https://github.com/ekrajghimire/hisabkitab/tree/main/lib/features/analytics/screens/"
    click ProfileScreens "https://github.com/ekrajghimire/hisabkitab/tree/main/lib/features/profile/screens/"
    click AuthProvider "https://github.com/ekrajghimire/hisabkitab/blob/main/lib/features/auth/providers/auth_provider.dart"
    click ExpensesProvider "https://github.com/ekrajghimire/hisabkitab/blob/main/lib/features/expenses/providers/expenses_provider.dart"
    click GroupsProvider "https://github.com/ekrajghimire/hisabkitab/blob/main/lib/features/groups/providers/groups_provider.dart"
    click ThemeProvider "https://github.com/ekrajghimire/hisabkitab/blob/main/lib/features/settings/providers/theme_provider.dart"
    click ExpenseModel "https://github.com/ekrajghimire/hisabkitab/blob/main/lib/models/expense_model.dart"
    click GroupModel "https://github.com/ekrajghimire/hisabkitab/blob/main/lib/models/group_model.dart"
    click SettlementModel "https://github.com/ekrajghimire/hisabkitab/blob/main/lib/models/settlement_model.dart"
    click UserModel "https://github.com/ekrajghimire/hisabkitab/blob/main/lib/models/user_model.dart"
    click AppUtils "https://github.com/ekrajghimire/hisabkitab/blob/main/lib/core/utils/app_utils.dart"
    click FirebaseService "https://github.com/ekrajghimire/hisabkitab/blob/main/lib/core/services/firebase_service.dart"
    click AppTheme "https://github.com/ekrajghimire/hisabkitab/blob/main/lib/core/theme/app_theme.dart"
    click AppConstants "https://github.com/ekrajghimire/hisabkitab/blob/main/lib/core/constants/app_constants.dart"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef presentation fill:#E0F7FA,stroke:#00796B,color:#00796B
    classDef state fill:#FFF9C4,stroke:#FBC02D,color:#F57F17
    classDef domain fill:#F3E5F5,stroke:#6A1B9A,color:#6A1B9A
    classDef service fill:#E8F5E9,stroke:#388E3C,color:#2E7D32
    classDef backend fill:#FFE0B2,stroke:#F57C00,color:#E65100
    classDef external fill:#F5F5F5,stroke:#9E9E9E,color:#616161
    classDef dashed-gray stroke-dasharray: 5 5,color:#9E9E9E
```
