# sleepymincy/mommy architecture

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

- Interactive diagram: https://gitdiagram.com/sleepymincy/mommy
- Repository: https://github.com/sleepymincy/mommy

## Overview

##### Project type and purpose
- This is a small Rust‐based CLI tool (“mommy”) whose sole purpose is to print randomized affirmations (or gentle chastisements) in your terminal after each command.

##### File structure
- Top level:
- Cargo.toml / Cargo.lock: Rust project manifest & dependencies.
- src/: main source code broken into modules:
– main.rs: entry point, orchestrates execution.
– config.rs: reading & parsing environment variables into app config.
– affirmations.rs: loading JSON, selecting messages.
– mommy.rs: core business logic (tie config + affirmations together).
– utils.rs: misc helpers.
- assets/affirmations.json: default affirmations data file.
- .github/workflows/rust.yml: CI build workflow.
- README.md: user & developer documentation.

##### Key components
a. CLI Interface (main.rs)
– Reads CLI args (exit code or command).
– Invokes the core logic.

b. Configuration Layer (config.rs)
– Reads environment variables (SHELL_MOMMYS_*).
– Builds a Config struct.

c. Asset Loader (affirmations.rs)
– If SHELL_MOMMYS_AFFIRMATIONS set, load JSON from path.
– Otherwise fall back to embedded JSON (assets/affirmations.json).
– Parses into Affirmation objects.

d. Core Logic (mommy.rs)
– Receives Config + Affirmations + exit code.
– Chooses positive or negative message based on exit code and flags.

– Wraps the chosen affirmation text.

f. Utilities (utils.rs)
– Helper functions (random selection, parsing RGB, splitting options).

g. Output (stdout)
– Terminal prints the styled affirmation.

##### Relationships and data flow
- main.rs → config.rs (load config)
- main.rs → affirmations.rs (load messages)
- main.rs → mommy.rs (pass config + data + exit code)
- mommy.rs → utils.rs (random pick, parsing)
- mommy.rs → stdout

##### Architectural patterns & principles
- Modular decomposition: each Rust module has a single responsibility.
- Dependency injection: main.rs injects env/config and data into core logic.
- Data flow is linear and functional—no global mutable state.

##### Technologies & frameworks
- Rust Cargo build system.
- serde_json for JSON parsing.
- rand crate (or std) for randomness.
- ANSI terminal styling.

##### Essential details to capture
- Explicit environment‐variable→Config mapping.
- Fallback logic: embedded JSON vs custom file.
- Conditional branching: positive vs negative response.
- ANSI styling pipeline after message selection.
- Integration points: user’s rc file hooking into prompt.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Modules and components
    CLI["CLI Interface\n(main.rs)"]:::cli
    subgraph "Input Layers"
        config["Configuration Layer\n(config.rs)"]:::config
        asset_loader["Asset Loader\n(affirmations.rs)"]:::config
        data["affirmations.json"]:::data
    end
    core["Core Logic\n(mommy.rs)"]:::logic
    styling["Styling Module\n(color.rs)"]:::styling
    utils["Utilities\n(utils.rs)"]:::utils
    stdout["Terminal stdout"]:::stdout
    subgraph "Project Metadata"
        manifest["Cargo.toml"]:::manifest
        doc["README.md"]:::doc
        CI["CI Workflow\n(rust.yml)"]:::ci
    end

    %% Data flows
    CLI -->|"load config"| config
    CLI -->|"load messages"| asset_loader
    asset_loader -->|"uses JSON"| data
    CLI -->|"invoke core"| core
    config --> core
    asset_loader --> core
    core -->|"random & parsing"| utils
    core -->|"apply style"| styling
    core -->|"select message"| styling
    styling -->|"print"| stdout

    %% Optional override dashed
    config -.->|override JSON| asset_loader

    %% Click events
    click CLI "https://github.com/sleepymincy/mommy/blob/master/src/main.rs"
    click config "https://github.com/sleepymincy/mommy/blob/master/src/config.rs"
    click asset_loader "https://github.com/sleepymincy/mommy/blob/master/src/affirmations.rs"
    click data "https://github.com/sleepymincy/mommy/blob/master/assets/affirmations.json"
    click core "https://github.com/sleepymincy/mommy/blob/master/src/mommy.rs"
    click styling "https://github.com/sleepymincy/mommy/blob/master/src/color.rs"
    click utils "https://github.com/sleepymincy/mommy/blob/master/src/utils.rs"
    click CI "https://github.com/sleepymincy/mommy/blob/master/.github/workflows/rust.yml"
    click manifest "https://github.com/sleepymincy/mommy/blob/master/Cargo.toml"
    click doc "https://github.com/sleepymincy/mommy/blob/master/README.md"

    %% Styles
    classDef cli fill:#FFD966,stroke:#333,stroke-width:1px,shape:parallelogram
    classDef config fill:#6FA8DC,stroke:#333,stroke-width:1px
    classDef data fill:#6FA8DC,stroke:#333,stroke-width:1px,shape:cylinder
    classDef logic fill:#93C47D,stroke:#333,stroke-width:1px
    classDef styling fill:#F9CB9C,stroke:#333,stroke-width:1px
    classDef utils fill:#D9D9D9,stroke:#333,stroke-width:1px
    classDef stdout fill:#FFD966,stroke:#333,stroke-width:1px,shape:parallelogram
    classDef ci fill:#D9D9D9,stroke:#333,stroke-width:1px
    classDef manifest fill:#D9D9D9,stroke:#333,stroke-width:1px
    classDef doc fill:#D9D9D9,stroke:#333,stroke-width:1px
```
