ignitionstack.pro v1.0 is out! Read the announcement →
Skip to Content

AI Runtime Architecture

Ignitionstack ships a first-class conversational assistant. This page documents how the code inside src/app/actions/ai and src/app/lib/ai works today so you can safely extend providers, routing rules, or storage models.

High-Level Flow

Server Actions

ActionPathResponsibilities
sendMessagesrc/app/actions/ai/send-message.tsOrchestrates validation, auth (requireAuth), conversation lifecycle, routing, provider execution, persistence, and usage logging.
create-conversation, delete-conversation, update-conversationsrc/app/actions/ai/*.tsCRUD for conversations and stored preferences (system prompt, temperature, provider overrides).
save-api-key, delete-api-keyManage per-user API keys once we allow bring-your-own-provider flows.

Every AI action returns an ActionResult object so UI callers can branch on success without guesswork.

Persistence Layer

Repositories map Supabase rows to domain objects through the mappers under src/app/lib/mappers. They never return raw JSON; for example src/app/lib/mappers/conversation.ts normalizes camelCase fields and attaches friendly enums.

Routing & Provider Selection

StrategyRouter

src/app/lib/ai/router/strategy-router.ts implements the IStrategyRouter interface and scores every available model by:

ProviderFactory & CircuitBreaker

Tooling & RAG

Data Model Snapshot

TableRepositoryNotes
ai_conversationsConversationRepositoryStores user ownership, provider defaults, system prompt, and UI metadata.
ai_messagesMessageRepositoryCaptures both user and assistant roles plus token/cost metadata for billing.
ai_models / ai_providersAIRepositoryFeature flags per plan tier, latency/cost hints, quotas.

Supabase migrations for these tables live in supabase/migrations/*. Each migration enables RLS and policies that ensure users can only touch their own conversations/messages.

Extending the AI Stack

  1. Add a provider – Implement the AIProvider interface under src/app/lib/ai/providers, register it in ProviderFactory, and document capability/cost/latency in StrategyRouter.
  2. Tune routing heuristics – Adjust MODEL_CAPABILITIES, MODEL_LATENCY, or scoring weights inside strategy-router.ts. Every change should be backed by unit tests in src/app/actions/ai/__tests__ and routing tests under src/app/lib/ai/router/__tests__.
  3. Add conversational metadata – Update repositories plus the relevant Supabase migration. Remember to expose mapper changes so presentation components receive the new fields.
  4. Wire UI controls – Client components in src/app/components/chat call the server actions via progressive enhancement. Make sure new parameters are validated in sendMessageSchema (src/app/lib/validations/ai.ts).

Observability & Safeguards

Keeping this architecture in sync with the actual code makes it far easier to reason about AI regressions. When you touch any of the components above, update this page and link to the relevant ADR under content/architecture.