Overview / Backend
Layer 1 · Complete & deployed

The ClinicIQ backend

A FastAPI application that takes an expert from onboarding, through a knowledge base, into a single conversational agent (IQ) that can build apps, write content, and ship them live. This is the engine — and it's running in production.

Production · healthy Python 3.12 · FastAPI · Postgres 45+ agent tools

Architecture at a glance

One agent, every capability behind it

The user only ever talks to IQ. IQ routes across modes and reaches into a registry of tools — onboarding, knowledge, builders, and the MIOSA infrastructure — then streams results back over SSE.

User surface
IQ chat (SSE streaming)file uploadscheckpoints
Orchestrator
IQAgentmode: chatmode: buildmode: writemode: onboarding
Tool registry
onboardingknowledgebuildersbuild/sandboxartifactsdraftingmediaorchestration
Services
offerQA checkpointavatar / FALknowledge indexpublishing
Data & jobs
Postgres (async)Redis + ARQ workersS3 / TigrisPinecone
Infra (MIOSA)
sandboxespreviewdeploymanaged DBdomains

The major flows

What the backend actually does

Six pipelines carry the product. Each is implemented, wired into IQ's tools, and exercised in the end-to-end tests.

Onboarding pipeline

Session → expert dossier → offer stack → context profile → avatar (FAL portraits) → QA checkpoint → engine selection → handoff. State-machine driven, with editable section revisions and progress tracking.

Knowledge base

Sources (files / URLs / pasted text) → async extraction (pypdf, docx) → embeddings → Pinecone, with custom retrieval rules and a manual review checkpoint. IQ retrieves from it via tools.

IQ agent

One conversational agent, four modes, 45+ tools auto-discovered across the codebase. Streams over SSE with ticket-based auth. Grounded in the knowledge base and foundation docs.

Content builders

Website, webinar, email, sales script/letter, ad creative, content, podcast, lead magnet, funnel, program. Outputs stored as versioned artifacts; exportable to Markdown / HTML / PDF.

MIOSA integration

Create sandboxes, write files, exec, expose previews, publish releases, deploy to *.cliniciq.com, provision managed databases and storage — all workspace-scoped.

Multi-channel publishing

Email (Resend / Mailchimp), social (Ayrshare), landing pages with custom domains + DNS verification. Background-job dispatched per target.

API surface

Key endpoints by domain

DomainRepresentative endpointsPurpose
AuthPOST /auth/login · /register · /google/login · /refreshJWT + Google OAuth, Argon2id, RBAC roles
OnboardingPOST /onboarding/session · /offer · /qa-checkpoint · GET /handoffExpert setup state machine
KnowledgePOST /knowledge/sources · GET /knowledge/documents · /rulesIndex + retrieve expert knowledge
IQPOST /iq/chat · /iq/sse-ticket · /iq/upload-filesConversational agent, streaming
BuildersPOST /builders/{website|webinar|email|funnel|…}Generate content artifacts
MIOSAPOST /miosa/sandboxes · /expose · /deploy · /databasesInfra: sandbox, preview, deploy, data
ArtifactsGET /artifacts/{id} · /export · /htmlBuilder output management + render
App projectsPOST /app-projects · /files · /diff · /deploySandbox-backed app lifecycle
PublishPOST /publish/schedule · POST /domains · /verifyMulti-channel + custom domains

Stack & conventions

Built to be maintained

Language / framework
Python 3.12, FastAPI (async), Uvicorn
Data
SQLAlchemy 2.0 (asyncpg) · Alembic migrations · Pydantic v2 DTOs
Jobs
ARQ + Redis (graceful inline fallback in dev)
AI
Anthropic Claude · Pinecone embeddings · FAL (images) · Deepgram (voice)
Integrations
Stripe · Mailchimp · Ayrshare · Resend · Unipile · Gamma · Google OAuth
Module pattern
Every feature follows a 6-layer shape: model · schema · repo · service · dependencies · controller
Quality gate
Ruff lint/format · pytest · pre-commit + pre-push hooks

In flight right now

The work I'm finishing as I write this

These are the uncommitted changes on my machine — the final pass on agent rendering and output quality before you pull. This is the "refine the outputs" work, mid-stride.

# backend-cliniciq · uncommitted (working tree)
 M app/agents/orchestrator/_llm_loop.py        // agent loop tuning
 M app/agents/orchestrator/runner.py           // streaming + render hook
 M app/agents/orchestrator/prompt_context.py   // prompt grounding
 M app/agents/meta_agents/artifact_renderer.py // output rendering
 M app/agents/tools/build/build_app.py         // IQ builds + previews
 M app/agents/tools/build/deploy_artifact.py   // deploy path
 M app/agents/tools/drafting/draft_landing.py  // landing output quality
 … + ad/email/post/content drafting + artifact create/update

# recently shipped
68e1f8a Scope sandbox preview exposure by workspace
b448337 wire build_app so IQ can build and preview through its own tools
3c25419 ground IQ in foundation docs, stop re-onboarding completed experts
cd84dc0 harden artifact renderer: detached serve, idempotency, premium slides