# kjczarne/baudelaire architecture

> Architecture diagram of the GitHub repository kjczarne/baudelaire, 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/kjczarne/baudelaire
- Repository: https://github.com/kjczarne/baudelaire

## Overview

Overview:
This project is a command-line tool designed to transform plaintext poetry into styled Instagram post images. The README and file structure show that it accepts a plaintext (or markdown) poem, processes it according to specific configuration parameters (from YAML and template files), and outputs a series of image files (namely, poem_part-*.png). It’s packaged as a Python module (with the baudelaire package and pyproject.toml for packaging), and it includes assets like fonts, configuration, and templates that contribute to the visual style of the generated posts.

##### Main Components
- Command-Line Interface (CLI) Entry Point:
- Represents the initial user invocation (i.e., the “baudelaire” command).
- Responsible for parsing command-line arguments (input text, output directory, optional config file).
- Core Processing Module (baudelaire package):
- Contains the primary logic to parse plain text (or markdown) poem input.
- Splits the poem appropriately (especially handling markdown code fences if present).
- Coordinates with other internal modules to apply the template and styling.
- Configuration Manager:
- Reads default configuration files from the config directory (e.g., default.yaml).
- Allows users to override settings by supplying an alternative configuration file.
- Assets Manager:
- Manages the visual elements including:
- Fonts (under the fonts directory, e.g., EB_Garamond).
- Templates (under the templates directory).
- Static assets like logos or images (in the static directory where both raw source files like logo.xcf are stored and the README references for rendered images).
- Output Handler:
- Takes processed content and generates image files.
- Writes the output files to a user-specified directory with filenames like poem_part-*.png.
- Testing/Validation:
- Indicated by the tests directory. It may be used to verify parsing correctness and image generation.

##### Relationships and Interactions
- Data Flow:
- User invokes the CLI with poem input and configuration options.
- CLI passes input to the Core Processing Module.
- The Core Module consults the Configuration Manager to set parameters (like line heights, board layout, etc.).
- It then integrates assets from the Assets Manager (fonts, templates, static images).
- Finally, the processed poem is rendered into images by the Output Handler.
- Dependency Flow:
- CLI depends on the Core Module.
- Core Module depends on configuration data and asset files.
- The Output Handler uses the rendering libraries (possibly PIL or similar) to generate images.

##### Architectural Patterns and Design Principles
- Modular Structure:
- The separation into distinct directories (baudelaire for core logic, config for configuration, fonts/templates/static for assets) reflects a modular design.
- Configuration-Driven Design:
- Uses externalized configuration (default.yaml) to allow customization without code changes.
- Separation of Concerns:
- Input parsing, configuration management, asset handling, and output rendering are managed in separate components.

##### Relevant Technologies/Frameworks
- Python (as indicated by pyproject.toml and package structure).
- YAML for configuration files.
- Likely imaging libraries to create PNG images.
- A templating system for processing the visual layout of the text (implicitly suggested by the templates, though not explicitly stated if using something like Jinja2).
- Standard libraries for CLI argument parsing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    UserInput["User Input"]:::input
    cli["CLI Interface"]:::cli
    core["Poetry Processor (Core)"]:::core
    config["Configuration Manager"]:::config

    subgraph "Assets Manager"
        fonts["Fonts"]:::assets
        templates["Templates"]:::assets
        static["Static Assets"]:::assets
    end

    output["Output Handler"]:::output
    generated["Generated Images"]:::output
    test["Testing/Validation"]:::test

    UserInput -->|"invokes"| cli
    cli -->|"calls"| core
    core -->|"loads"| config
    core -->|"fetches"| fonts
    core -->|"fetches"| templates
    core -->|"fetches"| static
    core -->|"generates"| output
    output -->|"writes"| generated
    test -->|"verifies"| core

    click cli "https://github.com/kjczarne/baudelaire/blob/main/baudelaire/__init__.py"
    click core "https://github.com/kjczarne/baudelaire/tree/main/baudelaire/"
    click config "https://github.com/kjczarne/baudelaire/blob/main/config/default.yaml"
    click fonts "https://github.com/kjczarne/baudelaire/tree/main/fonts/EB_Garamond/"
    click templates "https://github.com/kjczarne/baudelaire/tree/main/templates/"
    click static "https://github.com/kjczarne/baudelaire/tree/main/static/"
    click test "https://github.com/kjczarne/baudelaire/tree/main/tests/"

    classDef input fill:#f3f315,stroke:#333,stroke-width:2px;
    classDef cli fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef core fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef config fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef assets fill:#ffddcc,stroke:#333,stroke-width:2px;
    classDef output fill:#d1e8ff,stroke:#333,stroke-width:2px;
    classDef test fill:#ffb3b3,stroke:#333,stroke-width:2px;
```
