# luler/reflex_ai_fast architecture

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

- Interactive diagram: https://gitdiagram.com/luler/reflex_ai_fast
- Repository: https://github.com/luler/reflex_ai_fast

## Overview

##### Project type and purpose
- This is a full-stack web application for “one-click” image generation powered by large language/image models (OpenAI).
- The frontend is a static JS/CSS bundle (exported via Reflex) stored in `frontend.zip`.
- The backend is a Python service (`image_gen_page`) exposing API endpoints that proxy requests to the large-model API.
- An Nginx reverse proxy sits in front to serve static assets and route API calls.

##### File structure
- Top-level Docker and Compose files:
- Dockerfile (build Python backend)
- Dockerfile-nginx (configure Nginx)
- docker-compose.yml (orchestrates nginx + backend)
- config/nginx.conf (routing rules)
- Frontend:
- `frontend.zip` (Reflex export of the UI)
- assets/ (if unzipped assets are placed here)
- Backend:
- image_gen_page/ (Python package)
– image_gen_page.py (server startup & routes)
– pages/ (handlers for GPT4o, JimEng endpoints)
- requirements.txt (dependencies)
- rxconfig.py (Reflex configuration for export)
- Environment:
- `.env` (not in repo; user must create with OPENAI_BASE_URL and OPENAI_API_KEY)
- Deployment:
- .dockerignore, .gitignore, .github/workflows/docker-image.yml

##### Extract README insights
- Two-step install:
1. `reflex export --frontend-only` to produce `frontend.zip`.
2. `docker-compose up -d` to launch nginx + backend.
- The frontend makes API calls to `API_URL` (127.0.0.1:8080).
- Access via HTTP port 8080.

##### Main components & interactions
a. Components
- Client (Browser)
- Nginx Reverse Proxy container
- Backend Python container (image_gen_page service)
- External LLM/Image generation API (OpenAI)
b. Data flows
1. User opens `http://host:8080/` → Browser GET served by Nginx static root from `frontend.zip`.
2. In-page JS UI sends HTTP POST to `/api/generate` (or similar) on same host.
3. Nginx forwards `/api/*` to the Python backend container.
4. Backend handlers (in image_gen_page/pages) receive request, read prompt, call external model API (OPENAI_BASE_URL + OPENAI_API_KEY).
5. External API returns image or URL → backend returns JSON/image data to client.
6. Browser displays the result.
c. Architectural patterns & principles
- Separation of concerns: static UI vs dynamic API
- Reverse proxy pattern with Nginx (static + API routing)
- Micro-service style (one backend service + one proxy)
- Environment-based configuration (via .env)
d. Key technologies
- Reflex (Python → static frontend export)
- FastAPI/Flask (likely used in image_gen_page)
- Docker & Docker-Compose
- Nginx
- OpenAI API (external service)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Browser["Browser"]:::client

    %% Docker-Compose Group
    subgraph "Docker-Compose"
        direction TB

        subgraph "Nginx Container"
            direction TB
            Nginx["Nginx Reverse Proxy"]:::proxy
            FrontendZip["frontend.zip"]:::static
            Assets["assets/"]:::static
            Config["nginx.conf"]:::config
            DfileNginx["Dockerfile-nginx"]:::config
        end

        subgraph "Backend Container"
            direction TB
            Backend["Python Backend Service"]:::backend
            ImageGenPkg["image_gen_page/"]:::code
            Startup["image_gen_page.py"]:::code
            GPT4o["gpt4o.py"]:::code
            JimEng["jimeng.py"]:::code
            Req["requirements.txt"]:::config
            Env[".env"]:::config
            Dfile["Dockerfile"]:::config
        end

        Compose["docker-compose.yml"]:::config
    end

    %% External Service
    External["OpenAI API (External)"]:::external

    %% File & Config
    Rx["rxconfig.py"]:::config
    CI[".github/workflows/docker-image.yml"]:::config

    %% Flows
    Browser -->|HTTP GET /| Nginx
    Nginx -->|serves| FrontendZip
    Nginx -->|serves| Assets

    Browser -->|HTTP POST /api/*| Nginx
    Nginx -->|proxy /api| Backend
    Backend -->|calls HTTPS| External
    External -->|response| Backend
    Backend -->|JSON/image| Nginx
    Nginx -->|response| Browser

    %% Click Events
    click FrontendZip "https://github.com/luler/reflex_ai_fast/blob/master/frontend.zip"
    click Assets "https://github.com/luler/reflex_ai_fast/tree/master/assets/"
    click Config "https://github.com/luler/reflex_ai_fast/blob/master/config/nginx.conf"
    click DfileNginx "https://github.com/luler/reflex_ai_fast/tree/master/Dockerfile-nginx"
    click Compose "https://github.com/luler/reflex_ai_fast/blob/master/docker-compose.yml"
    click Dfile "https://github.com/luler/reflex_ai_fast/tree/master/Dockerfile"
    click ImageGenPkg "https://github.com/luler/reflex_ai_fast/tree/master/image_gen_page/"
    click Startup "https://github.com/luler/reflex_ai_fast/blob/master/image_gen_page/image_gen_page.py"
    click GPT4o "https://github.com/luler/reflex_ai_fast/blob/master/image_gen_page/pages/gpt4o.py"
    click JimEng "https://github.com/luler/reflex_ai_fast/blob/master/image_gen_page/pages/jimeng.py"
    click Req "https://github.com/luler/reflex_ai_fast/blob/master/requirements.txt"
    click Env "https://github.com/luler/reflex_ai_fast/blob/master/.env"
    click Rx "https://github.com/luler/reflex_ai_fast/blob/master/rxconfig.py"
    click CI "https://github.com/luler/reflex_ai_fast/blob/master/.github/workflows/docker-image.yml"

    %% Styles
    classDef client fill:#FFD580,stroke:#E59400,color:#000;
    classDef proxy fill:#80C0FF,stroke:#3399FF,color:#000;
    classDef backend fill:#C8A2C8,stroke:#A040A0,color:#000;
    classDef static fill:#B0E57C,stroke:#6DA34D,color:#000;
    classDef code fill:#FFF2CC,stroke:#D6B656,color:#000;
    classDef config fill:#E0E0E0,stroke:#A0A0A0,color:#000;
    classDef external fill:#FFB3B3,stroke:#FF6666,color:#000
```
