# chinmaynkr/stock_avg_calculator architecture

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

- Interactive diagram: https://gitdiagram.com/chinmaynkr/stock_avg_calculator
- Repository: https://github.com/chinmaynkr/stock_avg_calculator

## Overview

##### Project type and purpose
- This is a Flutter-based, cross-platform mobile (Android, iOS), desktop (Windows, macOS, Linux), and web application.
- Purpose: Let users add stock purchase entries (quantity, unit price), compute total investment and overall average price, manage entries (delete, reset), and persist history locally using SharedPreferences.

##### File structure
- Top-level “lib/” holds the Dart source: main.dart, UI screens, models, providers.
- “android/”, “ios/”, “windows/”, “macos/”, “linux/”, “web/” directories contain platform-specific embedder code generated by Flutter.
- pubspec.yaml + pubspec.lock list dependencies, including provider (state management) and shared_preferences.

##### README for insights
- Architecture is not explicitly drawn but mentions Provider for state management and SharedPreferences for persistence.
- Features: Entry addition, deletion, reset, history, theming.

##### Main components and their interactions
a. UI Layer (Flutter Widgets)
- Screens/Widgets:
- EntryFormWidget (quantity & price input, “Add Entry” button)
- HistoryScreen (lists all past entries with timestamps)
- SettingsScreen (theme toggle, social links)
- Interacts with State Provider to read and modify data.
b. State Management Layer
- Provider(s): e.g., StockEntryProvider or HistoryProvider
- Holds in-memory list of entries, computes total and average.
- Exposes methods: addEntry(), deleteEntry(), resetEntries().
c. Persistence Layer
- SharedPreferences plugin (Flutter → native mobile storage)
- On each add/delete/reset, Provider writes updated history to SharedPreferences.
- At app startup, Provider loads persisted history.
d. Domain Model
- StockEntry: data class with quantity, pricePerUnit, totalInvestment, timestamp.
e. Flutter Engine & Platform Embedders
- Flutter framework and Dart runtime communicate via platform channels to native code for SharedPreferences and theming.
f. Third-Party Libraries
- provider: state management
- shared_preferences: persistence
- cupertino_icons, flutter_localizations (optional)

##### Architectural patterns & design principles
- Provider pattern (simple MVVM-style):
- View (Widgets) binds to ViewModel (Provider)
- ViewModel updates Model (StockEntry list) and notifies View
- Single responsibility:
- UI widgets focus on rendering, Provider on state, SharedPreferences on persistence.
- Dependency injection via Provider’s MultiProvider at root (in main.dart).

##### Detail level
- Every logical component: entry form, list widget, provider, model, persistence plugin, Flutter Engine, platform embedder.
- Avoid over-abstracting; break UI layer into main screens.
- Data flow from user input → in-memory state → persistence → UI update.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI Layer"
        EF["EntryFormWidget"]:::ui
        EL["EntryListWidget"]:::ui
        HS["HistoryScreen"]:::ui
        SS["SettingsScreen"]:::ui
    end

    subgraph "State Management"
        SP["StockEntryProvider"]:::state
    end

    DM["StockEntry"]:::domain

    subgraph "Persistence Layer"
        PL["SharedPreferences"]:::persistence
    end

    subgraph "Flutter Engine"
        FE["Flutter Engine"]:::embedder
    end

    subgraph "Platform Layer"
        A["Android"]:::embedder
        I["iOS"]:::embedder
        Wb["Web"]:::embedder
        Lnx["Linux"]:::embedder
        Mac["macOS"]:::embedder
        Win["Windows"]:::embedder
    end

    subgraph "Third-Party Libraries"
        Prov["Provider"]:::thirdparty
        SPkg["shared_preferences"]:::thirdparty
        CI["cupertino_icons"]:::thirdparty
        FL["flutter_localizations"]:::thirdparty
    end

    subgraph "Assets"
        Fonts["Custom Fonts"]:::asset
    end

    EF -->|"addEntry()"| SP
    EL -->|"deleteEntry()"| SP
    HS -->|"readHistory()"| SP
    SS -->|"resetEntries()"| SP

    SP -->|"saveHistory()/loadHistory()"| PL
    SP -->|"create instances"| DM

    FE <--> A
    FE <--> I
    FE <--> Wb
    FE <--> Lnx
    FE <--> Mac
    FE <--> Win

    %% Click Events
    click EF "https://github.com/chinmaynkr/stock_avg_calculator/blob/main/lib/main.dart"
    click EL "https://github.com/chinmaynkr/stock_avg_calculator/blob/main/lib/main.dart"
    click HS "https://github.com/chinmaynkr/stock_avg_calculator/blob/main/lib/main.dart"
    click SS "https://github.com/chinmaynkr/stock_avg_calculator/blob/main/lib/main.dart"
    click SP "https://github.com/chinmaynkr/stock_avg_calculator/blob/main/lib/main.dart"
    click DM "https://github.com/chinmaynkr/stock_avg_calculator/blob/main/lib/main.dart"
    click PL "https://github.com/chinmaynkr/stock_avg_calculator/blob/main/pubspec.yaml"
    click Fonts "https://github.com/chinmaynkr/stock_avg_calculator/tree/main/assets/fonts/"
    click A "https://github.com/chinmaynkr/stock_avg_calculator/tree/main/android/"
    click I "https://github.com/chinmaynkr/stock_avg_calculator/tree/main/ios/"
    click Wb "https://github.com/chinmaynkr/stock_avg_calculator/tree/main/web/"
    click Lnx "https://github.com/chinmaynkr/stock_avg_calculator/tree/main/linux/"
    click Mac "https://github.com/chinmaynkr/stock_avg_calculator/tree/main/macos/"
    click Win "https://github.com/chinmaynkr/stock_avg_calculator/tree/main/windows/"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000;
    classDef state fill:#90EE90,stroke:#000;
    classDef persistence fill:#FFA500,stroke:#000;
    classDef embedder fill:#D3D3D3,stroke:#000;
    classDef thirdparty fill:#DDA0DD,stroke:#000;
    classDef domain fill:#FFFFFF,stroke:#000;
    classDef asset fill:#FFE4B5,stroke:#000;
```
