Architecture¶
The forge is a standalone FastAPI + Celery service that generates website
entities and publishes them through the cms-api admin block using a
persisted state machine for durable, idempotent execution.
Full design lives in the workspace architecture doc for the CMS AI generation pipeline (epic AISD-148): components (control plane, Celery/RabbitMQ workers, generation core, publishers), the request envelope, the job/task state machine, the provider abstraction, the publishing adapters, and the forge-owned MySQL schema.
Phase 1a (AISD-150, this repo's bootstrap) ships the core plumbing only:
control_plane/--POST /jobs,GET /jobs/{id}, SSE events, task retry.datastore/-- the 8 forge-owned tables on a single SQLAlchemyBase, applied via an integratedcreate_all()+ddl/*.sqlbootstrap hook (no Alembic).state_machine/-- guarded transitions, an append-only transition log, and a retry beat.workers/-- Celery app bound to RabbitMQ, one queue per entity type, a generic "advance one transition" worker with a stub generator seam.publishing/cms_publisher.py-- auth againstcms-api's admin API plus one exercised content-upsert path.generation/providers/-- aTextProviderregistry with a stub-by-defaultClaudeProvider(Anthropic SDK path gated behind config).
Per-entity generators, image providers, media publishing, and the
site_scaffold orchestration chain are deferred to AISD-151+ (Phase 1b).
Phase 2 -- Articles + media loop (AISD-152)¶
Phase 2 fills the styled shell with real content: an article-generation + media loop that publishes only through cms-api.
generation/ai_accounts.py-- reads the harvesterai_accountsrows directly over a separate read-only SQLAlchemy engine (secret/{env}/mysql/skynet-harvester-- a different schema than the forge DB, same host on stage), viaCALL get_all_active_ai_accounts()with a plain-SELECTfallback. Caches the{account_id: row}map; no harvester-service call. Intest/localit never touches a DB (an injectable fake map).generation/providers/openai.py+openai_image.py--OpenAIProvider(text, defaultgpt-4o) andOpenAIImageProvider(images, defaultgpt-image-1), ported from the harvesteropen_ai.py. Credentials come from theai_accountsrows at call time (keyed byaccount_id), never stored. The image provider normalizes the dual-shape response ({"url"}/{"b64"}) to bytes and can also fetch a brief'ssource_url(media migration).generation/providers/claude.py-- resolves its key from/common/cms-ai-forge/anthropicinside a try/except; a missing/inaccessible key returns a stubbed "key not provided" result instead of raising, so the forge never crashes when the (code-gen-only) Claude key is absent.generation/generators/article.py+image.py--ArticleGenerator(validators, uniqueness/avoidance viaai_content_ledger,ContentCreate+ image-brief output) andImageGenerator(generate/fetch + upload one asset viaMediaPublisher).generation/sources/-- three article-source strategies feeding the same publish path:ai_generate(default),wp_import(WordPress -> CMS; MySQL primary + REST fallback, HTML ->content_blocksviageneration/converters.py), andcms_copy(CMS -> CMS). Migration folded in; the AISD-95 direct-cms_dbload/layer is NOT reused.workers/-- planner intentssingle_article/wp_import/cms_copy(plus existingarticle_batch); the entity worker spawns oneimagechild per brief at an article'svalidated -> assets_readystep and dispatches them as a Celery chord whose callback (finalize_article_assets) wires the featured + inline images onto the article and re-enqueues its publish;publish.pysends the fullContentCreate(with the requiredauthor_id), lands a draft, then conditionallyPATCHes{"status": "published"}, and writes aai_content_ledgerrow.
Idempotency / resume: the ai_content_ledger (dedup by (site_ref, title_hash))
and the slug-matched, client-side-paged GET /admin/v1/content lookup mean a
re-run makes no duplicate content; guarded transitions + the children-pending
gate let a worker killed mid-article resume to completion.