# jhonacodes/reactive_notifier architecture

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

- Interactive diagram: https://gitdiagram.com/jhonacodes/reactive_notifier
- Repository: https://github.com/jhonacodes/reactive_notifier

## Overview

##### Project Type & Purpose
- This project is a Dart/Flutter state management library designed to be flexible and to work well with the MVVM architectural pattern.
- The README emphasizes use cases such as independent state control (no BuildContext dependency), built-in async & stream support, and repository/service integration. The project is meant to be used as a core state management toolkit in Flutter apps.

##### File Structure for Component Mapping
- The top-level directories (lib, example, test) indicate the organization:
- The “lib” directory contains the core library. Look especially under lib/src which is sub-divided into:
▪ builder – houses various widget builders (reactive_builder.dart, reactive_async_builder.dart, reactive_stream_builder.dart)
▪ handler – contains state handlers for async and stream modes.
▪ implements – provides concrete implementations (notifier_impl.dart, repository_impl.dart, service_impl.dart)
▪ tracker – holds functionality to track state (state_tracker.dart)
▪ viewmodel – includes base classes for ViewModel implementations.
- The “example” directory demonstrates usage (service and viewmodel examples) and
- The “test” folder contains unit tests and golden tests for UI components.

##### Core Components
a. Core State Management Engine:
- ReactiveNotifier (the public API seen in lib/reactive_notifier.dart) – acts as the central point of state creation and update.
b. Builders:
- ReactiveBuilder, ReactiveAsyncBuilder, ReactiveStreamBuilder – Flutter widgets that listen to changes in the ReactiveNotifier and trigger UI updates.
c. Internal Implementations:
- NotifierImpl, RepositoryImpl, ServiceImpl – encapsulate specific functionalities such as state instantiation, repository interactions, and service layers.
d. ViewModel Layer:
- ViewModelImpl and ViewModelStateImpl in the MVVM pattern – manage business logic and state transitions.
e. Support & Utility Components:
- Handlers and trackers (async_state.dart, stream_state.dart, state_tracker.dart) managing state transitions and debug-related tracking.
f. External Integration:
- Repository and Service layers connected with external or asynchronous data sources.
- Example usage demonstrates how the library integrates with the Flutter UI via “ReactiveBuilder” and how notifiers can be declared using mixins.

##### Establish Relationships and Interactions
- Data Flow: Show the relationship from a Repository (data source) → ViewModel (business logic using RepositoryImpl and ViewModelImpl) → ReactiveNotifier (state holder) → Flutter UI (via ReactiveBuilder).
- Modular separation: Highlight that the UI is independent from the business logic (MVVM) and state management.

##### Architectural Patterns and Design Principles to Highlight
- MVVM Pattern: Separate View (builders), ViewModel (state logic) and Model (data provided via repositories).
- Layered Architecture: Core library (business logic and state management), a middle layer (repository/service logic), and presentation (Flutter widgets) are clearly demarcated.
- Unidirectional Data Flow: The state is updated in the notifier and then propagated down to the UI.
- Dependency Injection: Notifiers are typically created at a higher level (for example, as static mixins) and injected where needed.
- Flexibility & Extensibility: The use of mixins and “related” notifiers to allow decoupled and independent updates.

- Component is labeled with its responsibilities and includes technology notes where relevant (e.g., Dart/Flutter, MVVM, etc.).

- Finally, link the notifier to various Flutter UI builder components, as seen in the example directory.

This structure should provide a complete and accurate visualization of the architecture for “ReactiveNotifier” that details its core design, how states are managed, and how various layers interact in a typical Flutter application using MVVM and reactive programming principles.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data/Business Logic Layer
    subgraph "Data/Business Logic"
        Repo["RepositoryImpl"]:::logic
        Serv["ServiceImpl"]:::logic
        VM["ViewModelImpl"]:::logic
    end

    %% Core Engine Layer
    subgraph "Core Engine"
        RN["ReactiveNotifier (API)"]:::core
        NI["NotifierImpl"]:::core
        ASH["Async State Handler"]:::utility
        SSH["Stream State Handler"]:::utility
        ST["State Tracker"]:::utility
    end

    %% UI/Presentation Layer
    subgraph "UI/Presentation"
        RB["ReactiveBuilder"]:::builder
        RAB["ReactiveAsyncBuilder"]:::builder
        RSB["ReactiveStreamBuilder"]:::builder
    end

    %% Example Integration Layer
    subgraph "Example Integration"
        CS["ConnectionService"]:::example
        CSVM["ConnectionStateViewmodel"]:::example
    end

    %% Connections between layers
    Repo -->|"provides"| VM
    Serv -->|"services"| VM
    VM -->|"updates"| RN
    RN -->|"notifies"| RB
    RN -->|"notifies"| RAB
    RN -->|"streams"| RSB
    RN -->|"implements"| NI
    RN -->|"handles"| ASH
    RN -->|"handles"| SSH
    RN -->|"tracks"| ST
    Serv -->|"integrates"| CS
    VM -->|"integrates"| CSVM

    %% Click Events
    click RN "https://github.com/jhonacodes/reactive_notifier/blob/main/lib/reactive_notifier.dart"
    click RB "https://github.com/jhonacodes/reactive_notifier/blob/main/lib/src/builder/reactive_builder.dart"
    click RAB "https://github.com/jhonacodes/reactive_notifier/blob/main/lib/src/builder/reactive_async_builder.dart"
    click RSB "https://github.com/jhonacodes/reactive_notifier/blob/main/lib/src/builder/reactive_stream_builder.dart"
    click NI "https://github.com/jhonacodes/reactive_notifier/blob/main/lib/src/implements/notifier_impl.dart"
    click Repo "https://github.com/jhonacodes/reactive_notifier/blob/main/lib/src/implements/repository_impl.dart"
    click Serv "https://github.com/jhonacodes/reactive_notifier/blob/main/lib/src/implements/service_impl.dart"
    click VM "https://github.com/jhonacodes/reactive_notifier/blob/main/lib/src/viewmodel/viewmodel_impl.dart"
    click ASH "https://github.com/jhonacodes/reactive_notifier/blob/main/lib/src/handler/async_state.dart"
    click SSH "https://github.com/jhonacodes/reactive_notifier/blob/main/lib/src/handler/stream_state.dart"
    click ST "https://github.com/jhonacodes/reactive_notifier/blob/main/lib/src/tracker/state_tracker.dart"
    click CS "https://github.com/jhonacodes/reactive_notifier/blob/main/example/service/connection_service.dart"
    click CSVM "https://github.com/jhonacodes/reactive_notifier/blob/main/example/viewmodel/connection_state_viewmodel.dart"

    %% Styles
    classDef core fill:#FFA07A,stroke:#8B0000,stroke-width:2px;
    classDef builder fill:#B0E0E6,stroke:#4682B4,stroke-width:2px;
    classDef logic fill:#98FB98,stroke:#2E8B57,stroke-width:2px;
    classDef utility fill:#FFFACD,stroke:#DAA520,stroke-width:2px;
    classDef example fill:#E6E6FA,stroke:#9400D3,stroke-width:2px;
```
