# bcomnes/top-bun architecture

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

- Interactive diagram: https://gitdiagram.com/bcomnes/top-bun
- Repository: https://github.com/bcomnes/top-bun

## Overview

##### Main Components

a. Core Build Pipeline
- Source Directory Handler
- Page Builders (MD, HTML, JS)
- Layout System
- Asset Bundler (esbuild)
- Static Asset Copier
- Output Directory Generator

b. Supporting Systems
- Template Engine
- Variable Management
- Watch System
- Development Server

##### Component Relationships

**Source Directory → Build Pipeline → Output Directory**
- ↑                   ↑               ↓
- Watchers          Build Systems    Dev Server

##### Detailed Component Breakdown

a. Source Directory Handler
- Input detection for different file types
- Parallel processing paths for different content types

- Markdown Processing Pipeline
- HTML Processing Pipeline
- JavaScript Page Pipeline
- How they converge into the layout system

c. Layout System
- Layout Resolution
- Variable Injection
- Template Processing
- Nested layout capability

d. Asset Processing
- esbuild Bundle Processing
- Static Asset Copying
- Parallel processing

##### Key Elements to Highlight

a. File Processing Flows:
**.md files → Markdown Processor → Layout System**
**.html files → HTML Processor → Layout System**
**.js files → JS Processor → Layout System**
**.css files → esbuild → CSS Bundles**
**Static files → Direct Copy → Output**

b. Variable System:
**global.vars.js → Variable Merger ← page.vars.js**
- ↓                ↓
- Templates ← Variable Resolver → Layouts

##### Implementation Details

- esbuild integration for JS/CSS bundling
- markdown-it for MD processing
- cpx2 for static file copying
- Handlebars template processing
- Browser sync dev server

**┌─ Input ─┐    ┌─ Processing ─┐    ┌─ Output ─┐**
- Source  │ → │ Build Pipeline│ → │  Public  │
- Tree   │    │    Systems   │    │   Dir   │
- ┬────┘    └──────┬───────┘    └────┬────┘

- Watch System & Dev Server ────┘

##### Additional Notes

- Version information and key dependencies
- Error handling flows
- Configuration points
- Extension/plugin capabilities

- The complete build pipeline
- How different file types are processed
- Where and how variables are injected
- How layouts and templates interact
- The parallel processing capabilities
- Development workflow integration

- Convention over configuration
- HTML as source of truth
- Library agnostic approach
- Pages as shallow apps
- Standardized entry points
- Colocated assets

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        SRC[Source Directory]
        MD[".md files"]
        HTML[".html files"]
        JS[".js files"]
        CSS[".css files"]
        STATIC["Static files"]
        VARS["global.vars.js"]
        PVARS["page.vars.js"]
    end

    subgraph "Build Pipeline"
        direction TB
        IDENTIFY["Page Identification"]:::core
        
        subgraph "Page Builders"
            direction TB
            MDB["Markdown Builder"]:::builder
            HB["HTML Builder"]:::builder
            JSB["JavaScript Builder"]:::builder
        end
        
        subgraph "Core Systems"
            direction TB
            LAYOUT["Layout Resolver"]:::core
            TEMPLATE["Template Builder"]:::core
            VARS_RESOLVE["Variable Resolver"]:::core
            WRITER["Page Writer"]:::core
        end
        
        subgraph "Asset Processing"
            direction TB
            ESBUILD["Asset Bundler (esbuild)"]:::asset
            COPY["Static Asset Copier"]:::asset
        end
    end

    subgraph Output
        PUBLIC["Public Directory"]
        SERVER["Development Server"]
    end

    %% Connections
    SRC --> IDENTIFY
    MD --> MDB
    HTML --> HB
    JS --> JSB
    CSS --> ESBUILD
    STATIC --> COPY

    MDB & HB & JSB --> LAYOUT
    LAYOUT --> TEMPLATE
    VARS & PVARS --> VARS_RESOLVE
    VARS_RESOLVE --> TEMPLATE
    TEMPLATE --> WRITER
    WRITER --> PUBLIC
    ESBUILD --> PUBLIC
    COPY --> PUBLIC
    PUBLIC --> SERVER
    SERVER -.-> SRC

    %% Click Events
    click MDB "https://github.com/bcomnes/top-bun/blob/master/lib/build-pages/page-builders/md/index.js"
    click HB "https://github.com/bcomnes/top-bun/blob/master/lib/build-pages/page-builders/html/index.js"
    click JSB "https://github.com/bcomnes/top-bun/blob/master/lib/build-pages/page-builders/js/index.js"
    click ESBUILD "https://github.com/bcomnes/top-bun/blob/master/lib/build-esbuild/index.js"
    click COPY "https://github.com/bcomnes/top-bun/blob/master/lib/build-static/index.js"
    click LAYOUT "https://github.com/bcomnes/top-bun/blob/master/lib/build-pages/resolve-layout.js"
    click VARS_RESOLVE "https://github.com/bcomnes/top-bun/blob/master/lib/build-pages/resolve-vars.js"
    click IDENTIFY "https://github.com/bcomnes/top-bun/blob/master/lib/identify-pages.js"
    click WRITER "https://github.com/bcomnes/top-bun/blob/master/lib/build-pages/page-builders/page-writer.js"
    click TEMPLATE "https://github.com/bcomnes/top-bun/blob/master/lib/build-pages/page-builders/template-builder.js"

    %% Styles
    classDef builder fill:#f9f,stroke:#333,stroke-width:2px
    classDef core fill:#9cf,stroke:#333,stroke-width:2px
    classDef asset fill:#ff9,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        direction TB
        L1["Page Builders"]:::builder
        L2["Core Systems"]:::core
        L3["Asset Processing"]:::asset
    end
```
