# mandava/pagebrew architecture

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

- Interactive diagram: https://gitdiagram.com/mandava/pagebrew
- Repository: https://github.com/mandava/pagebrew

## Overview

##### And outline the main components
- CLI/Command Interface – Representing the entry point that accepts user commands (e.g., “npx pagebrew serve/build/preview”). Use the bin/cli.js file as the CLI’s code base.
- Static Site Generator Core – This comprises several sub-components:
– Markdown Parser (src/markdown.js): Handles converting Markdown content to HTML.
– Generator (src/generator.js): Orchestrates the process of scanning input directories (like examples and user-provided markdown files), invoking the markdown parser, and calling the templating engine.
– Server (src/server.js): Provides local server functionality for live previewing.
– Theme Files (under src/themes/aurora, src/themes/frappe, src/themes/minimal): Each theme has its own EJS templates, CSS files (often with Tailwind pre-configurations), and partials (header.ejs, footer.ejs, etc.).
– Configuration Files (e.g., src/pagebrew.config.json and pagebrew.config.json present in examples): These determine rules for the site such as theme selection, output directory, and menu items.
- File System / Content Repository – Represent how markdown files (like index.md, about.md, and content within blog directories) are read from the project’s file tree. Component boundaries should also include the examples directory which provides demos.
- Build/Output Process – This involves writing the generated files to an output directory (as specified in the config, by default "dist").

##### Out interactions and data flow
- The Generator then reads the Markdown files from the file system, feeding them through the Markdown Parser.
- Output from parsing the Markdown is passed into the Templating Engine, which uses EJS templates – these templates are chosen based on the theme configuration.
- Tailwind CSS plays a role in styling the resulting HTML. Denote that Tailwind is integrated into the theme assets.
- Finally, the rendered HTML files are written to the output directory.
- For local previewing, the Server component serves the generated static site, allowing the user to see the site in a browser.

##### Architectural patterns and technologies
- Modular Design – Clearly separate responsibilities between CLI, file parsing, templating, and serving.
- Configuration-Driven Customization – The system depends on configuration files (pagebrew.config.json, theme-specific configs) to control behavior.
- Template-based Rendering – Use of EJS templates facilitates layout reuse and theme swapping.
- Integration with Tailwind CSS – Shows the styling aspect managed via dedicated configuration files (e.g., tailwind.config.js in multiple theme directories).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        CLI["CLI/Command Interface"]:::cli
    end

    %% Static Site Generator Core
    subgraph "Static Site Generator Core"
        GEN["Generator Core"]:::core
        MD["Markdown Parser"]:::core
        SV["Server (Live Preview)"]:::server
    end

    %% Templating & Theming Engine
    subgraph "Templating & Theming Engine"
        TEMPL["Templating Engine"]:::templating
        TW["Tailwind CSS Integration"]:::css
        subgraph "Themes"
            AUR["Aurora Theme"]:::theme
            FRA["Frappe Theme"]:::theme
            MIN["Minimal Theme"]:::theme
        end
    end

    %% Configuration & Content
    subgraph "Configuration and Content"
        CONF["Core Configuration Files"]:::config
        EXCONF["Example Project Configurations"]:::config
        FS["Content Repository (Markdown/Examples)"]:::storage
    end

    %% Output Directory
    DIST["Output Directory (dist)"]:::storage

    %% Data Flow Connections
    CLI -->|"triggers"| GEN
    FS -->|"providesMarkdown"| GEN
    CONF -->|"drivesConfig"| GEN
    EXCONF -->|"drivesConfig"| GEN

    GEN -->|"invokes"| MD
    MD -->|"returnsHTML"| GEN

    GEN -->|"rendersUsing"| TEMPL
    CONF -->|"selectsTheme"| TEMPL
    EXCONF -->|"selectsTheme"| TEMPL

    TW -->|"styles"| TEMPL

    TEMPL -->|"outputsTo"| DIST
    GEN -->|"servesPreviewVia"| SV

    %% Click Events
    click CLI "https://github.com/mandava/pagebrew/blob/main/bin/cli.js"
    click MD "https://github.com/mandava/pagebrew/blob/main/src/markdown.js"
    click GEN "https://github.com/mandava/pagebrew/blob/main/src/generator.js"
    click SV "https://github.com/mandava/pagebrew/blob/main/src/server.js"
    click AUR "https://github.com/mandava/pagebrew/tree/main/src/themes/aurora"
    click FRA "https://github.com/mandava/pagebrew/tree/main/src/themes/frappe"
    click MIN "https://github.com/mandava/pagebrew/tree/main/src/themes/minimal"
    click CONF "https://github.com/mandava/pagebrew/blob/main/src/pagebrew.config.json"
    click EXCONF "https://github.com/mandava/pagebrew/blob/main/examples/aurora-demo/pagebrew.config.json"
    click FS "https://github.com/mandava/pagebrew/tree/main/examples"

    %% Styles
    classDef cli fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef core fill:#8ecae6,stroke:#023047,stroke-width:2px;
    classDef templating fill:#caf0f8,stroke:#023047,stroke-width:2px;
    classDef theme fill:#a2d2ff,stroke:#023047,stroke-width:2px;
    classDef config fill:#f7d6e0,stroke:#b5179e,stroke-width:2px;
    classDef storage fill:#bde0fe,stroke:#03045e,stroke-width:2px;
    classDef server fill:#ffb703,stroke:#fb8500,stroke-width:2px;
    classDef css fill:#ffd6a5,stroke:#e85d04,stroke-width:2px;
```
