|
| 1 | +# CLAUDE.md — ComfyUI Workflow Templates Monorepo |
| 2 | + |
| 3 | +## What This Repo Is |
| 4 | + |
| 5 | +A monorepo managing **ComfyUI workflow templates** distributed as Python packages AND a public **Astro-based workflow hub website** at templates.comfy.org. Two distinct systems share the same template data. |
| 6 | + |
| 7 | +## Repository Map |
| 8 | + |
| 9 | +``` |
| 10 | +workflow_templates/ |
| 11 | +├── templates/ # SOURCE OF TRUTH: workflow JSONs, thumbnails, index metadata |
| 12 | +│ ├── index.json # Master template metadata (English) |
| 13 | +│ ├── index.{locale}.json # 11 locale variants (zh, ja, ko, es, fr, ru, tr, ar, pt-BR, zh-TW) |
| 14 | +│ ├── *.json # ComfyUI workflow definitions |
| 15 | +│ └── *-1.webp, *-2.webp # Template thumbnails |
| 16 | +├── blueprints/ # Reusable subgraph blueprint definitions |
| 17 | +├── bundles.json # Maps template names → Python package bundles |
| 18 | +├── blueprints_bundles.json # Maps blueprint names → package |
| 19 | +├── packages/ # Python distribution packages (Nx monorepo) |
| 20 | +│ ├── core/ # Loader + manifest |
| 21 | +│ ├── media_api/ # API-calling templates (Replicate, BFL, etc.) |
| 22 | +│ ├── media_image/ # Image generation templates |
| 23 | +│ ├── media_video/ # Video generation templates |
| 24 | +│ ├── media_other/ # Audio, 3D, utilities |
| 25 | +│ ├── meta/ # Meta package aggregating all above |
| 26 | +│ └── blueprints/ # Subgraph blueprints package |
| 27 | +├── scripts/ # Python: validation, sync, i18n |
| 28 | +├── site/ # INDEPENDENT Astro 5 project (see "Site" section below) |
| 29 | +├── docs/ # Specs, i18n guide, publishing guide |
| 30 | +├── .claude/skills/ # 6 Claude skill definitions |
| 31 | +├── .github/workflows/ # CI/CD (validation, deploy, lint, tests) |
| 32 | +├── pyproject.toml # Python project version & config |
| 33 | +├── package.json # Nx monorepo root (npm run sync, etc.) |
| 34 | +└── nx.json # Nx workspace config |
| 35 | +``` |
| 36 | + |
| 37 | +## Two Distinct Systems |
| 38 | + |
| 39 | +### System 1: Template Packages (Python/PyPI) |
| 40 | +- Templates are grouped into 4 media bundles via `bundles.json` |
| 41 | +- `scripts/sync_bundles.py` copies templates + thumbnails into package directories |
| 42 | +- Published to PyPI as `comfyui-workflow-templates-*` packages |
| 43 | +- Version lives in root `pyproject.toml` (currently 0.8.43) |
| 44 | + |
| 45 | +### System 2: Astro Website (`site/`) |
| 46 | +- **Independent project** — own `package.json`, `pnpm-lock.yaml`, tooling |
| 47 | +- Consumes templates from `../templates/` via sync scripts |
| 48 | +- AI content generation pipeline (GPT-4o) enriches template pages |
| 49 | +- Deployed to Vercel |
| 50 | + |
| 51 | +## Data Flow |
| 52 | + |
| 53 | +``` |
| 54 | +templates/index.json + *.json + *.webp |
| 55 | + ├──→ scripts/sync_bundles.py ──→ packages/media_*/ |
| 56 | + └──→ site/scripts/sync-templates.ts ──→ site/src/content/templates/ |
| 57 | + └──→ site/scripts/generate-ai.ts ──→ AI-enriched content |
| 58 | + └──→ astro build ──→ templates.comfy.org (Vercel) |
| 59 | +``` |
| 60 | + |
| 61 | +## Key Commands |
| 62 | + |
| 63 | +### Root (template management) |
| 64 | +```bash |
| 65 | +npm run sync # Sync bundle manifests + assets to packages |
| 66 | +python scripts/validate_templates.py # Validate template JSON |
| 67 | +python scripts/sync_data.py --templates-dir templates # Sync i18n translations |
| 68 | +``` |
| 69 | + |
| 70 | +### Site (in site/ directory) |
| 71 | +```bash |
| 72 | +pnpm install # Install deps (required first) |
| 73 | +pnpm run dev # Dev server at localhost:4321 |
| 74 | +pnpm run build # Full build (prebuild + astro build) |
| 75 | +pnpm run sync # Sync templates from ../templates/ |
| 76 | +pnpm run sync -- --top-50 # Sync top 50 only (faster dev) |
| 77 | +pnpm run generate:ai # AI content generation (needs OPENAI_API_KEY) |
| 78 | +pnpm run generate:ai -- --skip-ai # Use placeholder content (no API key needed) |
| 79 | +pnpm run lint # ESLint |
| 80 | +pnpm run format # Prettier |
| 81 | +pnpm run test:e2e # Playwright E2E tests |
| 82 | +``` |
| 83 | + |
| 84 | +## Template Structure |
| 85 | + |
| 86 | +### index.json Entry |
| 87 | +Each template in `templates/index.json` has: |
| 88 | +- `name` — Must match the JSON filename (snake_case, no extension) |
| 89 | +- `title`, `description` — Display metadata |
| 90 | +- `mediaType` — "image" | "video" | "audio" | "3d" |
| 91 | +- `mediaSubtype` — Usually "webp" |
| 92 | +- `thumbnailVariant` — "compareSlider" | "hoverDissolve" | "hoverZoom" | "zoomHover" | null |
| 93 | +- `tags`, `models`, `logos`, `date`, `usage`, `size`, `vram`, `searchRank` |
| 94 | +- `tutorialUrl`, `openSource`, `requiresCustomNodes`, `io` |
| 95 | + |
| 96 | +### Workflow JSON Files |
| 97 | +Standard ComfyUI workflow format with embedded model metadata: |
| 98 | +- `properties.models[]` — Download URLs, SHA256 hashes, target directories |
| 99 | +- `properties.cnr_id` + `properties.ver` — Node version pinning |
| 100 | + |
| 101 | +### Thumbnails |
| 102 | +- Named `{template_name}-1.webp` (primary), `{template_name}-2.webp` (comparison) |
| 103 | +- WebP format, target <1MB, 512×512 or 768×768 |
| 104 | + |
| 105 | +## Bundle Assignment |
| 106 | +Templates in `bundles.json` map to Python packages: |
| 107 | +| Bundle | Contents | |
| 108 | +|--------|----------| |
| 109 | +| `media-api` | Templates using external APIs | |
| 110 | +| `media-image` | Image generation/editing | |
| 111 | +| `media-video` | Video generation | |
| 112 | +| `media-other` | Audio, 3D, utilities | |
| 113 | + |
| 114 | +## Internationalization |
| 115 | + |
| 116 | +### 11 Supported Languages |
| 117 | +en (default), zh, zh-TW, ja, ko, es, fr, ru, tr, ar, pt-BR |
| 118 | + |
| 119 | +### Template i18n |
| 120 | +- Master: `templates/index.json` (English) |
| 121 | +- Locales: `templates/index.{locale}.json` |
| 122 | +- Translation tracking: `scripts/i18n.json` |
| 123 | +- Sync: `python scripts/sync_data.py --templates-dir templates` |
| 124 | + |
| 125 | +### Site i18n |
| 126 | +- Config: `site/src/i18n/config.ts` |
| 127 | +- UI strings: `site/src/i18n/ui.ts` |
| 128 | +- URL pattern: English at `/templates/`, others at `/{locale}/templates/` |
| 129 | +- SEO: Hreflang tags via `HreflangTags.astro` |
| 130 | + |
| 131 | +## Site Architecture (Astro 5) |
| 132 | + |
| 133 | +### Key Directories |
| 134 | +- `site/src/pages/` — Route pages ([slug].astro, [locale]/templates/) |
| 135 | +- `site/src/components/` — Astro components (TemplateCard, TemplateDetailPage, etc.) |
| 136 | +- `site/src/lib/` — Utilities (templates.ts, urls.ts, slugify.ts, model-logos.ts) |
| 137 | +- `site/src/content/` — Content collections (git-ignored, generated by sync) |
| 138 | +- `site/scripts/` — Build scripts (sync, AI generation, previews, OG images) |
| 139 | +- `site/knowledge/` — AI generation context (prompts, model docs, concepts) |
| 140 | +- `site/overrides/templates/` — Human-edited content (survives AI regeneration) |
| 141 | + |
| 142 | +### AI Content Pipeline |
| 143 | +1. `sync-templates.ts` syncs metadata from `../templates/` |
| 144 | +2. `generate-ai.ts` calls GPT-4o with context from `knowledge/` |
| 145 | +3. Generates: extendedDescription, howToUse[], metaDescription, suggestedUseCases[], faqItems[] |
| 146 | +4. Content templates: tutorial (default), showcase, comparison, breakthrough |
| 147 | +5. Cached in `.content-cache/` with hash-based invalidation |
| 148 | +6. Human overrides in `site/overrides/templates/{name}.json` (set `humanEdited: true`) |
| 149 | + |
| 150 | +### Critical Site Components (DO NOT remove/modify without care) |
| 151 | +- `SEOHead.astro` — Meta tags, structured data |
| 152 | +- `HreflangTags.astro` — i18n SEO |
| 153 | +- `t()` calls, `localizeUrl()` — i18n functions |
| 154 | +- `<Analytics />` — Telemetry |
| 155 | + |
| 156 | +## CI/CD |
| 157 | + |
| 158 | +### Template Validation (triggers on templates/ changes) |
| 159 | +- `validate-templates.yml` — JSON schema validation |
| 160 | +- `validate-blueprints.yml` — Blueprint validation |
| 161 | +- `validate-manifests.yml` — Manifest sync check |
| 162 | +- `link-checker.yml` — Model download URL validation |
| 163 | + |
| 164 | +### Site (triggers on site/ changes) |
| 165 | +- `lint-site.yml` — ESLint + Prettier |
| 166 | +- `e2e-tests-site.yml` — Playwright tests |
| 167 | +- `visual-regression-site.yml` — Visual regression |
| 168 | +- `seo-audit-site.yml` — SEO audit |
| 169 | +- `lighthouse.yml` — Performance checks |
| 170 | +- `deploy-site.yml` — Manual Vercel deploy |
| 171 | + |
| 172 | +## Code Style |
| 173 | +- **Python**: Ruff, line-length 100, py312, rules E/F |
| 174 | +- **TypeScript/Astro**: ESLint + Prettier (configured in site/) |
| 175 | +- **Templates**: snake_case naming, JSON format |
| 176 | +- **Commits**: Bump version in `pyproject.toml` when modifying templates |
| 177 | + |
| 178 | +## Claude Skills Available |
| 179 | +- `/adding-templates` — Add new workflow templates (full workflow) |
| 180 | +- `/managing-bundles` — Move templates between bundles, reorder |
| 181 | +- `/managing-thumbnails` — Add/replace/audit thumbnails |
| 182 | +- `/managing-translations` — Sync/check translations across 11 languages |
| 183 | +- `/editing-site-content` — Edit site page content with overrides |
| 184 | +- `/regenerating-ai-content` — Regenerate AI descriptions, manage cache |
| 185 | + |
| 186 | +## Important Docs |
| 187 | +- `docs/SPEC.md` — Formal template JSON schema |
| 188 | +- `docs/BLUEPRINTS.md` — Subgraph blueprint spec |
| 189 | +- `docs/I18N_GUIDE.md` — Translation management workflow |
| 190 | +- `site/docs/PRD.md` — Product requirements for the site |
| 191 | +- `site/docs/TDD.md` — Technical design document |
| 192 | +- `site/docs/design-integration-guide.md` — REQUIRED when implementing Figma designs |
0 commit comments