# shenzili/comfyui-gallery architecture

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

- Interactive diagram: https://gitdiagram.com/shenzili/comfyui-gallery
- Repository: https://github.com/shenzili/comfyui-gallery

## Overview

ArtMirror is a local-first ComfyUI image and prompt asset manager, also runnable as a standalone web app. Users browse and organize local images, search and filter by folders/tags/prompts, inspect embedded workflow metadata, and optionally use configured AI services for translation, prompt interrogation, rating, and workflow parsing. The backend scans folders into SQLite references and metadata, while thumbnails are cached separately. The graph includes the documented gallery and AI capabilities; several route details are unsampled, so only indexed or documented connections are shown.

Main entry points: [`artmirror/main.py`](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/main.py) (FastAPI app), [`artmirror/services/scanner.py`](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/services/scanner.py) (Folder scanner), [`artmirror/database.py`](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/database.py) (SQLite access), [`artmirror/routers/compress.py`](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/routers/compress.py) (Image compression)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["App entry points"]
  node_standalone["Standalone launcher<br/>[main.py]"]
  node_plugin_routes["Plugin routes<br/>[routes.py]"]
  node_plugin_embed["Embedded server<br/>[embed.py]"]
  node_app["FastAPI app<br/>[main.py]"]
end

subgraph group_gallery["Gallery experience"]
  node_web_tab["ComfyUI gallery tab<br/>[artmirror-tab.js]"]
  node_frontend["Gallery UI<br/>[app.js]"]
  node_api["API client<br/>[api.js]"]
  node_image_routes["Image browsing<br/>[images.py]"]
  node_aggregate["Aggregate browsing<br/>[aggregate.py]"]
  node_folder_routes["Folder management<br/>[folders.py]"]
  node_tag_routes["Tag filters<br/>[tags.py]"]
end

subgraph group_ingest["Scanning and metadata"]
  node_scan_tasks["Scan coordinator<br/>[scan_tasks.py]"]
  node_scanner["Folder scanner<br/>[scanner.py]"]
  node_parser["Workflow parser<br/>[comfyui_parser.py]"]
  node_meta["Metadata ingestion<br/>[meta_service.py]"]
end

subgraph group_services["AI and operations"]
  node_settings_routes["Settings and scans<br/>[settings.py]"]
  node_watcher["Background watcher<br/>[watcher.py]"]
  node_llm["AI capabilities<br/>[llm.py]"]
  node_compress_routes["Image compression<br/>[compress.py]"]
  node_compress["Compression service<br/>[compress.py]"]
end

