# mbrubeck/agate architecture

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

- Interactive diagram: https://gitdiagram.com/mbrubeck/agate
- Repository: https://github.com/mbrubeck/agate

## Overview

##### Main Components Identification
The system should be represented with these key components:

a) Server Core
- TLS Handler (supports TLS 1.2 and 1.3)
- Request Handler
- Virtual Host Manager
- Certificate Manager

b) File System Interface
- Static Content Server
- Directory Listing Handler
- Meta Configuration Parser

c) Security Layer
- Certificate Generation/Management
- Access Control

**[Client Layer]**
- ↓
**[TLS/Security Layer]**
- ↓
**[Server Core Layer]**
- ↓
**[File System Layer]**

##### Component Relationships

**[Gemini Client] → [TLS Handler]**
- ↓
**[Certificate Manager] ← [Virtual Host Manager] → [Request Handler]**
- ↓
- [Meta Config Parser] ← [Static Content Server]
- ↓
- [File System Interface]

##### Important Details

a) Input/Output flows:
- Gemini requests (gemini://) coming from clients
- File system paths for content serving
- Certificate/key paths (.certificates directory)
- Configuration files (.meta)

b) Key Features:
- Virtual hosting support
- Directory listing capability
- Meta-configuration system
- Automatic certificate generation

##### Technical Specifications

Technical details:
- Port: 1965 (standard Gemini port)
- Supported TLS versions: 1.2, 1.3
- File formats: .gmi (Gemini), .der (certificates)
- Configuration files: .meta, .directory-listing-ok

##### Implementation Notes

Notes about:
- Rust async runtime usage
- Static file serving optimization
- Certificate loading and caching
- Language-specific content negotiation

Remember to maintain a balance between showing the high-level architecture and including important implementation details that affect the system's behavior, such as the certificate management system and virtual hosting capabilities.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        GC[Gemini Client]
    end

    subgraph Security
        TLS[TLS Handler]
        CM[Certificate Manager]:::cert
        click CM "https://github.com/mbrubeck/agate/blob/master/src/certificates.rs"
    end

    subgraph Core
        VH[Virtual Host Manager]:::vhost
        click VH "https://github.com/mbrubeck/agate/tree/master/tests/data/content/example.com/"
        RH[Request Handler]:::handler
        click RH "https://github.com/mbrubeck/agate/blob/master/src/codes.rs"
        SC[Server Core]:::core
        click SC "https://github.com/mbrubeck/agate/blob/master/src/main.rs"
    end

    subgraph "File System"
        SCS[Static Content Server]:::static
        click SCS "https://github.com/mbrubeck/agate/tree/master/content/"
        DL[Directory Listing Handler]:::dirlist
        click DL "https://github.com/mbrubeck/agate/tree/master/tests/data/dirlist/"
        MCP[Meta Configuration Parser]:::meta
        click MCP "https://github.com/mbrubeck/agate/blob/master/src/metadata.rs"
        FSI[File System Interface]
    end

    GC --> TLS
    TLS --> CM
    CM --> VH
    VH --> RH
    RH --> SC
    SC --> SCS
    SCS --> MCP
    MCP --> FSI
    FSI --> DL

    %% Certificate Storage
    CS[(Certificate Storage)]:::certstorage
    click CS "https://github.com/mbrubeck/agate/tree/master/tests/data/.certificates/"
    CM --- CS

    %% Meta Config Storage
    MS[(Meta Config)]:::metaconfig
    click MS "https://github.com/mbrubeck/agate/blob/master/tests/data/content/.meta"
    MCP --- MS

    %% Language Content
    LC[(Language Content)]:::lang
    click LC "https://github.com/mbrubeck/agate/blob/master/tests/data/content/testdir/a.{de,nl,gmi}"
    SCS --- LC

    %% Styles
    classDef cert fill:#f00,stroke:#333,stroke-width:2px
    classDef vhost fill:#09f,stroke:#333,stroke-width:2px
    classDef handler fill:#09f,stroke:#333,stroke-width:2px
    classDef core fill:#09f,stroke:#333,stroke-width:2px
    classDef static fill:#0f0,stroke:#333,stroke-width:2px
    classDef dirlist fill:#0f0,stroke:#333,stroke-width:2px
    classDef meta fill:#ff0,stroke:#333,stroke-width:2px
    classDef certstorage fill:#f00,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
    classDef metaconfig fill:#ff0,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
    classDef lang fill:#0f0,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5

    %% Legend
    subgraph Legend
        N1[Network/Protocol]:::handler
        N2[File System]:::static
        N3[Security]:::cert
        N4[Configuration]:::meta
    end
```
