# andrewbrey/mdrb architecture

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

- Interactive diagram: https://gitdiagram.com/andrewbrey/mdrb
- Repository: https://github.com/andrewbrey/mdrb

## Overview

##### Main Components

a. Input Sources Layer:
- Local Markdown Files
- Remote Markdown URLs
- Stdin Pipe

b. Core Processing Layer:
- Markdown Parser
- Code Block Extractor
- Configuration Parser (TOML)
- Code Block Processor

c. Execution Layer:
- Deno Runtime Environment
- Dax Integration
- Execution Modes Manager

d. Output/Interface Layer:
- Terminal Interface
- Progress/Status Display
- Interactive Prompts

##### Component Relationships and Data Flow

- Input → Parser → Processor → Executor → Output
- Configuration flow from TOML parser to execution settings
- Dax integration path into code blocks
- Mode selection impact on execution flow

**┌─────────────────────────────────────────────────────────┐**
- Input Sources                       │
- ┌─────────────┐   ┌──────────────┐   ┌─────────────┐  │
- Local MD Files│   │Remote MD URLs│   │Stdin Pipe   │  │
- ┬──────┘   └──────┬───────┘   └─────┬───────┘  │
- ┼───────────────┬─┼───────────────┬─┼──────────┘

**┌─────────▼───────────────▼─▼───────────────▼─▼──────────┐**
- Core Processing                      │
- ┌─────────────┐   ┌──────────────┐   ┌─────────────┐  │
- Markdown     │   │Code Block    │   │Config       │  │
- Parser       ├──►│Extractor    │◄──┤Parser(TOML) │  │
- ┘   └──────┬───────┘   └─────────────┘  │
- ┬──┼────────────────────────────┘

**┌────────────────────────▼──▼────────────────────────────┐**
- Execution Layer                       │
- ┌─────────────┐   ┌──────────────┐   ┌─────────────┐  │
- Deno Runtime │◄──┤Mode Manager  │◄──┤Dax          │  │
- Environment  │   │(Runbook/     │   │Integration  │  │
- ┬──────┘   │Isolated/     │   └─────────────┘  │
- Single)       │                     │
- ┬───────┘                     │
- ┼───────────────┬┼─────────────────────────────┘

**┌─────────▼───────────────▼▼────────────────────────────┐**
- Output Interface                      │
- ┌─────────────┐   ┌──────────────┐   ┌─────────────┐  │
- Terminal     │   │Progress      │   │Interactive  │  │
- Output      │◄──┤Display       │◄──┤Prompts     │  │
- ┘   └──────────────┘   └─────────────┘  │
- ┘

##### Implementation Notes

- cli.ts as the entry point
- markdown.ts for parsing
- util.ts for helper functions
- Integration with external dependencies

This system design accurately represents MDRB as a CLI tool that transforms Markdown documentation into executable runbooks, with clear separation of concerns between input handling, processing, execution, and output management.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style definitions
    classDef input fill:#e1f5fe,stroke:#01579b
    classDef process fill:#e8f5e9,stroke:#1b5e20
    classDef execution fill:#fff3e0,stroke:#e65100
    classDef output fill:#e3f2fd,stroke:#0d47a1
    
    subgraph Input
        LocalMD["Local MD Files"]:::input
        RemoteURL["Remote MD URLs"]:::input
        StdinPipe["Stdin Pipe"]:::input
    end

    subgraph CoreProcessing
        MarkdownParser["Markdown Parser"]:::process
        CodeBlockExtractor["Code Block Extractor"]:::process
        ConfigParser["Configuration Parser (TOML)"]:::process
    end

    subgraph Execution
        DenoRuntime["Deno Runtime Environment"]:::execution
        DaxIntegration["Dax Integration"]:::execution
        ModeManager["Mode Manager<br/>(Runbook/Isolated/Single)"]:::execution
    end

    subgraph Output
        TerminalInterface["Terminal Interface"]:::output
        ProgressDisplay["Progress Display"]:::output
        InteractivePrompts["Interactive Prompts"]:::output
    end

    %% Connections
    LocalMD --> MarkdownParser
    RemoteURL --> MarkdownParser
    StdinPipe --> MarkdownParser
    
    MarkdownParser --> CodeBlockExtractor
    ConfigParser --> CodeBlockExtractor
    
    CodeBlockExtractor --> ModeManager
    DaxIntegration --> ModeManager
    ModeManager --> DenoRuntime
    
    DenoRuntime --> ProgressDisplay
    ProgressDisplay --> TerminalInterface
    InteractivePrompts --> TerminalInterface

    %% Click events for component mapping
    click TerminalInterface "https://github.com/andrewbrey/mdrb/blob/main/src/cli.ts"
    click MarkdownParser "https://github.com/andrewbrey/mdrb/blob/main/src/markdown.ts"
    click CodeBlockExtractor "https://github.com/andrewbrey/mdrb/blob/main/src/markdown.ts"
    click DenoRuntime "https://github.com/andrewbrey/mdrb/blob/main/src/util.ts"
    click DaxIntegration "https://github.com/andrewbrey/mdrb/blob/main/src/deps.ts"
    click LocalMD "https://github.com/andrewbrey/mdrb/blob/main/demo.md"
    click RemoteURL "https://github.com/andrewbrey/mdrb/tree/main/.github/demos/usage-remote/"
    click StdinPipe "https://github.com/andrewbrey/mdrb/tree/main/.github/demos/usage-remote-pipe/"
    click ConfigParser "https://github.com/andrewbrey/mdrb/blob/main/deno.jsonc"

    %% Legend
    classDef legend fill:#f5f5f5,stroke:#333
    subgraph Legend
        Input_["Input Components"]:::input
        Process_["Processing Components"]:::process
        Execution_["Execution Components"]:::execution
        Output_["Output Components"]:::output
    end
```
