# jhonacodes/result_controller architecture

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

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

## Overview

##### Main components
- Public API Module: Represented by the core file (lib/result_controller.dart) and the publicly exported interfaces (including parts of the lib/ directory).
- Internal Modules (lib/src): This includes:
- API Error Handling: api_err_handler.dart, api_response_handler.dart, and api_handler.dart.
- Core Error Handling: err_handler.dart and ok_handler.dart which underpin the Result functionality.
- Extensions: extension.dart to offer extra utilities on the Result type.
- Additional internal implementation: result_controller.dart (inside lib/src) which might contain helper classes and logic.
- Testing and Examples: Although not part of the runtime architecture, the test and example directories show how the library is used and provide a good reference for usage scenarios.

##### Relationships and interactions
- The Public API (lib/result_controller.dart) acts as the entry point for developers and reuses many functions found in the lib/src directory.
- The internal modules interact as follows:
- The API modules handle the conversion between API responses and the standardized Result type.
- Error handling modules (err_handler.dart and ok_handler.dart) manage the logic for constructing and transforming error/success values.
- The extension module augments the Result type with chaining, mapping, and other functional operations.
- The design supports both synchronous and asynchronous operations (as indicated by the presence of trySync, tryAsync, and async operation tests).

##### Architectural patterns
- Functional Programming: The project is built around the Result/Either pattern and the use of chainable, composable operations.
- Separation of Concerns: There is a clear distinction between components that deal with API responses and those that manage internal error handling or data transformations.
- Modularity: The public interfaces are separated from the internal implementations, allowing for cleaner extension points and easier testing.

##### Detailed elements
- A node for the “Result<T, E>” type and its base operations (Ok and Err).
- Nodes for each API Response Handling function (when, whenList, etc.).
- Nodes for helper transformers (map, flatMap, recover, mapError).
- Technology references (Dart 3, Flutter 3.10) if desired for context.

This approach should give a comprehensive visual representation that can be easily communicated and understood by your development team and stakeholders.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Public API Layer"
        PublicAPIModule["Public API Module"]:::public
    end

    subgraph "Internal Modules"
        ResultController["Result Controller"]:::internal
        APIHandler["API Handler"]:::internal
        APIErrorHandler["API Error Handler"]:::internal
        APIResponseHandler["API Response Handler"]:::internal
        ErrorHandler["Error Handler"]:::internal
        OkHandler["Ok Handler"]:::internal
        Extensions["Extensions"]:::internal
        ResultType["Result<T,E>"]:::core
    end

    subgraph "Testing/Examples"
        Testing["Testing/Examples"]:::testing
    end

    PublicAPIModule --> ResultController
    ResultController --> APIHandler
    APIHandler --> APIErrorHandler
    APIHandler --> APIResponseHandler
    ResultController --> ErrorHandler
    ResultController --> OkHandler
    ErrorHandler --> ResultType
    OkHandler --> ResultType
    ResultController --> Extensions
    Extensions --> ResultType
    PublicAPIModule --> Testing

    click PublicAPIModule "https://github.com/jhonacodes/result_controller/blob/main/lib/result_controller.dart"
    click ResultController "https://github.com/jhonacodes/result_controller/blob/main/lib/src/result_controller.dart"
    click APIHandler "https://github.com/jhonacodes/result_controller/blob/main/lib/src/api_handler.dart"
    click APIErrorHandler "https://github.com/jhonacodes/result_controller/blob/main/lib/src/api_err_handler.dart"
    click APIResponseHandler "https://github.com/jhonacodes/result_controller/blob/main/lib/src/api_response_handler.dart"
    click ErrorHandler "https://github.com/jhonacodes/result_controller/blob/main/lib/src/err_handler.dart"
    click OkHandler "https://github.com/jhonacodes/result_controller/blob/main/lib/src/ok_handler.dart"
    click Extensions "https://github.com/jhonacodes/result_controller/blob/main/lib/src/extension.dart"
    click Testing "https://github.com/jhonacodes/result_controller/blob/main/example/main.dart"

    classDef public fill:#ffcccc,stroke:#d62728,stroke-width:2px;
    classDef internal fill:#ccffcc,stroke:#2ca02c,stroke-width:2px;
    classDef core fill:#cce5ff,stroke:#1f77b4,stroke-width:2px;
    classDef testing fill:#ffffcc,stroke:#ff7f0e,stroke-width:2px;
```
