# monopole/mdrip architecture

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

- Interactive diagram: https://gitdiagram.com/monopole/mdrip
- Repository: https://github.com/monopole/mdrip

## Overview

##### Main Components Identification

a) Core Components:
- Markdown Processing Engine (internal/parsren)
- File Loading System (internal/loader)
- Web Server (internal/web)
- Command Line Interface (internal/commands)
- TMux Integration (internal/tmux)

b) Web Application Components:
- Widget System (internal/web/app/widget)
- Server Handlers (internal/web/server)
- Configuration (internal/web/config)

**[Browser] ←→ [Web Server Layer]**
- ↓
**[Core Processing Layer (Markdown Parser, Loader)]**
- ↓
**[Command Layer]**
- ↓
**[External Systems (TMux, File System)]**

##### Component Relationships

Key interactions:
- Web server receiving requests from browsers
- Markdown processor parsing content
- File loader accessing local/remote content
- TMux integration for code block execution
- Command processing flow

##### Detailed Component Breakdown

Web Layer:
**[Web Server] → [Widgets]**
- ↓
**[App State] ← [Widget Components]**

Core Layer:
**[Markdown Parser] → [Code Block Processor]**
- ↓
**[File Loader] → [GitHub Loader]**

##### Specific elements

a) Entry Points:
- HTTP endpoints (port 8000)
- CLI commands (print, serve, test, etc.)

b) Data Flow:
- Markdown content flow
- Code block execution path
- TMux communication

##### Technical Details

- Go-based implementation
- Markdown parsing capabilities
- TMux integration
- GitHub integration
- Web server functionality

##### Notes

- Keep the abstraction level focused on major components while showing key interactions
- Markdown processing and code execution flow
- Clear separation between web and CLI functionalities
- Testing capabilities

This design will help developers understand both the high-level architecture and the specific component interactions that enable mdrip's core functionalities of markdown rendering, code block execution, and testing capabilities.

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Systems
    Browser[Browser]:::external
    TMux[TMux]:::external
    FileSystem[(File System)]:::storage
    GitHub[(GitHub)]:::storage

    %% Web Layer
    subgraph WebLayer[Web Application Layer]
        WebServer["Web Server<br/>(Port 8000)"]
        Handlers["Server Handlers"]
        WebApp["Web Application"]
        
        subgraph WidgetSystem[Widget System]
            Widgets["Widget Components"]
            CodeBlock["Code Block Widget"]
            AppState["Application State"]
        end
        
        Config["Configuration"]
    end

    %% Core Layer
    subgraph CoreLayer[Core Processing Layer]
        MarkdownParser["Markdown Processing<br/>Engine"]
        FileLoader["File Loading<br/>System"]
        GitHubLoader["GitHub<br/>Integration"]
    end

    %% Command Layer
    subgraph CommandLayer[Command Layer]
        CLI["Command Line<br/>Interface"]
        TMuxIntegration["TMux<br/>Integration"]
    end

    %% Relationships
    Browser --> WebServer
    WebServer --> Handlers
    Handlers --> WebApp
    WebApp --> Widgets
    Widgets --> CodeBlock
    Widgets --> AppState
    WebServer --> Config

    WebApp --> MarkdownParser
    MarkdownParser --> FileLoader
    FileLoader --> FileSystem
    FileLoader --> GitHubLoader
    GitHubLoader --> GitHub

    CLI --> MarkdownParser
    CLI --> TMuxIntegration
    TMuxIntegration --> TMux
    
    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:2px
    classDef storage fill:#f96,stroke:#333,stroke-width:2px
    classDef core fill:#9cf,stroke:#333,stroke-width:2px
    classDef web fill:#9f9,stroke:#333,stroke-width:2px

    %% Click Events
    click MarkdownParser "https://github.com/monopole/mdrip/blob/master/internal/parsren/mdparserrenderer.go"
    click FileLoader "https://github.com/monopole/mdrip/tree/master/internal/loader/"
    click WebServer "https://github.com/monopole/mdrip/blob/master/internal/web/server/webserver.go"
    click CLI "https://github.com/monopole/mdrip/tree/master/internal/commands/"
    click TMuxIntegration "https://github.com/monopole/mdrip/blob/master/internal/tmux/tmux.go"
    click Widgets "https://github.com/monopole/mdrip/tree/master/internal/web/app/widget/"
    click Handlers "https://github.com/monopole/mdrip/blob/master/internal/web/server/handlers.go"
    click Config "https://github.com/monopole/mdrip/blob/master/internal/web/config/config.go"
    click GitHubLoader "https://github.com/monopole/mdrip/blob/master/internal/loader/github.go"
    click WebApp "https://github.com/monopole/mdrip/blob/master/internal/web/app/webapp.go"
    click CodeBlock "https://github.com/monopole/mdrip/tree/master/internal/web/app/widget/codeblock/"
    click AppState "https://github.com/monopole/mdrip/blob/master/internal/web/app/widget/appstate/appstate.go"
```
