Skip to main content

Architecture overview

This overview describes the current runtime architecture of the web client and API platform.

Runtime architecture (request path)

Background pipeline architecture

Key runtime flows

1

Authenticated API request

The web client reads session tokens from client state, attaches Authorization: Bearer ..., and sends same-origin /api/* requests through a shared API client.
2

401 recovery policy

The frontend API client calls /api/auth/refresh once on 401 and retries the original request once. If refresh still fails, it clears local auth state and logs out.
3

Chat streaming path

POST /api/chat/send returns SSE. The frontend stream reader parses data: frames, while backend chat routes persist user/assistant messages and emit structured SSE envelopes.
4

Onboarding to background execution

Onboarding and integration actions enqueue task runs. Workers execute finance/KG/sync handlers and materialize data consumed by Money and Growth endpoints.

System components

Frontend shell

React + TanStack Query + Zustand state. Uses one API client for auth-aware fetches and SSE chat consumption.

API gateway

FastAPI app with centralized middleware, router composition, schema validation, and request-scoped identity enforcement.

Domain services

Chat orchestration (including v2 planner path), onboarding services, integration services, and prompt registry lifecycle.

Data + jobs

AsyncPG-backed reads/writes with background-job pipelines for metrics, actions, opportunities, reports, and integration sync state.

Component responsibility map

LayerComponentResponsibility
ClientReact app shellRenders product surfaces and routes user actions to API clients.
ClientAPI client moduleAdds auth headers, executes refresh-on-401 logic, normalizes errors.
ClientSSE stream parserParses streaming assistant responses for Coach chat UX.
APIFastAPI middlewareAdds request IDs, captures errors, and emits operational notifications.
APIAuth routesLogin/refresh/logout/me plus OIDC callback handling.
APIProduct routesCoach, Money, Growth, onboarding, settings, integrations, tasking endpoints.
ServiceBackground job orchestrationExecutes async workflows and scheduled materialization jobs.
DataPostgreSQL schemasStores identity/session, chat history, metrics/actions/opps, projects, and task runs.
For production readiness reviews, pair this overview with Security posture and Authentication.