# semihalev/sdns architecture

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

## Overview

##### Main Components Identification

The system should be represented with these key components:

a) Core DNS Server Components:
- DNS Protocol Handlers (UDP/TCP/DoT/DoH/DoQ)
- Query Router/Dispatcher
- Cache System
- DNSSEC Validator
- Middleware Chain

b) External Interfaces:
- HTTP API Server
- Metrics Endpoint
- Configuration Manager

**┌─ Client Layer ─────────────────────────────────┐**
- DNS Clients │ DoT Clients │ DoH Clients │ DoQ  │
- ┴─────────────┴─────────────┴──────┘
**┌─ Server Layer ────────────────────────────────────────────┐**
- ┌─────────┐ ┌────────┐ ┌─────────┐ ┌────────┐           │
- DNS :53  │ │DoT:853 │ │DoH:8053 │ │DoQ:853 │ API Server│
- ┘ └────────┘ └─────────┘ └────────┘           │
- ┘
**┌─ Middleware Chain ──────────────────────────────────────┐**
- AccessList → RateLimit → Metrics → Cache → Resolver ... │
- ┘
**┌─ Core Services ───────────────────────────────────────┐**
- Cache Manager │ DNSSEC Validator │ Query Router       │
- ┘
**┌─ External Communication ────────────────────────────┐**
- Root Servers │ Fallback Servers │ Forwarders        │
- ┘

##### Component Relationships

- Query flow from clients through the system
- Cache read/write operations
- DNSSEC validation flow
- Middleware chain execution order
- External server communications

##### Technical Details

Annotations for:
- Port numbers (53, 853, 8053)
- Supported protocols (UDP, TCP, TLS, HTTPS, QUIC)
- Cache size limits
- Rate limiting thresholds
- Timeout values

##### Implementation Notes

- The middleware-based architecture (shown in middleware/ directory)
- The plugin system's extensibility
- Multiple server type support (shown in server/ directory)
- Cache implementation (shown in cache/ directory)
- Authentication and authorization flow (shown in authcache/ directory)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Clients
        DNS_C[DNS Clients]:::client
        DoT_C[DoT Clients]:::client
        DoH_C[DoH Clients]:::client
        DoQ_C[DoQ Clients]:::client
    end

    subgraph "Server Layer"
        DNS[DNS :53]:::server
        DoT[DoT :853]:::server
        DoH[DoH :8053]:::server
        DoQ[DoQ :853]:::server
        API[API Server]:::server
    end

    subgraph "Middleware Chain"
        direction TB
        M_Chain[Chain Manager]:::middleware
        Access[Access Control]:::middleware
        RateLimit[Rate Limit]:::middleware
        Metrics[Metrics]:::middleware
        Cache[Cache]:::middleware
        Resolver[Resolver]:::middleware
        EDNS[EDNS]:::middleware
        Failover[Failover]:::middleware
        Forward[Forwarder]:::middleware
    end

    subgraph "Core Services"
        CacheManager[Cache Manager]:::core
        DNSSEC[DNSSEC Validator]:::core
        QueryRouter[Query Router]:::core
        AuthServer[Auth Server]:::core
        NSCache[NS Cache]:::core
    end

    subgraph "External Communication"
        Root[Root Servers]:::external
        Fallback[Fallback Servers]:::external
        Forwarders[Forwarders]:::external
    end

    DNS_C --> DNS
    DoT_C --> DoT
    DoH_C --> DoH
    DoQ_C --> DoQ

    DNS & DoT & DoH & DoQ --> M_Chain

    M_Chain --> Access
    Access --> RateLimit
    RateLimit --> Metrics
    Metrics --> Cache
    Cache --> EDNS
    EDNS --> Resolver
    Resolver --> Failover
    Failover --> Forward

    Resolver --> DNSSEC
    Cache --> CacheManager
    DNSSEC --> Root
    Failover --> Fallback
    Forward --> Forwarders
    
    AuthServer --> NSCache

    classDef client fill:#6495ED
    classDef server fill:#4CAF50
    classDef middleware fill:#FFA500
    classDef core fill:#9C27B0
    classDef external fill:#FF5722

    click DoH "https://github.com/semihalev/sdns/tree/master/server/doh/"
    click DoQ "https://github.com/semihalev/sdns/tree/master/server/doq/"
    click DNS "https://github.com/semihalev/sdns/blob/master/server/server.go"
    click CacheManager "https://github.com/semihalev/sdns/tree/master/cache/"
    click AuthServer "https://github.com/semihalev/sdns/blob/master/authcache/authserver.go"
    click NSCache "https://github.com/semihalev/sdns/blob/master/authcache/ns_cache.go"
    click M_Chain "https://github.com/semihalev/sdns/blob/master/middleware/chain.go"
    click Access "https://github.com/semihalev/sdns/tree/master/middleware/accesslist/"
    click RateLimit "https://github.com/semihalev/sdns/tree/master/middleware/ratelimit/"
    click Metrics "https://github.com/semihalev/sdns/tree/master/middleware/metrics/"
    click Resolver "https://github.com/semihalev/sdns/tree/master/middleware/resolver/"
    click EDNS "https://github.com/semihalev/sdns/tree/master/middleware/edns/"
    click Failover "https://github.com/semihalev/sdns/tree/master/middleware/failover/"
    click Forward "https://github.com/semihalev/sdns/tree/master/middleware/forwarder/"
    click DNSSEC "https://github.com/semihalev/sdns/blob/master/middleware/resolver/resolver.go"
    click API "https://github.com/semihalev/sdns/blob/master/api/api.go"
    click Cache "https://github.com/semihalev/sdns/tree/master/middleware/cache/"
```
