# jorisvink/kore architecture

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

## Overview

##### Main Components

a) Core Server Components:
- Worker Process Manager
- TLS/Security Layer
- Event-driven Architecture (epoll/kqueue)
- HTTP/1.1 Server
- WebSocket Server
- Module System

b) Extension Systems:
- Python Runtime Integration
- Lua Runtime Integration
- PostgreSQL Connector
- CURL Integration
- ACME Certificate Manager

c) Security Components:
- Privilege Separation System
- Seccomp/Pledge Sandbox
- Key Management Process
- TLS Backend

**┌─ External Clients Layer ─┐**
- (HTTP/WS/TLS)     │
**┌─ Security Layer ────────┐**
- (Privilege Sep.)    │
**┌─ Core Server Layer ─────┐**
- (Worker Processes)  │
**┌─ Extension Layer ───────┐**
- (Python/Lua/DB/etc.) │

##### Key Relationships to Highlight

- Privilege separation between components using distinct boundaries
- Worker process distribution
- Demonstrate the module loading system
- Connection handling flow
- Integration points with external services

##### Important Elements

a) Process Flow Indicators:
- Request handling path
- Worker process communication
- Module loading/reloading
- Security boundary crossing

b) Component Details:
- Worker process pools
- Event handling system
- Module system
- Security containers

##### Specific Implementation Details

- The event-driven architecture
- Per-CPU worker process distribution
- Privilege separation boundaries
- Module hot-reloading capability
- Security sandbox implementation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Clients
        Client1[Web Browser]
        Client2[WebSocket Client]
        Client3[API Client]
    end

    subgraph "Security Layer"
        TLS["TLS/Security Layer"]:::security
        ACME["ACME Certificate Manager"]:::security
        KeyMgr["Key Management"]:::security
    end

    subgraph "Server Core"
        HTTP["HTTP/1.1 Server"]:::core
        WS["WebSocket Server"]:::core
        EventSystem["Event System"]:::core
        ConnMgr["Connection Manager"]:::core
        WorkerMgr["Worker Process Manager"]:::core
        TaskSystem["Task System"]:::core
    end

    subgraph "Security Sandbox"
        Seccomp["Seccomp/Pledge"]:::security
        PrivSep["Privilege Separation"]:::security
    end

    subgraph "Module System"
        ModLoader["Module Loader"]:::module
        HotReload["Hot Reloading"]:::module
    end

    subgraph "Extensions"
        Python["Python Runtime"]:::ext
        Lua["Lua Runtime"]:::ext
        PGSQL["PostgreSQL"]:::ext
        CURL["CURL Integration"]:::ext
    end

    %% Client Connections
    Client1 --> TLS
    Client2 --> TLS
    Client3 --> TLS

    %% Security Layer Flow
    TLS --> HTTP
    TLS --> WS
    ACME --> TLS
    KeyMgr --> TLS

    %% Core Server Flow
    HTTP --> EventSystem
    WS --> EventSystem
    EventSystem --> ConnMgr
    ConnMgr --> WorkerMgr
    WorkerMgr --> TaskSystem

    %% Security Implementation
    WorkerMgr --> Seccomp
    WorkerMgr --> PrivSep

    %% Module System
    ModLoader --> Python
    ModLoader --> Lua
    ModLoader --> PGSQL
    ModLoader --> CURL
    ModLoader --> HotReload

    %% Styling
    classDef core fill:#2374ab
    classDef security fill:#ff7f50
    classDef module fill:#4CAF50
    classDef ext fill:#ffd700

    %% Click Events
    click WorkerMgr "https://github.com/jorisvink/kore/blob/master/src/worker.c"
    click TLS "https://github.com/jorisvink/kore/blob/master/src/tls_openssl.c"
    click HTTP "https://github.com/jorisvink/kore/blob/master/src/http.c"
    click WS "https://github.com/jorisvink/kore/blob/master/src/websocket.c"
    click ModLoader "https://github.com/jorisvink/kore/blob/master/src/module.c"
    click Python "https://github.com/jorisvink/kore/blob/master/src/python.c"
    click Lua "https://github.com/jorisvink/kore/blob/master/src/lua.c"
    click PGSQL "https://github.com/jorisvink/kore/blob/master/src/pgsql.c"
    click CURL "https://github.com/jorisvink/kore/blob/master/src/curl.c"
    click ACME "https://github.com/jorisvink/kore/blob/master/src/acme.c"
    click Seccomp "https://github.com/jorisvink/kore/blob/master/src/seccomp.c"
    click KeyMgr "https://github.com/jorisvink/kore/blob/master/src/keymgr_openssl.c"
    click EventSystem "https://github.com/jorisvink/kore/blob/master/src/runtime.c"
    click ConnMgr "https://github.com/jorisvink/kore/blob/master/src/connection.c"
    click TaskSystem "https://github.com/jorisvink/kore/blob/master/src/tasks.c"
```
