# san-mark/comiccraft architecture

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

- Interactive diagram: https://gitdiagram.com/san-mark/comiccraft
- Repository: https://github.com/san-mark/comiccraft

## Overview

ComicCraft is a FastAPI application for turning a user’s comic prompt into a five-panel story, illustrated panels, a preview, and a downloadable PDF. Its main workflow is orchestrated by the generation route, which validates input and calls the outline, story, image, layout, and export stages. The graph also shows the separate image-provider integrations and file outputs. Source excerpts establish these backend relationships; template contents were not sampled, so UI interactions beyond route rendering are not inferred.

Main entry points: [`app/routes.py`](https://github.com/san-mark/comiccraft/blob/main/app/routes.py) (Generation routes), [`app/services/image_generator.py`](https://github.com/san-mark/comiccraft/blob/main/app/services/image_generator.py) (Panel image generation), [`app/services/exporters.py`](https://github.com/san-mark/comiccraft/blob/main/app/services/exporters.py) (PDF exporter), [`app/config.py`](https://github.com/san-mark/comiccraft/blob/main/app/config.py) (Settings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_routes["Generation routes<br/>[routes.py]"]
  node_app["FastAPI app<br/>[main.py]"]
  node_config["Settings<br/>[config.py]"]
  node_schemas["Prompt and story schemas<br/>[schemas.py]"]
  node_templates["HTML templates"]
end

subgraph group_story["Story generation"]
  node_outline["Outline generation<br/>[gemini_flash.py]"]
  node_storygen["Story generation<br/>[gemini_pro.py]"]
end

subgraph group_art["Illustration"]
  node_imagegen["Panel image generation<br/>[image_generator.py]"]
  node_storageutil["Filename and URL helpers<br/>[storage.py]"]
  node_panelstore[("Panel image files")]
end

subgraph group_output["Layout and export"]
  node_layout["Comic layout builder<br/>[layout_builder.py]"]
  node_exporter["PDF exporter<br/>[exporters.py]"]
  node_exports[("PDF files")]
end

node_user(("Comic creator"))
node_gemini{{"Google Gemini API"}}
node_hf{{"Hugging Face inference"}}
node_diffusers{{"Diffusers pipeline"}}

node_user -->|"submits prompt"| node_routes
node_app -->|"registers routes"| node_routes
node_routes -->|"renders pages"| node_templates
node_routes -->|"validates input"| node_schemas
node_routes -->|"requests outline"| node_outline
node_outline -->|"generates outline"| node_gemini
node_routes -->|"expands story"| node_storygen
node_storygen -->|"generates story"| node_gemini
node_routes -->|"requests panel images"| node_imagegen
node_imagegen -->|"generates images"| node_hf
node_imagegen -->|"generates images"| node_diffusers
node_imagegen -->|"names image files"| node_storageutil
node_imagegen -->|"writes images"| node_panelstore
node_routes -->|"builds layout"| node_layout
node_layout -->|"reads story panels"| node_schemas
node_routes -->|"exports layout"| node_exporter
node_exporter -->|"reads panel images"| node_panelstore
node_exporter -->|"writes PDF"| node_exports
node_app -->|"serves static files"| node_panelstore
node_app -->|"serves PDF files"| node_exports
node_outline -->|"reads settings"| node_config
node_storygen -->|"reads settings"| node_config
node_imagegen -->|"reads settings"| node_config
node_exporter -->|"reads settings"| node_config

click node_routes "https://github.com/san-mark/comiccraft/blob/main/app/routes.py"
click node_app "https://github.com/san-mark/comiccraft/blob/main/app/main.py"
click node_config "https://github.com/san-mark/comiccraft/blob/main/app/config.py"
click node_schemas "https://github.com/san-mark/comiccraft/blob/main/app/schemas.py"
click node_templates "https://github.com/san-mark/comiccraft/tree/main/templates"
click node_outline "https://github.com/san-mark/comiccraft/blob/main/app/services/gemini_flash.py"
click node_storygen "https://github.com/san-mark/comiccraft/blob/main/app/services/gemini_pro.py"
click node_imagegen "https://github.com/san-mark/comiccraft/blob/main/app/services/image_generator.py"
click node_storageutil "https://github.com/san-mark/comiccraft/blob/main/app/utils/storage.py"
click node_panelstore "https://github.com/san-mark/comiccraft/tree/main/static/panels"
click node_layout "https://github.com/san-mark/comiccraft/blob/main/app/services/layout_builder.py"
click node_exporter "https://github.com/san-mark/comiccraft/blob/main/app/services/exporters.py"
click node_exports "https://github.com/san-mark/comiccraft/tree/main/exports"

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_routes,node_app,node_config,node_schemas,node_templates,node_diffusers toneBlue
class node_outline,node_storygen toneAmber
class node_imagegen,node_storageutil,node_panelstore,node_gemini toneMint
class node_layout,node_exporter,node_exports toneRose
class node_user,node_hf toneIndigo
```

## Components

### Web application

- [Generation routes](https://github.com/san-mark/comiccraft/blob/main/app/routes.py): `app/routes.py`
- [FastAPI app](https://github.com/san-mark/comiccraft/blob/main/app/main.py): `app/main.py`
- [Settings](https://github.com/san-mark/comiccraft/blob/main/app/config.py): `app/config.py`
- [Prompt and story schemas](https://github.com/san-mark/comiccraft/blob/main/app/schemas.py): `app/schemas.py`
- [HTML templates](https://github.com/san-mark/comiccraft/tree/main/templates): `templates`

### Story generation

- [Outline generation](https://github.com/san-mark/comiccraft/blob/main/app/services/gemini_flash.py): `app/services/gemini_flash.py`
- [Story generation](https://github.com/san-mark/comiccraft/blob/main/app/services/gemini_pro.py): `app/services/gemini_pro.py`

### Illustration

- [Panel image generation](https://github.com/san-mark/comiccraft/blob/main/app/services/image_generator.py): `app/services/image_generator.py`
- [Filename and URL helpers](https://github.com/san-mark/comiccraft/blob/main/app/utils/storage.py): `app/utils/storage.py`
- [Panel image files](https://github.com/san-mark/comiccraft/tree/main/static/panels): `static/panels`

### Layout and export

- [Comic layout builder](https://github.com/san-mark/comiccraft/blob/main/app/services/layout_builder.py): `app/services/layout_builder.py`
- [PDF exporter](https://github.com/san-mark/comiccraft/blob/main/app/services/exporters.py): `app/services/exporters.py`
- [PDF files](https://github.com/san-mark/comiccraft/tree/main/exports): `exports`

### Other components

- **Comic creator**
- **Google Gemini API**
- **Hugging Face inference**
- **Diffusers pipeline**

## Connections

- Comic creator → Generation routes: submits prompt (evidence: `app/routes.py`)
- FastAPI app → Generation routes: registers routes (evidence: `app/main.py`)
- Generation routes → HTML templates: renders pages (evidence: `app/routes.py`)
- Generation routes → Prompt and story schemas: validates input (evidence: `app/routes.py`)
- Generation routes → Outline generation: requests outline (evidence: `app/routes.py`)
- Outline generation → Google Gemini API: generates outline (evidence: `app/services/gemini_flash.py`)
- Generation routes → Story generation: expands story (evidence: `app/routes.py`)
- Story generation → Google Gemini API: generates story (evidence: `app/services/gemini_pro.py`)
- Generation routes → Panel image generation: requests panel images (evidence: `app/routes.py`)
- Panel image generation → Hugging Face inference: generates images (evidence: `app/services/image_generator.py`)
- Panel image generation → Diffusers pipeline: generates images (evidence: `app/services/image_generator.py`)
- Panel image generation → Filename and URL helpers: names image files (evidence: `app/services/image_generator.py`)
- Panel image generation → Panel image files: writes images (evidence: `app/services/image_generator.py`)
- Generation routes → Comic layout builder: builds layout (evidence: `app/routes.py`)
- Comic layout builder → Prompt and story schemas: reads story panels (evidence: `app/services/layout_builder.py`)
- Generation routes → PDF exporter: exports layout (evidence: `app/routes.py`)
- PDF exporter → Panel image files: reads panel images (evidence: `app/services/exporters.py`)
- PDF exporter → PDF files: writes PDF (evidence: `app/services/exporters.py`)
- FastAPI app → Panel image files: serves static files (evidence: `app/main.py`)
- FastAPI app → PDF files: serves PDF files (evidence: `app/main.py`)
- Outline generation → Settings: reads settings (evidence: `app/services/gemini_flash.py`)
- Story generation → Settings: reads settings (evidence: `app/services/gemini_pro.py`)
- Panel image generation → Settings: reads settings (evidence: `app/services/image_generator.py`)
- PDF exporter → Settings: reads settings (evidence: `app/services/exporters.py`)
