# tarmac-project/tarmac architecture

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

- Interactive diagram: https://gitdiagram.com/tarmac-project/tarmac
- Repository: https://github.com/tarmac-project/tarmac

## Overview

##### Main Components

a. Core Components:
- Tarmac Host Server
- WebAssembly Engine
- Function Registry
- Route Handler
- Callback System
- Configuration Manager

b. Integration Components:
- Key-Value Store Interface
- SQL Database Interface
- HTTP Client Interface
- Metrics System
- Logging System

c. External Services Support:
- Redis
- MySQL/PostgreSQL
- Cassandra
- Consul
- Prometheus

**Layer 1: Client Interface Layer**
- HTTP Endpoints
- Scheduled Task Triggers
- Boot Triggers

**Layer 2: Tarmac Host Layer**
- Route Handler
- Configuration Manager
- Function Registry

**Layer 3: WebAssembly Runtime Layer**
- WASM Engine (waPC)
- Function Instances
- Callback Handler

**Layer 4: Core Capabilities Layer**
- Key-Value Store Interface
- SQL Interface
- HTTP Client
- Logging
- Metrics

**Layer 5: External Services Layer**
- Databases
- Caches
- Monitoring Systems

##### Key Relationships

a. Request Flow:
- Client → HTTP Handler → WASM Function → Callback System → External Services
- Scheduler → WASM Function → Callback System → External Services

b. Configuration Flow:
- tarmac.json → Configuration Manager → Function Registry → WASM Engine

c. Integration Points:
- WASM Functions ↔ Callback System
- Callback System ↔ Core Capabilities
- Core Capabilities ↔ External Services

##### Implementation Notes

- Maintain consistent spacing and alignment
- Brief annotations for complex interactions
- Creating separate detailed views for specific subsystems
- Version information and date

##### Focus Areas

- WebAssembly-centric architecture
- Flexibility in supporting multiple functions
- Built-in capabilities
- Demonstrate the language-agnostic nature
- Scalability aspects

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef core fill:#2374ab,color:white
    classDef wasm fill:#7dba84,color:white
    classDef interface fill:#ffb347,color:white
    classDef external fill:#808080,color:white
    classDef legend fill:none,stroke:gray,stroke-dasharray: 5 5

    %% Legend
    subgraph Legend
        L1[Core Component]:::core
        L2[WebAssembly Component]:::wasm
        L3[Integration Interface]:::interface
        L4[External Service]:::external
        L5[Data Flow] --> L6[Component]
    end

    %% Layer 1: Client Interface
    subgraph "Client Interface Layer"
        HTTP[HTTP Endpoints]
        SCHED[Scheduled Tasks]
        BOOT[Boot Triggers]
    end

    %% Layer 2: Tarmac Host
    subgraph "Tarmac Host Layer"
        HOST[Tarmac Host Server]:::core
        CONFIG[Configuration Manager]:::core
        REGISTRY[Function Registry]:::core
        ROUTE[Route Handler]:::core
    end

    %% Layer 3: WebAssembly Runtime
    subgraph "WebAssembly Runtime Layer"
        WASM[WebAssembly Engine]:::wasm
        CALLBACK[Callback System]:::wasm
    end

    %% Layer 4: Core Capabilities
    subgraph "Core Capabilities Layer"
        KV[Key-Value Store Interface]:::interface
        SQL[SQL Database Interface]:::interface
        HTTPC[HTTP Client Interface]:::interface
        LOG[Logging System]:::interface
        METRICS[Metrics System]:::interface
        TELEMETRY[Telemetry System]:::interface
    end

    %% Layer 5: External Services
    subgraph "External Services Layer"
        REDIS[Redis]:::external
        DB[MySQL/PostgreSQL]:::external
        CASS[Cassandra]:::external
        CONSUL[Consul]:::external
        PROM[Prometheus]:::external
    end

    %% Connections
    HTTP --> HOST
    SCHED --> HOST
    BOOT --> HOST
    
    HOST --> ROUTE
    HOST --> CONFIG
    HOST --> REGISTRY
    
    ROUTE --> WASM
    REGISTRY --> WASM
    CONFIG --> REGISTRY
    
    WASM --> CALLBACK
    
    CALLBACK --> KV
    CALLBACK --> SQL
    CALLBACK --> HTTPC
    CALLBACK --> LOG
    CALLBACK --> METRICS
    CALLBACK --> TELEMETRY
    
    KV --> REDIS
    SQL --> DB
    SQL --> CASS
    METRICS --> PROM
    CONFIG --> CONSUL

    %% Click events for component mapping
    click HOST "https://github.com/tarmac-project/tarmac/blob/main/pkg/app/server.go"
    click WASM "https://github.com/tarmac-project/tarmac/blob/main/pkg/wasm/wasm.go"
    click CONFIG "https://github.com/tarmac-project/tarmac/blob/main/pkg/config/config.go"
    click CALLBACK "https://github.com/tarmac-project/tarmac/blob/main/pkg/callbacks/callbacks.go"
    click KV "https://github.com/tarmac-project/tarmac/blob/main/pkg/callbacks/kvstore/kvstore.go"
    click SQL "https://github.com/tarmac-project/tarmac/blob/main/pkg/callbacks/sql/sql.go"
    click HTTPC "https://github.com/tarmac-project/tarmac/blob/main/pkg/callbacks/httpclient/httpclient.go"
    click METRICS "https://github.com/tarmac-project/tarmac/blob/main/pkg/callbacks/metrics/metrics.go"
    click LOG "https://github.com/tarmac-project/tarmac/blob/main/pkg/callbacks/logging/logging.go"
    click REGISTRY "https://github.com/tarmac-project/tarmac/blob/main/pkg/sdk/function/function.go"
    click TELEMETRY "https://github.com/tarmac-project/tarmac/blob/main/pkg/telemetry/telemetry.go"
```
