# ptlc8/apache-docker-proxy architecture

> Architecture diagram of the GitHub repository ptlc8/apache-docker-proxy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ptlc8/apache-docker-proxy
- Repository: https://github.com/ptlc8/apache-docker-proxy

## Overview

##### Main Components

a) Docker Environment Layer:
- Container labels (show as metadata attached to containers)
- Docker socket connection

b) Config Generator Component:
- Config generator container
- Templates directory
- docker-gen process
- config.toml configuration
- Apache2 template processor

c) HTTP Daemon Layer:
- Apache2 server container
- Generated configuration files
- Static files server

##### Flow and Relationships

- Docker socket → Config Generator (watching for container events)
- Config Generator → Apache2 Configuration (writing generated configs)
- Apache2 → External Traffic (handling incoming requests)
- Container Labels → Config Generator (input for configuration)
- Environment Variables → Config Generator (global settings)

##### Key Elements to Highlight

- Blue containers for Docker components

##### Specific Details

a) Configuration Sources:
- Environment Variables
- TOPDOMAIN
- HTTP_PORT
- HTDOCS_DIRECTORY
- Other env vars...

- Container Labels
- webproxy.subdomain
- webproxy.path
- webproxy.port
- Other labels...

b) Processing Flow:
1. Container Event Detection
2. Label Processing
3. Template Rendering
4. Config Generation
5. Apache2 Reload

##### Important Notes

- Template mechanism (apache2.tmpl)
- Static file serving capability
- Demonstrate the proxy paths and subdomain routing
- SSL/HTTPS redirect mechanism
- Error page handling

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Docker["Docker Environment"]
        DC[("Docker Socket")]
        C1["Container 1"]
        C2["Container 2"]
        C3["Container N"]
    end

    subgraph ConfigGen["Configuration Generator"]
        CG["Config Generator Container"]:::container
        TM["Template Mechanism"]
        DGP["docker-gen Process"]
        CFG["config.toml"]
        TPL["Apache2 Template"]
    end

    subgraph Apache["HTTP Daemon Layer"]
        AP["Apache2 Server"]:::container
        GC["Generated Configs"]
        SF["Static Files Server"]
    end

    subgraph Inputs["Configuration Sources"]
        direction TB
        EV["Environment Variables"]
        CL["Container Labels"]
        subgraph EVars["Environment Variables"]
            TD["TOPDOMAIN"]
            HP["HTTP_PORT"]
            HD["HTDOCS_DIRECTORY"]
        end
        subgraph CLabs["Container Labels"]
            SD["webproxy.subdomain"]
            PT["webproxy.path"]
            PP["webproxy.port"]
        end
    end

    DC --> DGP
    C1 & C2 & C3 --> CL
    CL --> CG
    EV --> CG
    DGP --> TM
    TM --> TPL
    TPL --> GC
    GC --> AP
    SF --> AP

    classDef container fill:#b3d9ff,stroke:#3385ff
    classDef config fill:#ffe6b3,stroke:#ffc34d
    classDef flow fill:#b3ffb3,stroke:#4dff4d

    click CG "https://github.com/ptlc8/apache-docker-proxy/tree/master/config-generator/Dockerfile"
    click CFG "https://github.com/ptlc8/apache-docker-proxy/blob/master/config-generator/config.toml"
    click TPL "https://github.com/ptlc8/apache-docker-proxy/blob/master/config-generator/templates/apache2.tmpl"
    click AP "https://github.com/ptlc8/apache-docker-proxy/tree/master/http-daemon/Dockerfile"
    click SF "https://github.com/ptlc8/apache-docker-proxy/tree/master/html/"
    click DC "https://github.com/ptlc8/apache-docker-proxy/blob/master/compose.yaml"

    subgraph Legend
        L1["Container"]:::container
        L2["Configuration"]:::config
        L3["Data Flow"]:::flow
    end
```
