# elixir-maru/maru_params architecture

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

- Interactive diagram: https://gitdiagram.com/elixir-maru/maru_params
- Repository: https://github.com/elixir-maru/maru_params

## Overview

##### Main components
- Core Parser Module: Represent the central component (Maru.Params) that orchestrates how parameters are collected, parsed, transformed, and validated.
- Type System/Validators: Identify each “type” module (see lib/maru/params/types) such as Atom, Base64, Boolean, DateTime, etc. Group them under a “Type Handlers” or “Validators” component.
- Parameter Builder and Pipeline: Include modules that build and configure the parsing logic (e.g., builder modules, pipeline chaining using type operators like “Base64 |> Integer”).
- Controller Integration: Since the library supports the Phoenix framework, include an integration module (Maru.Params.PhoenixController) that acts as an adapter when used within Phoenix controllers.
- Exception Handling: Represent error management and exception modules (e.g., lib/maru/params/exceptions.ex) that dictate how the system reacts to invalid input.
- Configuration & Options: Note that the library also involves configuration (through config/config.exs and runtime options for types) which can be represented as a separate configuration component.

##### Relationships and Interactions
- Input Flow: Start with external requests coming into a Phoenix controller or direct API endpoint that uses this library.
- Processing Pipeline: Illustrate how the input data flows into the core parser, which then passes the data to the various type/validation modules.
- Error/Exception Flow: Show that if any type conversion or validation fails, control flows into the exception module, which either raises an error or returns a formatted error response.

##### Architectural Patterns & Design Principles
- Modularity: Emphasize the separation of concerns by having distinct modules for each type and for adapter functionality (Phoenix integration).
- Pipeline Processing: Note that the library supports chained operations on parameter types (using the pipeline notion: Json |> List[Integer] etc.) which is a key conceptual and diagrammatic element.
- Extensibility: Indicate that the architecture allows for extension via custom types and validators, as well as integration points (e.g., custom JSON libraries or ecto_enum validation).

##### Technologies and Dependencies
- Elixir (base language) and its mix project structure.
- Integration dependencies such as Phoenix, Plug, Jason, Decimal, and ecto.
- GitHub workflows (CI/CD) for testing and integration, represented optionally in a “DevOps/CI” bubble if needed.

##### Creating a Detailed Sketch
- From there, connect to a central “Maru.Params Core Engine” that manages parameter parsing.
- A side branch showing the “Pipeline Processing” where transformation sequences (Base64 → Integer, Json → List[Integer], etc.) are applied.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Web/API Request"]:::source
    B["Phoenix Controller Adapter (Maru.Params.PhoenixController)"]:::controller
    C["Maru.Params Core Engine"]:::core
    F["Type Handlers/Validators"]:::validators
    G["Exception Handling"]:::exception

    subgraph "Pipeline Processing"
        D["Parameter Builder"]:::pipeline
        E["Type Builder"]:::pipeline
    end

    subgraph "Configuration & Options"
        H1["Global Config"]:::config
        H2["Runtime Options"]:::config
    end

    %% Data Flow
    A -->|"data_flow"| B
    B -->|"data_flow"| C
    C -->|"invokes"| D
    D -->|"chains_to"| E
    E -->|"transformation"| F
    C -->|"calls"| F
    F -->|"error_propagation"| G
    H1 -->|"config_injection"| C
    H2 -->|"config_injection"| C

    %% Click Events
    click B "https://github.com/elixir-maru/maru_params/blob/main/lib/maru/params/phoenix_controller.ex"
    click C "https://github.com/elixir-maru/maru_params/blob/main/lib/maru/params.ex"
    click D "https://github.com/elixir-maru/maru_params/blob/main/lib/maru/params/builder.ex"
    click E "https://github.com/elixir-maru/maru_params/blob/main/lib/maru/params/type_builder.ex"
    click F "https://github.com/elixir-maru/maru_params/tree/main/lib/maru/params/types"
    click G "https://github.com/elixir-maru/maru_params/blob/main/lib/maru/params/exceptions.ex"
    click H1 "https://github.com/elixir-maru/maru_params/blob/main/config/config.exs"
    click H2 "https://github.com/elixir-maru/maru_params/blob/main/lib/maru/params/runtime.ex"

    %% Styles
    classDef source fill:#AED6F1,stroke:#5DADE2,stroke-width:2px;
    classDef controller fill:#F9E79F,stroke:#F4D03F,stroke-width:2px;
    classDef core fill:#D5F5E3,stroke:#58D68D,stroke-width:2px;
    classDef pipeline fill:#F5CBA7,stroke:#E67E22,stroke-width:2px;
    classDef validators fill:#D7BDE2,stroke:#AF7AC5,stroke-width:2px;
    classDef exception fill:#FADBD8,stroke:#E74C3C,stroke-width:2px;
    classDef config fill:#E8DAEF,stroke:#AF7AC5,stroke-width:2px;
```
