# brioche-dev/brioche architecture

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

- Interactive diagram: https://gitdiagram.com/brioche-dev/brioche
- Repository: https://github.com/brioche-dev/brioche

## Overview

Main Components to Include:

##### Core Engine (brioche-core)
- Subcomponents:
- Bake System (handles build processes)
- Script Engine (TypeScript runtime)
- Sandbox System (for isolated builds)
- Project Manager
- Registry Client
- Blob Storage

##### CLI Interface (brioche crate)
- Commands like build, check, format, install, publish

##### Runtime Environment
- TypeScript Runtime
- Node.js Compatibility Layer
- LSP Support

##### External Integrations
- Registry Service
- Cache Storage
- Container Systems
- Build Environments

##### Connection types
- Double lines: Data flow

Layout Structure:

**┌─────────────────────────────────────────────┐**
- CLI Layer                  │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- Core Engine Layer              │
- ┬─────────────┬────────────────┤
- Bake       │  Script     │  Project       │
- System     │  Engine     │  Manager       │
- ┼─────────────┼────────────────┤
- Sandbox    │  Registry   │  Blob          │
- System     │  Client     │  Storage       │
- ┴─────────────┴────────────────┘
- ↕
**┌─────────────────────────────────────────────┐**
- Runtime Environment              │
- ┬─────────────┬────────────────┤
- TypeScript │   Node.js   │     LSP        │
- Runtime    │   Compat    │    Server      │
- ┴─────────────┴────────────────┘
- ↕
**┌─────────────────────────────────────────────┐**
- External Systems                 │
- ┬─────────────┬────────────────┤
- Registry   │    Cache    │   Container    │
- Service    │   Storage   │    Runtime     │
- ┴─────────────┴────────────────┘

Important Details to Include:

##### Data Flow
- How build requests flow from CLI through the system
- Cache checking/storage paths
- Registry interaction points

##### Key Features
- Caching mechanisms
- Lockfile management
- Cross-compilation paths
- TypeScript integration points

##### Process Flow
- Build request handling
- Dependency resolution
- Cache management
- Sandbox execution

##### Integration Points
- External tool connections
- Registry communication
- Container system interaction

Remember to:
- Use a consistent style
- Brief annotations for complex interactions
- Version/configuration management
- Error handling paths

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef cli fill:#f9f,stroke:#333,stroke-width:2px
    classDef core fill:#9cf,stroke:#333,stroke-width:2px
    classDef runtime fill:#9f9,stroke:#333,stroke-width:2px
    classDef external fill:#fc9,stroke:#333,stroke-width:2px
    classDef storage fill:#ddd,stroke:#333,stroke-width:2px

    %% CLI Layer
    CLI["CLI Interface"]:::cli
    click CLI "https://github.com/brioche-dev/brioche/tree/main/crates/brioche/"

    %% Core Engine Layer
    subgraph CoreEngine["Core Engine"]
        BakeSystem["Bake System"]
        click BakeSystem "https://github.com/brioche-dev/brioche/tree/main/crates/brioche-core/src/bake/"
        ScriptEngine["Script Engine"]
        click ScriptEngine "https://github.com/brioche-dev/brioche/tree/main/crates/brioche-core/src/script/"
        ProjectMgr["Project Manager"]
        click ProjectMgr "https://github.com/brioche-dev/brioche/tree/main/crates/brioche-core/src/project/"
        Sandbox["Sandbox System"]
        click Sandbox "https://github.com/brioche-dev/brioche/tree/main/crates/brioche-core/src/sandbox/"
        Registry["Registry Client"]
        click Registry "https://github.com/brioche-dev/brioche/blob/main/crates/brioche-core/src/registry.rs"
        BlobStore["Blob Storage"]
        click BlobStore "https://github.com/brioche-dev/brioche/blob/main/crates/brioche-core/src/blob.rs"
    end
    click CoreEngine "https://github.com/brioche-dev/brioche/tree/main/crates/brioche-core/"

    %% Runtime Environment Layer
    subgraph Runtime["Runtime Environment"]
        TSRuntime["TypeScript Runtime"]
        click TSRuntime "https://github.com/brioche-dev/brioche/tree/main/crates/brioche-core/runtime/"
        NodeCompat["Node.js Compatibility"]
        click NodeCompat "https://github.com/brioche-dev/brioche/tree/main/crates/brioche-core/runtime/src/compat/node/"
        LSP["LSP Server"]
        click LSP "https://github.com/brioche-dev/brioche/blob/main/crates/brioche-core/runtime/src/lsp.ts"
    end

    %% External Systems Layer
    subgraph External["External Systems"]
        RegistryService[("Registry Service")]:::storage
        CacheStorage[("Cache Storage")]:::storage
        ContainerRuntime["Container Runtime"]:::external
    end

    %% Connections
    CLI --> CoreEngine
    BakeSystem <--> ScriptEngine
    ScriptEngine <--> ProjectMgr
    ProjectMgr <--> Sandbox
    Sandbox <--> Registry
    Registry <--> BlobStore
    
    CoreEngine <--> Runtime
    TSRuntime <--> NodeCompat
    NodeCompat <--> LSP
    
    Registry -.-> RegistryService
    BlobStore -.-> CacheStorage
    Sandbox -.-> ContainerRuntime

    %% Legend
    subgraph Legend
        CLI_L["CLI Component"]:::cli
        Core_L["Core Component"]:::core
        Runtime_L["Runtime Component"]:::runtime
        External_L["External Component"]:::external
        Storage_L[("Storage System")]:::storage
    end
```
