# phoenixframework/flame architecture

> Architecture diagram of the GitHub repository phoenixframework/flame, 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/phoenixframework/flame
- Repository: https://github.com/phoenixframework/flame

## Overview

##### Main Components

a) Core Components:
- FLAME Pool (Central orchestrator)
- Backends (FlyBackend and LocalBackend)
- Runner (Execution environment)
- Queue (Job management)
- Terminator (Resource cleanup)
- CodeSync (Code synchronization)
- Parser (JSON handling)

b) External Integration:
- Host Application
- Infrastructure Provider (e.g., Fly.io)
- Temporary Application Instances

**┌─ Host Application Layer ─────────────────────┐**

- ┌─ FLAME Core ──────────────────────────┐  │

- ┌─ Pool Management ─┐   ┌─ Queue ─┐  │  │

- ┘   └─────────┘  │  │

- ┌─ Backend Interface ─────────────┐  │  │
- (FlyBackend/LocalBackend)      │  │  │
- ┘  │  │
- ┘  │
- ┘

**┌─ Infrastructure Layer ────────────────────────┐**
- ┌─ Runner 1 ─┐  ┌─ Runner 2 ─┐  ┌─ ... ─┐   │

- ┘  └────────────┘  └───────┘   │
- ┘

##### Component Relationships

- Function calls (FLAME.call/cast) from Host App → FLAME Core
- Pool management flows
- Backend communication with infrastructure
- Runner lifecycle management

##### Implementation Details

- Supervision tree structure
- Backend implementation options
- Parser and code sync mechanisms
- Terminator cleanup processes

##### Job Submission Flow
**Host App → FLAME.call → Pool → Queue → Runner → Result**

##### Runner Lifecycle
**Pool → Backend → Infrastructure → Runner Creation → Execution → Termination**

##### Additional Notes

- Configuration parameters
- Monitoring points
- Error handling paths
- Cleanup mechanisms

Remember to maintain a balance between showing the complexity of the system while keeping it clear and understandable. The key is to highlight how FLAME enables treating the entire application as a lambda function that can be executed on temporary infrastructure.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Host["Host Application Layer"]
        HostApp["Host Application"]
        FLAME["FLAME Interface"]:::interface
        
        subgraph Core["FLAME Core"]
            Pool["Pool Manager"]:::pool
            Queue["Queue"]:::queue
            CodeSync["Code Sync"]:::codesync
            Parser["Parser"]:::parser
            Terminator["Terminator"]:::terminator
            
            subgraph Backend["Backend Interface"]
                FlyBackend["Fly Backend"]:::backend
                LocalBackend["Local Backend"]:::backend
            end
        end
        
        HostApp --> |FLAME.call/cast| FLAME
        FLAME --> Pool
        Pool --> Queue
        Pool --> CodeSync
        Pool --> Parser
        Pool --> Terminator
        Pool --> FlyBackend
        Pool --> LocalBackend
    end
    
    subgraph Infra["Infrastructure Layer"]
        Runner1["Runner Instance 1"]:::runner
        Runner2["Runner Instance 2"]:::runner
        Runner3["Runner Instance 3"]:::runner
    end
    
    FlyBackend --> |Create/Manage| Runner1
    FlyBackend --> |Create/Manage| Runner2
    LocalBackend --> |Create/Manage| Runner3
    
    Queue --> |Dispatch Jobs| Runner1
    Queue --> |Dispatch Jobs| Runner2
    Queue --> |Dispatch Jobs| Runner3
    
    Terminator --> |Cleanup| Runner1
    Terminator --> |Cleanup| Runner2
    Terminator --> |Cleanup| Runner3
    
    CodeSync --> |Sync Code| Runner1
    CodeSync --> |Sync Code| Runner2
    CodeSync --> |Sync Code| Runner3

    classDef interface fill:#f9f,stroke:#333,stroke-width:2px
    classDef pool fill:#bbf,stroke:#333,stroke-width:2px
    classDef queue fill:#bfb,stroke:#333,stroke-width:2px
    classDef backend fill:#ffb,stroke:#333,stroke-width:2px
    classDef runner fill:#ddd,stroke:#333,stroke-width:2px
    classDef codesync fill:#fbf,stroke:#333,stroke-width:2px
    classDef parser fill:#bff,stroke:#333,stroke-width:2px
    classDef terminator fill:#fbb,stroke:#333,stroke-width:2px
    
    click FLAME "https://github.com/phoenixframework/flame/blob/main/lib/flame.ex"
    click Pool "https://github.com/phoenixframework/flame/blob/main/lib/flame/pool.ex"
    click Queue "https://github.com/phoenixframework/flame/blob/main/lib/flame/queue.ex"
    click CodeSync "https://github.com/phoenixframework/flame/blob/main/lib/flame/code_sync.ex"
    click Parser "https://github.com/phoenixframework/flame/blob/main/lib/flame/parser/json.ex"
    click Terminator "https://github.com/phoenixframework/flame/blob/main/lib/flame/terminator.ex"
    click FlyBackend "https://github.com/phoenixframework/flame/blob/main/lib/flame/fly_backend.ex"
    click LocalBackend "https://github.com/phoenixframework/flame/blob/main/lib/flame/local_backend.ex"
    click Runner1 "https://github.com/phoenixframework/flame/blob/main/lib/flame/runner.ex"
    click Runner2 "https://github.com/phoenixframework/flame/blob/main/lib/flame/runner.ex"
    click Runner3 "https://github.com/phoenixframework/flame/blob/main/lib/flame/runner.ex"
```
