Architecture & Docs Overview
Purpose
This page is the hosted entry point to the repository architecture. The codebase
is a transitional monorepo: application processes live in apps/**, reusable
runtime and domain ownership is moving into packages/**, and selected shared
implementations remain under src/mastra/**. Source and tests win when a page
disagrees with implementation.
System shape
Executable applications
| Path | Deployed process |
|---|---|
apps/runtime + runtime-entry | Mastra HTTP runtime and build/dev adapter. Runtime composition is owned by apps/runtime/src/mastra-runtime.ts. |
apps/admin-ui | React operator dashboard and Express BFF. Browser traffic uses /admin-api/**; the BFF proxies controlled requests to runtime /admin/**. |
apps/widget | SDAC assistant UI and BFF. It proxies /api/ingestion/** and /api/mastra/**. |
apps/ingestion-server | FastAPI ingestion API plus independently registered Azure Functions v2 blueprints. |
apps/handbook-app | Handbook review/generation UI and Express server. |
apps/health-aggregator | Azure Functions timer app for health aggregation, APIM keep-warm, and retention work. |
apps/diagnostics-service | Read-only diagnostics control-plane or worker service, including the diagnostics MCP HTTP handler. |
apps/admin-ui-reference | Legacy static reference app; it is not the production dashboard. |
The root npm workspaces are runtime-entry, apps/runtime,
apps/diagnostics-service, and packages/*. The other apps retain independent
install/build contracts.
Package boundaries
Domain ownership lives in packages/domain-k12, packages/domain-sdac,
packages/domain-tap, and packages/domain-handbook. Each domain supplies a
loader that contributes agents, tools, workflows, routes, and MCP servers to
runtime composition. Domain packages must not import one another or app code.
Shared ownership is divided across:
packages/platform-runtime: runtime factories, providers, routes, services, schemas, configuration, tools, telemetry, and explicit bridges to retainedsrc/mastra/**implementations;packages/platform-rag: reusable ingestion, retrieval, generation, verification, and evaluation contracts used by Handbook;packages/platform-data: shared SQL Server/Azure SQL client;packages/platform-core: stable domain/package type vocabulary;packages/platform-config: reserved scaffold, not the current configuration owner;packages/diagnostics-*: diagnostics contracts, gateway, and MCP clients.
Use package exports such as @maf/platform-runtime/* rather than reaching into
bridged src/mastra/** files from new package or app code.
Runtime composition
scripts/build/generate-domain-barrel.tsresolves the active target and cross-cutting loaders.apps/runtime/src/mastra-runtime.tsconfigures dependencies and invokes the selected loaders.- Registries are merged with duplicate detection, then route factories expose the selected agents, tools, and workflows.
runtime-entry/index.tsconstructs the final Mastra instance.- Production builds copy domain bundles into
.mastra/output/domain-runtimes/**; built execution does not evaluate raw domain TypeScript.
Data and contracts
db/sqlproj/**is the authoritative DACPAC source for Core, K12, SDAC, TAP, Handbook, Ingestion, Reasoning, Recovered, Memory, and Mastra-native schemas.docs/contracts/*.jsonanddocs/openapi/*.jsonare generated or maintained API inventories; run their freshness checks before treating them as current.bruno/**contains executable HTTP examples and smoke collections.environments/**,.github/config/projects/**, andazure_template/profiles/**jointly define deployable environment behavior.
Change routing
| Change | Inspect together |
|---|---|
| Runtime/domain inclusion | apps/runtime, domain loader/exports, generated barrels, build scripts, Dockerfiles, smoke tests |
| Agent/tool/workflow | Owning package, registry/loader, conformance tests, contracts, Bruno, profile seeds |
| Public route/schema | Route source, OpenAPI/contracts, Bruno request, route tests, hosted API page |
| Database | Owning SQL project, Mastra.AllDb, migration/seed needs, infra tests, deployment order |
| Deployment | .github/workflows, .github/config, scripts/github-actions, azure_template, environments, Dockerfiles, db, tests/infra |