# rails/jsbundling-rails architecture

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

- Interactive diagram: https://gitdiagram.com/rails/jsbundling-rails
- Repository: https://github.com/rails/jsbundling-rails

## Overview

##### Main Components Identification

a) Input Layer:
- JavaScript source files (app/javascript/*)
- Package management (npm/yarn/pnpm/bun)
- Configuration files (bun.config.js, rollup.config.js, webpack.config.js)

b) Processing Layer:
- Bundler Options (Bun, esbuild, rollup.js, Webpack)
- Build Process
- Watch Mode System

c) Output Layer:
- Asset Pipeline Integration
- Built Assets Location (app/assets/builds)
- Public Assets (public/assets)

##### Workflow and Integration Points

a) Development Flow:
- Watch mode process
- Build trigger points
- Development server integration

b) Production Flow:
- Assets:precompile integration
- Production build process
- Final asset serving

c) Testing Flow:
- Integration with test:prepare
- Test suite build process

##### Key Relationships to Highlight

- How the gem integrates with Rails' asset pipeline
- Relationship between package.json scripts and the build process
- Demonstrate how different bundlers plug into the system
- Watch mode feedback loop

##### Important Notes

Specific details:
- Entry point convention (app/javascript/application.js)
- Output convention (app/assets/builds/application.js)
- Rake task integration points
- Asset pipeline delivery mechanism

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        style Legend fill:#f5f5f5,stroke:#333
        L1[Input Files]:::input
        L2[Processing Components]:::process
        L3[Output Files]:::output
        L4[Configuration]:::config
    end

    subgraph "Input Layer"
        JS[["JavaScript Source Files<br/>(app/javascript/*)"]]:::input
        PM["Package Management"]:::input
        click PM "https://github.com/rails/jsbundling-rails/blob/main/lib/install/package.json"
        
        subgraph "Bundler Configs"
            BC_BUN["Bun Config"]:::config
            BC_WP["Webpack Config"]:::config
            BC_RP["Rollup Config"]:::config
            click BC_BUN "https://github.com/rails/jsbundling-rails/blob/main/lib/install/bun/bun.config.js"
            click BC_WP "https://github.com/rails/jsbundling-rails/blob/main/lib/install/webpack/webpack.config.js"
            click BC_RP "https://github.com/rails/jsbundling-rails/blob/main/lib/install/rollup/rollup.config.js"
        end
    end

    subgraph "Processing Layer"
        subgraph "Bundler Options"
            BO_BUN["Bun"]:::process
            BO_ESB["esbuild"]:::process
            BO_RP["rollup.js"]:::process
            BO_WP["Webpack"]:::process
            click BO_BUN "https://github.com/rails/jsbundling-rails/blob/main/lib/install/bun/install.rb"
            click BO_ESB "https://github.com/rails/jsbundling-rails/blob/main/lib/install/esbuild/install.rb"
            click BO_RP "https://github.com/rails/jsbundling-rails/blob/main/lib/install/rollup/install.rb"
            click BO_WP "https://github.com/rails/jsbundling-rails/blob/main/lib/install/webpack/install.rb"
        end

        BP["Build Process"]:::process
        WM["Watch Mode System"]:::process
        IS["Installation System"]:::process
        click BP "https://github.com/rails/jsbundling-rails/blob/main/lib/tasks/jsbundling/build.rake"
        click IS "https://github.com/rails/jsbundling-rails/blob/main/lib/install/install.rb"
        click WM "https://github.com/rails/jsbundling-rails/blob/main/lib/install/Procfile.dev"
    end

    subgraph "Output Layer"
        API["Asset Pipeline Integration"]:::output
        BAL["Built Assets Location<br/>(app/assets/builds)"]:::output
        PA["Public Assets<br/>(public/assets)"]:::output
        click API "https://github.com/rails/jsbundling-rails/blob/main/lib/jsbundling/engine.rb"
    end

    subgraph "Documentation"
        WM_DOC["Webpacker Migration Guide"]:::doc
        WC_DOC["Webpacker Comparison"]:::doc
        click WM_DOC "https://github.com/rails/jsbundling-rails/blob/main/docs/switch_from_webpacker.md"
        click WC_DOC "https://github.com/rails/jsbundling-rails/blob/main/docs/comparison_with_webpacker.md"
    end

    JS --> BP
    PM --> BP
    BC_BUN --> BO_BUN
    BC_WP --> BO_WP
    BC_RP --> BO_RP

    BO_BUN --> BP
    BO_ESB --> BP
    BO_RP --> BP
    BO_WP --> BP

    BP --> BAL
    BAL --> API
    API --> PA

    WM --> BP
    IS --> BP

    classDef input fill:#e1f5fe,stroke:#01579b
    classDef process fill:#e8f5e9,stroke:#1b5e20
    classDef output fill:#fff3e0,stroke:#e65100
    classDef config fill:#f5f5f5,stroke:#424242
    classDef doc fill:#f3e5f5,stroke:#4a148c
```
