# bogdan-95/content-factory-console architecture

> Architecture diagram of the GitHub repository bogdan-95/content-factory-console, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bogdan-95/content-factory-console
- Repository: https://github.com/bogdan-95/content-factory-console

## Overview

Content Factory Console is a FastAPI-backed image-generation service: a client submits validated generation parameters, the API queues a job in PostgreSQL, and a background worker claims it, runs an SDXL workflow through ComfyUI, then records status and output filename. Clients poll job status/result and retrieve the generated image through the protected files endpoint. The README also documents health checks, API-key/rate-limit security, horizontal worker scaling, and Docker-hosted ComfyUI with automatic model preparation. Unsampled ComfyUI, deployment, and preflight wiring is represented only where the README supports it.

Main entry points: [`api/app/routers/jobs.py`](https://github.com/bogdan-95/content-factory-console/blob/main/api/app/routers/jobs.py) (Status and result routes), [`api/app/main.py`](https://github.com/bogdan-95/content-factory-console/blob/main/api/app/main.py) (FastAPI app), [`api/app/routers/generate.py`](https://github.com/bogdan-95/content-factory-console/blob/main/api/app/routers/generate.py) (Submit generation), [`api/app/routers/files.py`](https://github.com/bogdan-95/content-factory-console/blob/main/api/app/routers/files.py) (Image file route)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_entry["FastAPI app<br/>[main.py]"]
  node_security["API key and limits<br/>[security.py]"]
  node_generate["Submit generation<br/>[generate.py]"]
  node_schemas["Request and response schemas<br/>[schemas.py]"]
  node_health["Health route<br/>[health.py]"]
end

subgraph group_queue["Job lifecycle"]
  node_job_service["Job queries<br/>[jobs.py]"]
  node_api_db["API database sessions<br/>[db.py]"]
  node_postgres[("PostgreSQL jobs and results")]
  node_worker["Job worker<br/>[worker.py]"]
  node_worker_db["Worker database sessions<br/>[db.py]"]
end

subgraph group_generation["Image generation"]
  node_worker_settings["Worker settings<br/>[settings.py]"]
  node_workflow["SDXL workflow template<br/>[base_sdxl_api.json]"]
  node_comfy_client["ComfyUI HTTP client<br/>[comfy_client.py]"]
  node_comfyui["ComfyUI renderer"]
  node_preflight["Model preparation<br/>[preflight.py]"]
end

subgraph group_delivery["Result delivery"]
  node_jobs_router["Status and result routes<br/>[jobs.py]"]
  node_files_router["Image file route<br/>[files.py]"]
  node_output["Generated image files"]
end

node_client(("API client"))

node_client -->|"sends HTTP"| node_entry
node_entry -->|"routes requests"| node_generate
node_entry -->|"routes requests"| node_jobs_router
node_entry -->|"routes requests"| node_files_router
node_entry -->|"routes requests"| node_health
node_generate -->|"validates with"| node_schemas
node_generate -->|"checks key"| node_security
node_generate -->|"creates job"| node_job_service
node_generate -->|"gets session"| node_api_db
node_job_service -->|"writes and reads"| node_postgres
node_worker -->|"claims and updates"| node_worker_db
node_worker_db -->|"reads and writes"| node_postgres
node_worker -->|"loads template"| node_workflow
node_worker -->|"submits and polls"| node_comfy_client
node_comfy_client -->|"sends workflow"| node_comfyui
node_comfyui -->|"returns history"| node_comfy_client
node_worker -->|"uses settings"| node_worker_settings
node_jobs_router -->|"checks key"| node_security
node_jobs_router -->|"reads job result"| node_job_service
node_jobs_router -->|"gets session"| node_api_db
node_jobs_router -->|"returns file URL"| node_files_router
node_files_router -->|"checks key"| node_security
node_files_router -->|"serves image"| node_output
node_client -->|"polls status"| node_jobs_router
node_client -->|"downloads image"| node_files_router
node_comfyui -.->|"saves image"| node_output
node_preflight -.->|"prepares models"| node_comfyui

click node_entry "https://github.com/bogdan-95/content-factory-console/blob/main/api/app/main.py"
click node_security "https://github.com/bogdan-95/content-factory-console/blob/main/api/app/security.py"
click node_generate "https://github.com/bogdan-95/content-factory-console/blob/main/api/app/routers/generate.py"
click node_schemas "https://github.com/bogdan-95/content-factory-console/blob/main/api/app/schemas.py"
click node_job_service "https://github.com/bogdan-95/content-factory-console/blob/main/api/app/services/jobs.py"
click node_api_db "https://github.com/bogdan-95/content-factory-console/blob/main/api/app/db.py"
click node_worker "https://github.com/bogdan-95/content-factory-console/blob/main/worker/app/worker.py"
click node_worker_db "https://github.com/bogdan-95/content-factory-console/blob/main/worker/app/db.py"
click node_worker_settings "https://github.com/bogdan-95/content-factory-console/blob/main/worker/app/settings.py"
click node_workflow "https://github.com/bogdan-95/content-factory-console/blob/main/worker/app/workflow_templates/base_sdxl_api.json"
click node_comfy_client "https://github.com/bogdan-95/content-factory-console/blob/main/worker/app/comfy_client.py"
click node_jobs_router "https://github.com/bogdan-95/content-factory-console/blob/main/api/app/routers/jobs.py"
click node_files_router "https://github.com/bogdan-95/content-factory-console/blob/main/api/app/routers/files.py"
click node_health "https://github.com/bogdan-95/content-factory-console/blob/main/api/app/routers/health.py"
click node_preflight "https://github.com/bogdan-95/content-factory-console/blob/main/scripts/preflight.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_security,node_generate,node_schemas,node_health,node_client toneBlue
class node_job_service,node_api_db,node_postgres,node_worker,node_worker_db toneAmber
class node_worker_settings,node_workflow,node_comfy_client,node_comfyui,node_preflight toneMint
class node_jobs_router,node_files_router,node_output toneRose
```

## Components

### API and access

- [FastAPI app](https://github.com/bogdan-95/content-factory-console/blob/main/api/app/main.py): `api/app/main.py`
- [API key and limits](https://github.com/bogdan-95/content-factory-console/blob/main/api/app/security.py): `api/app/security.py`
- [Submit generation](https://github.com/bogdan-95/content-factory-console/blob/main/api/app/routers/generate.py): `api/app/routers/generate.py`
- [Request and response schemas](https://github.com/bogdan-95/content-factory-console/blob/main/api/app/schemas.py): `api/app/schemas.py`
- [Health route](https://github.com/bogdan-95/content-factory-console/blob/main/api/app/routers/health.py): `api/app/routers/health.py`

### Job lifecycle

- [Job queries](https://github.com/bogdan-95/content-factory-console/blob/main/api/app/services/jobs.py): `api/app/services/jobs.py`
- [API database sessions](https://github.com/bogdan-95/content-factory-console/blob/main/api/app/db.py): `api/app/db.py`
- **PostgreSQL jobs and results**
- [Job worker](https://github.com/bogdan-95/content-factory-console/blob/main/worker/app/worker.py): `worker/app/worker.py`
- [Worker database sessions](https://github.com/bogdan-95/content-factory-console/blob/main/worker/app/db.py): `worker/app/db.py`

### Image generation

- [Worker settings](https://github.com/bogdan-95/content-factory-console/blob/main/worker/app/settings.py): `worker/app/settings.py`
- [SDXL workflow template](https://github.com/bogdan-95/content-factory-console/blob/main/worker/app/workflow_templates/base_sdxl_api.json): `worker/app/workflow_templates/base_sdxl_api.json`
- [ComfyUI HTTP client](https://github.com/bogdan-95/content-factory-console/blob/main/worker/app/comfy_client.py): `worker/app/comfy_client.py`
- **ComfyUI renderer**
- [Model preparation](https://github.com/bogdan-95/content-factory-console/blob/main/scripts/preflight.py): `scripts/preflight.py`

### Result delivery

- [Status and result routes](https://github.com/bogdan-95/content-factory-console/blob/main/api/app/routers/jobs.py): `api/app/routers/jobs.py`
- [Image file route](https://github.com/bogdan-95/content-factory-console/blob/main/api/app/routers/files.py): `api/app/routers/files.py`
- **Generated image files**

### Other components

- **API client**

## Connections

- API client → FastAPI app: sends HTTP (evidence: `README.md`)
- FastAPI app → Submit generation: routes requests (evidence: `api/app/main.py`)
- FastAPI app → Status and result routes: routes requests (evidence: `api/app/main.py`)
- FastAPI app → Image file route: routes requests (evidence: `api/app/main.py`)
- FastAPI app → Health route: routes requests (evidence: `api/app/main.py`)
- Submit generation → Request and response schemas: validates with (evidence: `api/app/routers/generate.py`)
- Submit generation → API key and limits: checks key (evidence: `api/app/routers/generate.py`)
- Submit generation → Job queries: creates job (evidence: `api/app/routers/generate.py`)
- Submit generation → API database sessions: gets session (evidence: `api/app/routers/generate.py`)
- Job queries → PostgreSQL jobs and results: writes and reads (evidence: `api/app/services/jobs.py`)
- Job worker → Worker database sessions: claims and updates (evidence: `worker/app/worker.py`)
- Worker database sessions → PostgreSQL jobs and results: reads and writes
- Job worker → SDXL workflow template: loads template (evidence: `worker/app/worker.py`)
- Job worker → ComfyUI HTTP client: submits and polls (evidence: `worker/app/worker.py`)
- ComfyUI HTTP client → ComfyUI renderer: sends workflow (evidence: `README.md`)
- ComfyUI renderer → ComfyUI HTTP client: returns history (evidence: `README.md`)
- Job worker → Worker settings: uses settings (evidence: `worker/app/worker.py`)
- Status and result routes → API key and limits: checks key (evidence: `api/app/routers/jobs.py`)
- Status and result routes → Job queries: reads job result (evidence: `api/app/routers/jobs.py`)
- Status and result routes → API database sessions: gets session (evidence: `api/app/routers/jobs.py`)
- Status and result routes → Image file route: returns file URL (evidence: `api/app/routers/jobs.py`)
- Image file route → API key and limits: checks key (evidence: `api/app/routers/files.py`)
- Image file route → Generated image files: serves image (evidence: `api/app/routers/files.py`)
- API client → Status and result routes: polls status (evidence: `README.md`)
- API client → Image file route: downloads image (evidence: `README.md`)
- ComfyUI renderer → Generated image files: saves image
- Model preparation → ComfyUI renderer: prepares models (evidence: `README.md`)
