# jeromeleong/poe2openai architecture

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

- Interactive diagram: https://gitdiagram.com/jeromeleong/poe2openai
- Repository: https://github.com/jeromeleong/poe2openai

## Overview

- HTTP/API Server: Represented by src/main.rs, which initializes and runs the web server. This component listens on a specified port (default 8080) and routes incoming HTTP requests.
- POE Client Interface: The src/poe_client.rs acts as the adapter module that translates and forwards requests to the underlying Poe API. This is a key integration point.
- Shared Components and Utilities: Include components like src/types.rs and src/utils.rs that define core data models and helper functions used throughout.
- Static Assets and Templates: The static folder (with assets like tailwind.js and fontawesome.css) and the templates folder (e.g., admin.html) denote the resources used for the web admin user interface. Indicate that these are served by the HTTP server for configuration management.
- Docker/Deployment Context: Highlight that a Dockerfile is used for containerizing the entire application and note the existence of Cargo.toml as the build/dependency file for the Rust project.

##### Relationships and Data Flow
- Client Request Flow: Show an external client (or web browser) sending HTTP requests which first hit the HTTP/API server.
- Internal Routing: Map out how the HTTP server dispatches different requests:
- Chat requests to chat.rs (possibly invoking the POE client to interact with the actual POE API).
- Model listing and admin requests to the admin and models handlers.
- Static file requests served from the static folder.

##### Architectural Patterns and Technologies
- Separation of Concerns: Divide the system into clear areas—managing API endpoints (handlers), external API communication (poe_client), and static content serving (for the admin UI).
- Modularization: Emphasize how each module (or file) handles a distinct responsibility. This reduces coupling and increases maintainability.
- Containerization: Indicate that the entire application is built with Rust and containerized using Docker, enabling easy deployment and scalability.
- Environment-driven Configuration: Note the use of environment variables to control settings such as PORT, ADMIN_USERNAME, ADMIN_PASSWORD, etc., as explained in the README.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client("Client (Web Browser)"):::external

    %% API Server Layer
    subgraph "API Server Layer"
        HTTP_Server("HTTP Server (main.rs)"):::server
    end

    %% Route Handlers
    subgraph "Route Handlers"
        Admin("Admin Handler (admin.rs)"):::handler
        Chat("Chat Handler (chat.rs)"):::handler
        CORS("CORS Handler (cors.rs)"):::handler
        Models("Models Handler (models.rs)"):::handler
    end

    %% Integration Module
    subgraph "Integration Modules"
        POE_Client("POE Client (poe_client.rs)"):::integration
    end

    %% Shared Components and Utilities
    subgraph "Shared Components"
        Types("Types (types.rs)"):::utility
        Utils("Helpers (utils.rs)"):::utility
    end

    %% Frontend & UI
    subgraph "Frontend & UI"
        Static("Static Assets"):::ui
        Template("Template (admin.html)"):::ui
    end

    %% Deployment
    subgraph "Deployment"
        Dockerfile("Dockerfile"):::deployment
        CargoToml("Cargo.toml"):::deployment
    end

    %% Connections
    Client -->|"HTTPRequest"| HTTP_Server

    HTTP_Server -->|"RoutesTo"| Admin
    HTTP_Server -->|"RoutesTo"| Chat
    HTTP_Server -->|"RoutesTo"| CORS
    HTTP_Server -->|"RoutesTo"| Models
    HTTP_Server -->|"Serves"| Static

    Admin -->|"Loads"| Template
    Chat -->|"Calls"| POE_Client

    %% Shared Components usage (illustrative)
    HTTP_Server ---|"Uses"| Types
    HTTP_Server ---|"Uses"| Utils
    Chat ---|"Uses"| Utils
    Admin ---|"Uses"| Types

    %% Deployment connection (containerizes)
    Dockerfile ---|"Containerizes"| HTTP_Server
    CargoToml ---|"Containerizes"| HTTP_Server

    %% Click Events
    click HTTP_Server "https://github.com/jeromeleong/poe2openai/blob/master/src/main.rs"
    click Admin "https://github.com/jeromeleong/poe2openai/blob/master/src/handlers/admin.rs"
    click Chat "https://github.com/jeromeleong/poe2openai/blob/master/src/handlers/chat.rs"
    click CORS "https://github.com/jeromeleong/poe2openai/blob/master/src/handlers/cors.rs"
    click Models "https://github.com/jeromeleong/poe2openai/blob/master/src/handlers/models.rs"
    click POE_Client "https://github.com/jeromeleong/poe2openai/blob/master/src/poe_client.rs"
    click Types "https://github.com/jeromeleong/poe2openai/blob/master/src/types.rs"
    click Utils "https://github.com/jeromeleong/poe2openai/blob/master/src/utils.rs"
    click Static "https://github.com/jeromeleong/poe2openai/tree/master/static/"
    click Template "https://github.com/jeromeleong/poe2openai/blob/master/templates/admin.html"
    click Dockerfile "https://github.com/jeromeleong/poe2openai/tree/master/Dockerfile"
    click CargoToml "https://github.com/jeromeleong/poe2openai/blob/master/Cargo.toml"

    %% Styles
    classDef server fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef handler fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef integration fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef utility fill:#e2e3e5,stroke:#41464b,stroke-width:2px;
    classDef ui fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef deployment fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef external fill:#fefefe,stroke:#6c757d,stroke-width:2px;
```
