# brucellino/cdevents architecture

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

- Interactive diagram: https://gitdiagram.com/brucellino/cdevents
- Repository: https://github.com/brucellino/cdevents

## Overview

##### Main Components

a) Client Layer:
- Web Browsers/API Clients
- Swagger UI Interface (running on port 8787 in development)

b) Cloudflare Infrastructure:
- Cloudflare Workers Runtime
- Edge Network Distribution

c) Application Components:
- Main Router (from src/index.ts)
- Endpoint Handlers Layer
- Event Handling System
- OpenAPI Schema Generator

##### Key Architectural Elements

a) Entry Point:
- Main router (src/index.ts) as the central orchestrator
- It to Hono framework for routing
- It to Chanfana for OpenAPI integration

b) Endpoint Structure (src/endpoints/):
- Endpoints into logical sections:
- Task Management (taskCreate, taskDelete, taskFetch, taskList)
- Event Handling (handleEvent)
- CDEvents (under dev/cdevents)

c) Event System:
- Event types hierarchy (src/event-types/)
- It to the core context and pipeline run components

##### Specific relationships

**Client Request → Cloudflare Edge → Workers Runtime → Main Router → Endpoint Handlers**
**↓**
**OpenAPI Validation (Chanfana) ←→ Schema Generation**
**↓**
**Event Processing → Event Types → Core Context**

##### Important Details to Highlight

- OpenAPI/Swagger integration at the top level
- Serverless nature of the architecture
- Automatic OpenAPI schema generation
- Separation between endpoint handlers and event types

##### Technical Stack Indicators

A tech stack section showing:
- TypeScript as the primary language
- Hono for routing
- Chanfana for OpenAPI support
- Cloudflare Workers as the runtime environment

##### Development Flow

A small section showing the development workflow:
**Local Development (wrangler dev) → Deployment (wrangler deploy) → Cloudflare Workers**

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser/API Client"]
        SwaggerUI["Swagger UI Interface"]
    end

    subgraph CloudflareInfra
        Edge["Cloudflare Edge Network"]
        Workers["Cloudflare Workers Runtime"]:::runtime
    end

    subgraph AppCore
        Router["Main Router"]:::core
        click Router "https://github.com/brucellino/cdevents/blob/main/src/index.ts"
        
        subgraph Endpoints
            TaskEndpoints["Task Management"]:::endpoint
            click TaskEndpoints "https://github.com/brucellino/cdevents/tree/main/src/endpoints"
            EventHandler["Event Handler"]:::endpoint
            click EventHandler "https://github.com/brucellino/cdevents/blob/main/src/endpoints/handleEvent.ts"
            CDEvents["CDEvents System"]:::endpoint
            click CDEvents "https://github.com/brucellino/cdevents/tree/main/src/endpoints/dev/cdevents"
        end

        subgraph EventSystem
            EventTypes["Event Types"]:::event
            click EventTypes "https://github.com/brucellino/cdevents/tree/main/src/event-types"
            CoreContext["Core Context"]:::event
            click CoreContext "https://github.com/brucellino/cdevents/blob/main/src/event-types/core/context.ts"
            PipelineRun["Pipeline Run"]:::event
            click PipelineRun "https://github.com/brucellino/cdevents/blob/main/src/event-types/core/pipelineRun/finished.ts"
        end

        subgraph Configuration
            WorkerConfig["Worker Configuration"]:::config
            click WorkerConfig "https://github.com/brucellino/cdevents/blob/main/wrangler.toml"
            TypeDefs["Type Definitions"]:::config
            click TypeDefs "https://github.com/brucellino/cdevents/blob/main/src/types.ts"
        end
    end

    subgraph Integration
        OpenAPI["OpenAPI Schema Generator"]
        Chanfana["Chanfana Integration"]
        Hono["Hono Framework"]
    end

    %% Connections
    Browser --> Edge
    SwaggerUI --> Edge
    Edge --> Workers
    Workers --> Router
    Router --> TaskEndpoints
    Router --> EventHandler
    Router --> CDEvents
    Router --> Hono
    Router --> Chanfana
    
    EventHandler --> EventTypes
    EventTypes --> CoreContext
    EventTypes --> PipelineRun
    
    Chanfana --> OpenAPI
    
    %% Styles
    classDef runtime fill:#f9f,stroke:#333
    classDef endpoint fill:#afd,stroke:#333
    classDef event fill:#fda,stroke:#333
    classDef core fill:#acf,stroke:#333
    classDef config fill:#ddd,stroke:#333

    %% Legend
    subgraph Legend
        L1["Runtime Component"]:::runtime
        L2["Endpoint Component"]:::endpoint
        L3["Event Component"]:::event
        L4["Core Component"]:::core
        L5["Configuration"]:::config
    end
```
