# devchain-network/cauldron architecture

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

- Interactive diagram: https://gitdiagram.com/devchain-network/cauldron
- Repository: https://github.com/devchain-network/cauldron

## Overview

##### Main Components Identification
The system consists of three main services (evident from the Dockerfiles and cmd directory):
- Cauldron Server (API Server)
- GitHub Consumer
- Migrator Service

##### Key Architectural Elements

a) Frontend Layer:
- External GitHub Webhooks interface
- Supported webhook events (as listed in README)

b) Backend Services:
- API Server (internal/apiserver)
- Kafka Consumer Service (internal/kafkaconsumer)
- Database Migration Service

c) Infrastructure Components:
- Kafka Message Queue (evident from docker-compose.kafka.yml)
- PostgreSQL Database (indicated by migrations folder with SQL files)

**[GitHub Webhooks] → [API Server Layer]**
- ↓
- [Kafka Queue]
- ↓
- [GitHub Consumer]
- ↓
- [PostgreSQL DB]

##### Detailed Component Breakdown

API Server Layer:
- HTTP handlers (internal/apiserver/handlers.go)
- GitHub handler options (internal/apiserver/githubhandleroptions)
- Error handling component (internal/cerrors)

Kafka Consumer Layer:
- GitHub event processing (internal/kafkaconsumer/github.go)
- Consumer types (internal/kafkaconsumer/types.go)

Storage Layer:
- Storage interfaces (internal/storage/storage.go)
- Query handling (internal/storage/query.go)

##### Additional Elements

Supporting components:
- Logging system (internal/slogger)
- Migration workflows
- Error handling paths

##### Important Flows to Highlight

a) Webhook Processing Flow:
**GitHub → API Server → Kafka → Consumer → Database**

b) Migration Flow:
**Migrator Service → Database**

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External
        GH[GitHub Webhooks]:::external
    end

    subgraph API["API Server Layer"]
        AS["API Server"]:::service
        GHH["GitHub Handler"]:::handler
        EH["Error Handler"]:::handler
        LOG["Logger"]:::util
    end

    subgraph Queue["Message Queue Layer"]
        KF["Kafka Queue"]:::queue
    end

    subgraph Consumer["Consumer Layer"]
        GC["GitHub Consumer"]:::service
        KT["Kafka Types"]:::component
    end

    subgraph Storage["Storage Layer"]
        SI["Storage Interface"]:::component
        QH["Query Handler"]:::component
        PG[(PostgreSQL)]:::database
    end

    subgraph Migration["Migration Layer"]
        MS["Migrator Service"]:::service
        MF["Migration Files"]:::component
    end

    %% Connections
    GH --> AS
    AS --> GHH
    AS --> EH
    AS --> LOG
    GHH --> KF
    KF --> GC
    GC --> KT
    GC --> SI
    SI --> QH
    QH --> PG
    MS --> MF
    MF --> PG

    %% Click Events
    click AS "https://github.com/devchain-network/cauldron/blob/main/cmd/server/main.go"
    click GHH "https://github.com/devchain-network/cauldron/blob/main/internal/apiserver/githubhandleroptions/githubhandleroptions.go"
    click EH "https://github.com/devchain-network/cauldron/blob/main/internal/cerrors/cerrors.go"
    click LOG "https://github.com/devchain-network/cauldron/blob/main/internal/slogger/slogger.go"
    click GC "https://github.com/devchain-network/cauldron/blob/main/cmd/githubconsumer/main.go"
    click KT "https://github.com/devchain-network/cauldron/blob/main/internal/kafkaconsumer/types.go"
    click SI "https://github.com/devchain-network/cauldron/blob/main/internal/storage/storage.go"
    click QH "https://github.com/devchain-network/cauldron/blob/main/internal/storage/query.go"
    click MS "https://github.com/devchain-network/cauldron/blob/main/cmd/migrator/main.go"
    click MF "https://github.com/devchain-network/cauldron/tree/main/migrations"
    click KF "https://github.com/devchain-network/cauldron/blob/main/docker-compose.kafka.yml"

    %% Styling
    classDef external fill:#2374e1
    classDef service fill:#85bb65
    classDef handler fill:#67c1c1
    classDef queue fill:#f9d66b
    classDef database fill:#b45dd9
    classDef component fill:#cccccc
    classDef util fill:#f97a6d

    %% Legend
    subgraph Legend
        L1[External Service]:::external
        L2[Internal Service]:::service
        L3[Handler]:::handler
        L4[Queue]:::queue
        L5[(Database)]:::database
        L6[Component]:::component
        L7[Utility]:::util
    end
```
