# komuw/ong architecture

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

- Interactive diagram: https://gitdiagram.com/komuw/ong
- Repository: https://github.com/komuw/ong

## Overview

##### Main Components

a) Core HTTP Server Layer:
- TLS/ACME handler (from server/tls_conf.go)
- Auto-configuration (GOMEMLIMIT, GOMAXPROCS)
- Graceful shutdown handler
- pprof endpoints

b) Middleware Chain:
- Rate Limiter
- Load Shedder
- CORS Handler
- CSRF Protection
- Session Manager
- Recovery Handler
- Logging Middleware
- Client IP Detection
- Security Headers

c) Router/Multiplexer:
- "Mux" component with:
- Route Registry
- Path Parameter Handler
- Route Conflict Detection

d) Supporting Services:
- Crypto Services (cry package)
- Session Management (sess package)
- Logging System (log package with circular buffer)
- ID Generation (id package)
- Error Handling (errors package)

##### Component Relationships

- External Request → TLS Termination → Middleware Chain → Router → Handler

##### Specific Implementation Details

- Security components (red)
- Performance components (blue)
- Core routing components (green)
- Supporting utilities (gray)

##### Specific elements

**┌─────────────────────────────────────────────┐**
- HTTP Server                   │
- ┌─────────────┐ ┌──────────┐ ┌──────────┐  │
- TLS/ACME    │ │ AutoMax  │ │ Graceful │  │
- Management  │ │ Config   │ │ Shutdown │  │
- ┘ └──────────┘ └──────────┘  │
- ┘

- ▼
**┌─────────────────────────────────────────────┐**
- Middleware Chain                  │
- ┌─────────┐ ┌────────┐ ┌────────────────┐  │
- Security│ │ Perf   │ │ Observability  │  │
- CSRF    │ │ Rate   │ │ Logging        │  │
- CORS    │ │ Limit  │ │ Tracing        │  │
- ┘ └────────┘ └────────────────┘  │
- ┘

- ▼
**┌─────────────────────────────────────────────┐**
- Router (Mux)                   │
- ┌─────────────┐ ┌──────────────────────┐   │
- Route       │ │ Path Parameter        │   │
- Registry    │ │ Handling             │   │
- ┘ └──────────────────────┘   │
- ┘

##### Implementation Notes

- Notes about auto-configuration features

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Server["HTTP Server Core"]
        TLS["TLS/ACME Handler"]
        AutoConf["Auto Configuration"]
        Shutdown["Graceful Shutdown"]
        PProf["pprof Endpoints"]
    end

    subgraph Middleware["Middleware Chain"]
        direction TB
        RateLimit["Rate Limiter"]
        LoadShed["Load Shedder"]
        CORS["CORS Handler"]
        CSRF["CSRF Protection"]
        Session["Session Manager"]
        Recovery["Recovery Handler"]
        Logging["Logging Middleware"]
        ClientIP["Client IP Detection"]
        SecHeaders["Security Headers"]
    end

    subgraph Router["Router Layer"]
        Mux["Route Registry"]
        PathHandler["Path Parameter Handler"]
        ConflictDetect["Route Conflict Detection"]
    end

    subgraph Support["Supporting Services"]
        Crypto["Crypto Services"]
        SessionMgmt["Session Management"]
        LogSystem["Logging System"]
        IDGen["ID Generation"]
        ErrorHandle["Error Handling"]
    end

    Request[("External Request")] --> TLS
    TLS --> Middleware
    Middleware --> Router
    Router --> Handler[("Request Handler")]

    Support --> Middleware
    Support --> Router

    %% Component Mappings
    click TLS "https://github.com/komuw/ong/blob/main/server/tls_conf.go"
    click AutoConf "https://github.com/komuw/ong/blob/main/automax/automax.go"
    click PProf "https://github.com/komuw/ong/blob/main/server/pprof.go"
    click RateLimit "https://github.com/komuw/ong/blob/main/middleware/ratelimiter.go"
    click CORS "https://github.com/komuw/ong/blob/main/middleware/cors.go"
    click CSRF "https://github.com/komuw/ong/blob/main/middleware/csrf.go"
    click Session "https://github.com/komuw/ong/blob/main/middleware/session.go"
    click Recovery "https://github.com/komuw/ong/blob/main/middleware/recoverer.go"
    click Logging "https://github.com/komuw/ong/blob/main/middleware/log.go"
    click ClientIP "https://github.com/komuw/ong/blob/main/middleware/client_ip.go"
    click LoadShed "https://github.com/komuw/ong/blob/main/middleware/loadshed.go"
    click Mux "https://github.com/komuw/ong/blob/main/mux/mux.go"
    click PathHandler "https://github.com/komuw/ong/blob/main/mux/route.go"
    click Crypto "https://github.com/komuw/ong/tree/main/cry/"
    click SessionMgmt "https://github.com/komuw/ong/blob/main/sess/sess.go"
    click LogSystem "https://github.com/komuw/ong/blob/main/log/log.go"
    click IDGen "https://github.com/komuw/ong/blob/main/id/id.go"
    click ErrorHandle "https://github.com/komuw/ong/blob/main/errors/errors.go"

    classDef security fill:#ff9999
    classDef performance fill:#99ccff
    classDef core fill:#99ff99
    classDef support fill:#cccccc

    class TLS,CSRF,CORS,SecHeaders security
    class RateLimit,LoadShed,AutoConf performance
    class Mux,PathHandler,ConflictDetect core
    class Support,Crypto,SessionMgmt,LogSystem,IDGen,ErrorHandle support
```
