Skip to content

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 SQLAlchemy Base, applied via an integrated create_all() + ddl/*.sql bootstrap 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 against cms-api's admin API plus one exercised content-upsert path.
  • generation/providers/ -- a TextProvider registry with a stub-by-default ClaudeProvider (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 harvester ai_accounts rows directly over a separate read-only SQLAlchemy engine (secret /{env}/mysql/skynet-harvester -- a different schema than the forge DB, same host on stage), via CALL get_all_active_ai_accounts() with a plain-SELECT fallback. Caches the {account_id: row} map; no harvester-service call. In test/local it never touches a DB (an injectable fake map).
  • generation/providers/openai.py + openai_image.py -- OpenAIProvider (text, default gpt-4o) and OpenAIImageProvider (images, default gpt-image-1), ported from the harvester open_ai.py. Credentials come from the ai_accounts rows at call time (keyed by account_id), never stored. The image provider normalizes the dual-shape response ({"url"} / {"b64"}) to bytes and can also fetch a brief's source_url (media migration).
  • generation/providers/claude.py -- resolves its key from /common/cms-ai-forge/anthropic inside 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 via ai_content_ledger, ContentCreate + image-brief output) and ImageGenerator (generate/fetch + upload one asset via MediaPublisher).
  • generation/sources/ -- three article-source strategies feeding the same publish path: ai_generate (default), wp_import (WordPress -> CMS; MySQL primary + REST fallback, HTML -> content_blocks via generation/converters.py), and cms_copy (CMS -> CMS). Migration folded in; the AISD-95 direct-cms_db load/ layer is NOT reused.
  • workers/ -- planner intents single_article / wp_import / cms_copy (plus existing article_batch); the entity worker spawns one image child per brief at an article's validated -> assets_ready step 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.py sends the full ContentCreate (with the required author_id), lands a draft, then conditionally PATCHes {"status": "published"}, and writes a ai_content_ledger row.

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.