# charmbracelet/pop architecture

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

- Interactive diagram: https://gitdiagram.com/charmbracelet/pop
- Repository: https://github.com/charmbracelet/pop

## Overview

##### Main Components Identification
The system has two primary interfaces:
- Text-based User Interface (TUI)
- Command Line Interface (CLI)

And two email delivery methods:
- Resend API Integration
- SMTP Integration

##### Key Architectural Elements
From the file structure, we can identify these core components:
- Main application logic (main.go)
- Email handling (email.go)
- Attachment management (attachments.go)
- UI model and state management (model.go)
- Styling and theming (style.go)
- Keyboard mapping (keymap.go)

##### Connection Flows

- User input flow from interfaces to core logic
- Email processing flow from core to delivery methods
- Configuration flow from environment variables to respective services

##### Additional Elements
- Environment variable configurations
- External tool integration points (mods, gum, invoice)
- File handling for attachments
- Markdown processing capability

##### Specific Implementation Details
- Support for multiple email delivery methods
- Configuration options through environment variables
- Integration points with other Charm tools
- Error handling flows

Key Technical Considerations:
- Go-based implementation
- Terminal-first design
- External service dependencies
- Environment-based configuration
- File system interactions for attachments
- Integration capabilities with other CLI tools

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef email fill:#f1c40f,stroke:#f39c12,color:black
    classDef delivery fill:#e74c3c,stroke:#c0392b,color:white
    classDef config fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef examples fill:#9b59b6,stroke:#8e44ad,color:white

    %% User Interface Layer
    TUI[Terminal UI]:::ui
    CLI[Command Line Interface]:::ui

    %% Core Application Layer
    MainApp[Main Application Logic]:::core
    Model[Model & State Management]:::core
    Style[UI Styling & Theming]:::core
    KeyMap[Keyboard Mapping]:::core

    %% Email Processing Layer
    EmailProc[Email Processing]:::email
    Attachments[Attachment Management]:::email
    MarkdownProc[Markdown Processing]:::email

    %% Delivery Layer
    ResendAPI[Resend API]:::delivery
    SMTP[SMTP Service]:::delivery

    %% Configuration
    Config[Environment Configuration]:::config

    %% Examples & Integration
    subgraph Examples
        MDExample[Markdown Templates]:::examples
        CLIExample[CLI Integration]:::examples
        ToolExample[Tool Integration]:::examples
        ContactExample[Contact Management]:::examples
    end

    %% Relationships
    TUI --> MainApp
    CLI --> MainApp
    MainApp --> Model
    MainApp --> Style
    MainApp --> KeyMap
    MainApp --> EmailProc
    EmailProc --> Attachments
    EmailProc --> MarkdownProc
    EmailProc --> ResendAPI
    EmailProc --> SMTP
    Config --> ResendAPI
    Config --> SMTP
    Model --> EmailProc

    %% Click Events
    click MainApp "https://github.com/charmbracelet/pop/blob/main/main.go"
    click Model "https://github.com/charmbracelet/pop/blob/main/model.go"
    click Style "https://github.com/charmbracelet/pop/blob/main/style.go"
    click KeyMap "https://github.com/charmbracelet/pop/blob/main/keymap.go"
    click EmailProc "https://github.com/charmbracelet/pop/blob/main/email.go"
    click Attachments "https://github.com/charmbracelet/pop/blob/main/attachments.go"
    click MDExample "https://github.com/charmbracelet/pop/blob/main/examples/message.md"
    click CLIExample "https://github.com/charmbracelet/pop/blob/main/examples/cli.tape"
    click ToolExample "https://github.com/charmbracelet/pop/tree/main/examples/"
    click ContactExample "https://github.com/charmbracelet/pop/blob/main/examples/contacts.txt"

    %% Legend
    subgraph Legend
        UI[User Interface]:::ui
        Core[Core Components]:::core
        EmailComp[Email Components]:::email
        DeliveryComp[Delivery Services]:::delivery
        ConfigComp[Configuration]:::config
        ExampleComp[Examples]:::examples
    end
```