subgraph group_storage["Persistent data"]
  node_database[("SQLite access<br/>[database.py]")]
  node_models["Asset data models<br/>[models.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

node_user(("Gallery user"))
node_comfyui["ComfyUI host"]

node_user -->|"opens gallery"| node_web_tab
node_user -->|"browses assets"| node_frontend
node_comfyui -->|"hosts extension"| node_plugin_routes
node_plugin_routes -->|"routes requests"| node_plugin_embed
node_plugin_embed -->|"starts app"| node_app
node_standalone -->|"creates app"| node_app
node_app -->|"registers routes"| node_image_routes
node_app -->|"registers routes"| node_aggregate
node_app -->|"registers routes"| node_folder_routes
node_app -->|"registers routes"| node_tag_routes
node_app -->|"registers routes"| node_settings_routes
node_app -->|"registers routes"| node_compress_routes
node_app -->|"starts watcher"| node_watcher
node_app -->|"initializes database"| node_database
node_frontend -.->|"uses client"| node_api
node_api -->|"calls backend"| node_app
node_settings_routes -->|"requests scans"| node_scan_tasks
node_settings_routes -->|"manages roots"| node_scanner
node_settings_routes -->|"tests providers"| node_llm
node_watcher -->|"schedules scans"| node_scan_tasks
node_scan_tasks -->|"runs scans"| node_scanner
node_scanner -->|"parses workflows"| node_parser
node_scanner -->|"ingests metadata"| node_meta
node_parser -->|"provides parse result"| node_meta
node_scanner -->|"updates assets"| node_database
node_meta -->|"writes metadata"| node_models
node_database -->|"creates schema"| node_models
node_image_routes -->|"queries assets"| node_database
node_image_routes -->|"reads metadata"| node_meta
node_image_routes -->|"requests AI actions"| node_llm
node_aggregate -->|"queries assets"| node_database
node_folder_routes -->|"manages folder roots"| node_scanner
node_folder_routes -->|"bumps sync"| node_watcher
node_tag_routes -->|"queries tags"| node_database
node_compress_routes -->|"invokes compression"| node_compress
node_compress_routes -->|"refreshes scan state"| node_scanner
node_compress_routes -->|"bumps sync"| node_watcher
node_compress_routes -->|"requests scans"| node_scan_tasks
node_config -->|"configures database path"| node_database

click node_standalone "https://github.com/shenzili/comfyui-gallery/blob/main/launchers/web/main.py"
click node_plugin_routes "https://github.com/shenzili/comfyui-gallery/blob/main/comfyui/routes.py"
click node_plugin_embed "https://github.com/shenzili/comfyui-gallery/blob/main/comfyui/embed.py"
click node_app "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/main.py"
click node_web_tab "https://github.com/shenzili/comfyui-gallery/blob/main/web/artmirror-tab.js"
click node_frontend "https://github.com/shenzili/comfyui-gallery/blob/main/frontend/app.js"
click node_api "https://github.com/shenzili/comfyui-gallery/blob/main/frontend/api.js"
click node_image_routes "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/routers/images.py"
click node_aggregate "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/routers/aggregate.py"
click node_folder_routes "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/routers/folders.py"
click node_tag_routes "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/routers/tags.py"
click node_settings_routes "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/routers/settings.py"
click node_scan_tasks "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/services/scan_tasks.py"
click node_scanner "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/services/scanner.py"
click node_parser "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/parsers/comfyui_parser.py"
click node_meta "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/services/meta_service.py"
click node_watcher "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/services/watcher.py"
click node_llm "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/services/llm.py"
click node_compress_routes "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/routers/compress.py"
click node_compress "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/services/compress.py"
click node_database "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/database.py"
click node_models "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/models.py"
click node_config "https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/config.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_standalone,node_plugin_routes,node_plugin_embed,node_app,node_user,node_comfyui toneBlue
class node_web_tab,node_frontend,node_api,node_image_routes,node_aggregate,node_folder_routes,node_tag_routes toneAmber
class node_scan_tasks,node_scanner,node_parser,node_meta toneMint
class node_settings_routes,node_watcher,node_llm,node_compress_routes,node_compress toneRose
class node_database,node_models,node_config toneIndigo
```

## Components

### App entry points

- [Standalone launcher](https://github.com/shenzili/comfyui-gallery/blob/main/launchers/web/main.py): `launchers/web/main.py`
- [Plugin routes](https://github.com/shenzili/comfyui-gallery/blob/main/comfyui/routes.py): `comfyui/routes.py`
- [Embedded server](https://github.com/shenzili/comfyui-gallery/blob/main/comfyui/embed.py): `comfyui/embed.py`
- [FastAPI app](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/main.py): `artmirror/main.py`

### Gallery experience

- [ComfyUI gallery tab](https://github.com/shenzili/comfyui-gallery/blob/main/web/artmirror-tab.js): `web/artmirror-tab.js`
- [Gallery UI](https://github.com/shenzili/comfyui-gallery/blob/main/frontend/app.js): `frontend/app.js`
- [API client](https://github.com/shenzili/comfyui-gallery/blob/main/frontend/api.js): `frontend/api.js`
- [Image browsing](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/routers/images.py): `artmirror/routers/images.py`
- [Aggregate browsing](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/routers/aggregate.py): `artmirror/routers/aggregate.py`
- [Folder management](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/routers/folders.py): `artmirror/routers/folders.py`
- [Tag filters](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/routers/tags.py): `artmirror/routers/tags.py`

### Scanning and metadata

- [Scan coordinator](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/services/scan_tasks.py): `artmirror/services/scan_tasks.py`
- [Folder scanner](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/services/scanner.py): `artmirror/services/scanner.py`
- [Workflow parser](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/parsers/comfyui_parser.py): `artmirror/parsers/comfyui_parser.py`
- [Metadata ingestion](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/services/meta_service.py): `artmirror/services/meta_service.py`

### AI and operations

- [Settings and scans](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/routers/settings.py): `artmirror/routers/settings.py`
- [Background watcher](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/services/watcher.py): `artmirror/services/watcher.py`
- [AI capabilities](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/services/llm.py): `artmirror/services/llm.py`
- [Image compression](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/routers/compress.py): `artmirror/routers/compress.py`
- [Compression service](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/services/compress.py): `artmirror/services/compress.py`

### Persistent data

- [SQLite access](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/database.py): `artmirror/database.py`
- [Asset data models](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/models.py): `artmirror/models.py`
- [Runtime configuration](https://github.com/shenzili/comfyui-gallery/blob/main/artmirror/config.py): `artmirror/config.py`

### Other components

- **Gallery user**
- **ComfyUI host**

## Connections

- Gallery user → ComfyUI gallery tab: opens gallery
- Gallery user → Gallery UI: browses assets
- ComfyUI host → Plugin routes: hosts extension
- Plugin routes → Embedded server: routes requests (evidence: `comfyui/routes.py`)
- Embedded server → FastAPI app: starts app (evidence: `comfyui/embed.py`)
- Standalone launcher → FastAPI app: creates app (evidence: `launchers/web/main.py`)
- FastAPI app → Image browsing: registers routes (evidence: `artmirror/main.py`)
- FastAPI app → Aggregate browsing: registers routes (evidence: `artmirror/main.py`)
- FastAPI app → Folder management: registers routes (evidence: `artmirror/main.py`)
- FastAPI app → Tag filters: registers routes (evidence: `artmirror/main.py`)
- FastAPI app → Settings and scans: registers routes (evidence: `artmirror/main.py`)
- FastAPI app → Image compression: registers routes (evidence: `artmirror/main.py`)
- FastAPI app → Background watcher: starts watcher (evidence: `artmirror/main.py`)
- FastAPI app → SQLite access: initializes database (evidence: `artmirror/main.py`)
- Gallery UI → API client: uses client
- API client → FastAPI app: calls backend
- Settings and scans → Scan coordinator: requests scans (evidence: `artmirror/routers/settings.py`)
- Settings and scans → Folder scanner: manages roots (evidence: `artmirror/routers/settings.py`)
- Settings and scans → AI capabilities: tests providers (evidence: `artmirror/routers/settings.py`)
- Background watcher → Scan coordinator: schedules scans (evidence: `artmirror/services/watcher.py`)
- Scan coordinator → Folder scanner: runs scans (evidence: `artmirror/services/scan_tasks.py`)
- Folder scanner → Workflow parser: parses workflows (evidence: `artmirror/services/scanner.py`)
- Folder scanner → Metadata ingestion: ingests metadata (evidence: `artmirror/services/scanner.py`)
- Workflow parser → Metadata ingestion: provides parse result (evidence: `artmirror/services/meta_service.py`)
- Folder scanner → SQLite access: updates assets (evidence: `artmirror/services/scanner.py`)
- Metadata ingestion → Asset data models: writes metadata (evidence: `artmirror/services/meta_service.py`)
- SQLite access → Asset data models: creates schema (evidence: `artmirror/database.py`)
- Image browsing → SQLite access: queries assets (evidence: `artmirror/routers/images.py`)
- Image browsing → Metadata ingestion: reads metadata (evidence: `artmirror/routers/images.py`)
- Image browsing → AI capabilities: requests AI actions (evidence: `artmirror/routers/images.py`)
- Aggregate browsing → SQLite access: queries assets (evidence: `artmirror/routers/aggregate.py`)
- Folder management → Folder scanner: manages folder roots (evidence: `artmirror/routers/folders.py`)
- Folder management → Background watcher: bumps sync (evidence: `artmirror/routers/folders.py`)
- Tag filters → SQLite access: queries tags (evidence: `artmirror/routers/tags.py`)
- Image compression → Compression service: invokes compression (evidence: `artmirror/routers/compress.py`)
- Image compression → Folder scanner: refreshes scan state (evidence: `artmirror/routers/compress.py`)
- Image compression → Background watcher: bumps sync (evidence: `artmirror/routers/compress.py`)
- Image compression → Scan coordinator: requests scans (evidence: `artmirror/routers/compress.py`)
- Runtime configuration → SQLite access: configures database path (evidence: `artmirror/database.py`)
