# minpeter/iplogger architecture

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

- Interactive diagram: https://gitdiagram.com/minpeter/iplogger
- Repository: https://github.com/minpeter/iplogger

## Overview

##### Main Components

a) Web Service Layer
- HTTP Server (Go-based)
- Template Engine (using .gohtml files)
- Request Handler (main.go)

b) Core Logic Modules
- IP Detection Module (pkg/ip)
- User Agent Parser (pkg/useragent)

c) External Interfaces
- Reverse Proxy Layer(s)
- Client Browsers/Curl Clients

**[Client Layer]**
- ↓ HTTP/HTTPS
**[Reverse Proxy Layer(s)]**
- ↓ Forwarded Headers
**[Application Layer]**
- Web Server (main.go)
- Template Engine
- index.gohtml
- detail.gohtml
- Core Modules
- IP Detection
- UserAgent Parser

##### Implementation Details to Highlight

- Docker containerization (show container boundary)
- Port mapping (10000:10000)
- Template rendering flow
- IP detection logic flow

Top Section:
- External clients (browsers, curl)
- Reverse proxy layers

Middle Section:
- Main application container
- Web server component

Bottom Section:
- Core logic modules
- Template engine

##### Additional Elements

- Notes about key configuration points
- Environment boundaries (container vs. host)
- Logging points

##### The containerized nature of the deployment

Keep the focus on the IP detection and logging aspects while maintaining enough detail to show how the service handles various proxy configurations. This is crucial for understanding how the service achieves its primary purpose of accurate client IP logging behind reverse proxies.

Remember to include version information and any relevant environment variables or configuration options that affect the IP logging behavior.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Clients
        Browser["Web Browser"]:::client
        Curl["Curl Client"]:::client
    end

    %% Proxy Layer
    subgraph "Proxy Infrastructure"
        RP1["Primary Reverse Proxy"]:::proxy
        RP2["Secondary Reverse Proxy"]:::proxy
    end

    %% Application Container
    subgraph "Docker Container"
        direction TB
        WebServer["HTTP Server (main.go)"]:::server
        click WebServer "https://github.com/minpeter/iplogger/blob/main/main.go"

        subgraph "Core Components"
            direction TB
            IPModule["IP Detection Module"]:::core
            click IPModule "https://github.com/minpeter/iplogger/blob/main/pkg/ip/ip.go"
            UAParser["User Agent Parser"]:::core
            click UAParser "https://github.com/minpeter/iplogger/blob/main/pkg/useragent/useragent.go"
        end

        subgraph "Template Engine"
            direction TB
            TemplateEngine["Template Processor"]:::template
            click TemplateEngine "https://github.com/minpeter/iplogger/tree/main/templates/"
            IndexTemplate["Index Template"]:::template
            click IndexTemplate "https://github.com/minpeter/iplogger/blob/main/templates/index.gohtml"
            DetailTemplate["Detail Template"]:::template
            click DetailTemplate "https://github.com/minpeter/iplogger/blob/main/templates/detail.gohtml"
        end

        Config["Container Config"]:::config
        click Config "https://github.com/minpeter/iplogger/tree/main/Dockerfile"
        Orchestration["Docker Compose"]:::config
        click Orchestration "https://github.com/minpeter/iplogger/blob/main/docker-compose.yml"
    end

    %% Documentation and CI/CD
    Documentation["Documentation"]:::docs
    click Documentation "https://github.com/minpeter/iplogger/blob/main/docs/result.md"
    CICD["CI/CD Pipeline"]:::cicd
    click CICD "https://github.com/minpeter/iplogger/blob/main/.github/workflows/ghr-image-bp.yml"

    %% Relationships
    Browser --> RP1
    Curl --> RP1
    RP1 --> RP2
    RP2 --> WebServer
    WebServer --> IPModule
    WebServer --> UAParser
    WebServer --> TemplateEngine
    TemplateEngine --> IndexTemplate
    TemplateEngine --> DetailTemplate
    Config -.- WebServer
    Orchestration -.- Config

    %% Styles
    classDef client fill:#6495ED,stroke:#333,stroke-width:2px
    classDef proxy fill:#FFA500,stroke:#333,stroke-width:2px
    classDef server fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef template fill:#98FB98,stroke:#333,stroke-width:2px
    classDef config fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef docs fill:#E6E6FA,stroke:#333,stroke-width:2px
    classDef cicd fill:#F0E68C,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Client"]:::client
        L2["Proxy"]:::proxy
        L3["Server"]:::server
        L4["Core Logic"]:::core
        L5["Templates"]:::template
        L6["Configuration"]:::config
        L7["Documentation"]:::docs
        L8["CI/CD"]:::cicd
    end
```
