# jason136/bonfire architecture

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

- Interactive diagram: https://gitdiagram.com/jason136/bonfire
- Repository: https://github.com/jason136/bonfire

## Overview

##### Main Components
- API Server: Represent the HTTP API layer that accepts incoming requests (e.g., POST /prompt_polled, GET /poll_text/{id}, POST /new_streaming, and POST /prompt_streaming/{id}). Indicate that Axum (via Tokio) is the framework handling these endpoints.
- Controller Layer: Illustrate a component that encapsulates request processing logic. The file "src/controller.rs" would be part of this layer.
- Request Extractors & Error Handling: Show supporting components such as extractors ("src/extractors.rs") and error management ("src/error.rs") that process incoming requests and manage invalid or expired responses.
- Text Generation Engine: Represent the core text generation functionality. This includes the distinct modules in "src/text_generation", which house different model implementations. Each file (e.g., "gguf_quantized.rs", "mistral7b.rs", "mixtral.rs", "token_stream.rs", "utils.rs") suggests a separation of concerns for supporting various AI models.
- Polled and Streaming Modules: Distinguish between the text generation strategies. You have a polled text generation endpoint handled by "src/text_polled.rs" and a real-time token streaming endpoint in "src/text_streaming.rs". These modules will orchestrate the asynchronous handling of model outputs (such as streaming or short-term storage for later polling).

##### Architectural Patterns and Design Principles
- Asynchronous Processing: Note that the project uses Tokio’s async runtime to manage long-running processes (especially important for streaming endpoints).

##### Specific Technologies
- Rust as the primary language.
- Tokio and Axum for async request handling.
- Huggingface’s Candle for interfacing with generative AI models.
- Any additional dependencies highlighted in Cargo.toml (implied by file structure) can be noted for build and dependency management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Layer
    subgraph "API Layer"
        A["API Server (Axum/Tokio)"]:::api
    end

    %% Controller & Request Handling Layer
    subgraph "Controller & Request Handling"
        B["Controller"]:::controller
        C["Request Extractors"]:::module
        D["Error Handling"]:::module
    end

    %% Text Generation Engine Layer
    subgraph "Text Generation Engine"
        E["Text Generation Engine"]:::engine
        subgraph "Model Implementations"
            E1["gguf_quantized"]:::module
            E2["Mistral7b"]:::module
            E3["Mixtral"]:::module
            E4["Token Stream Handling"]:::module
            E5["Model Factory & Utilities"]:::module
        end
    end

    %% Text Generation Modules (Operational Modes)
    subgraph "Text Generation Modules"
        F["Polled Text Generation"]:::module
        G["Streaming Text Generation"]:::module
    end

    %% External Dependencies
    H["Huggingface's Candle"]:::external

    %% Connections
    A -->|"routes"| B
    B -->|"parses"| C
    B -->|"handles"| D
    B -->|"selects_model_via_enum"| E
    E -->|"factory_usage"| E5
    E5 -->|"factory"| E1
    E5 -->|"factory"| E2
    E5 -->|"factory"| E3
    E5 -->|"factory"| E4
    E -->|"for_polled_output"| F
    E -->|"for_streaming_output"| G
    E -->|"calls"| H

    %% Click Events
    click A "https://github.com/jason136/bonfire/blob/main/src/main.rs"
    click B "https://github.com/jason136/bonfire/blob/main/src/controller.rs"
    click C "https://github.com/jason136/bonfire/blob/main/src/extractors.rs"
    click D "https://github.com/jason136/bonfire/blob/main/src/error.rs"
    click E "https://github.com/jason136/bonfire/tree/main/src/text_generation"
    click E1 "https://github.com/jason136/bonfire/blob/main/src/text_generation/gguf_quantized.rs"
    click E2 "https://github.com/jason136/bonfire/blob/main/src/text_generation/mistral7b.rs"
    click E3 "https://github.com/jason136/bonfire/blob/main/src/text_generation/mixtral.rs"
    click E4 "https://github.com/jason136/bonfire/blob/main/src/text_generation/token_stream.rs"
    click E5 "https://github.com/jason136/bonfire/blob/main/src/text_generation/utils.rs"
    click F "https://github.com/jason136/bonfire/blob/main/src/text_polled.rs"
    click G "https://github.com/jason136/bonfire/blob/main/src/text_streaming.rs"

    %% Styles
    classDef api fill:#aee1f9,stroke:#333,stroke-width:2px
    classDef controller fill:#c7f9cc,stroke:#333,stroke-width:2px
    classDef module fill:#fff1ab,stroke:#333,stroke-width:2px
    classDef engine fill:#f9d6a5,stroke:#333,stroke-width:2px
    classDef external fill:#f3c4fb,stroke:#333,stroke-width:2px
```
