GraphQL Runtime
Expose Ambiten models through GraphQL while preserving context propagation, middleware behavior, and resolver-safe execution.
Build one Workspace API from your first MongoDB connection to a production-oriented Ambiten runtime.
The 12-part core path is complete. Tutorial 12 consolidates process, execution, and operation lifetimes; the framework tracks are separate follow-up work. Deployment hardening and tenant authorization remain application and infrastructure responsibilities.
Build an Agent-Ready MCP Server with Ambiten exposes the existing application through two tenant-scoped MCP tools. REST requests, background jobs, and agent tool calls reuse the same model policies, instrumentation, and tenant infrastructure.
This is a separate bonus after Tutorial 12, not Tutorial 13.
Fastify, NestJS, GraphQL, and Lambda demonstrate different ingress points using the same Ambiten runtime. They complement the primary Express series instead of repeating it.
The existing Document-to-PDF SaaS tutorial remains a separate, standalone tutorial.
Learn Ambiten by building complete systems instead of isolated examples.
Tutorials show how Ambiten behaves across real application workflows: execution boundaries, context propagation, model operations, middleware, transactions, tenant-aware infrastructure, instrumentation, and persistence working together inside one system.
The request enters the framework with tenant identity, request metadata, and application input.
The framework request enters Ambiten through the appropriate adapter integration boundary.
Tenant identity, request metadata, validation, and configured execution options are resolved before application logic begins.
Execution-scoped state is bound to the active asynchronous flow and remains isolated from unrelated executions.
Application logic invokes model operations without manually forwarding tenant, request, database, or transaction state.
The model receives the operation, applies its model definition, and resolves the effective operation context.
Explicit operation context, active AmbitenContext, and model defaults are merged into the persistence-facing operation state.
Validation, persistence policy, middleware, lifecycle behavior, and operation-specific rules execute using the effective ModelContext.
Providers, MultiTenantManager, and runtime infrastructure resolve the required database, MongoDB client, tenant resources, and active session while the model retains collection ownership.
The provider implementation supplies MongoDB database, client, and session capability for the resolved operation scope.
The persistence operation executes against the resolved database, model collection, MongoDB client, and active transaction session when one exists.
Post-operation middleware and instrumentation complete, an active transaction boundary commits or rolls back as appropriate, and the result returns through the framework response.
Ambiten is not only a collection of APIs.
It is a runtime system.
Understanding individual methods is useful, but production behavior emerges from how execution boundaries interact across adapters, AmbitenContext, application logic, models, middleware, transactions, providers, tenant infrastructure, and MongoDB.
That is why the tutorials focus on complete execution flows rather than disconnected snippets.
The goal is not only to show how to call Ambiten APIs.
The goal is to show how execution remains understandable as an application grows.
A typical runtime path looks like:
Execution Ingress
↓
Execution Boundary
↓
AmbitenContext
↓
Application Logic
↓
AmbitenModel
↓
Effective ModelContext
↓
Schema / Middleware
↓
Infrastructure Resolution
↓
AmbitenClient
↓
MongoDBThe tutorials make that architecture concrete.
Each tutorial is built around a real architectural pattern rather than a synthetic API demonstration.
You will see how execution state is established at a boundary and carried through the runtime.
You will learn how:
AmbitenContext carries execution-scoped stateAmbitenModel binds runtime state into an Effective ModelContextAmbitenClient resolve database resourcesThe tutorials also show where Ambiten's guarantees stop.
External side effects, authorization policy, cross-process coordination, and infrastructure topology remain application or system responsibilities unless explicitly handled by the surrounding architecture.
Every tutorial follows the same architectural progression.
Product Definition
→ Data Modeling
→ Runtime Setup
→ Execution Boundaries
→ Feature Workflows
→ Runtime Behavior
→ Operational InsightThis structure keeps the focus on system behavior rather than only implementation syntax.
You are not only learning how to write a feature.
You are learning how that feature participates in an execution.
A feature inside Ambiten does not execute in isolation.
For model-driven persistence, the runtime path is typically:
Application Operation
↓
AmbitenModel
↓
mergeCtx()
↓
Effective ModelContext
↓
Schema / Middleware
↓
Collection Resolution
↓
DbProvider
↓
AmbitenClient
↓
MongoDBThe Effective ModelContext can inherit execution values such as:
tenantId
requestId
dbName
collectionName
sessionwhile also carrying operation-specific controls such as:
db
config
withDeleted
onlyDeleted
hardDeleteThis distinction is important throughout the tutorials.
AmbitenContext represents the broader execution.
ModelContext represents the persistence-facing state of a model operation.
Expose workspace capabilities to AI hosts through MCP while reusing Ambiten tenant scope, lifecycle policies, and instrumentation.
Build a tenant-aware SaaS product with tier policies, transaction-safe workflows, runtime instrumentation, and operational visibility.
Expose Ambiten models through GraphQL while preserving context propagation, middleware behavior, and resolver-safe execution.
Design tenant-aware infrastructure with provider routing, runtime policy boundaries, and operational isolation strategies.
Run queues and scheduled jobs with explicit runtime scope so asynchronous execution remains observable and context-safe.
This tutorial builds a complete multi-tenant Document-to-PDF SaaS application.
The system combines tenant-aware execution, transaction-aware workflows, runtime instrumentation, usage controls, and application-level policy decisions inside one architecture.
You will follow the execution path from request ingress through tenant resolution and context binding into model operations and tenant-specific MongoDB infrastructure.
The application includes practical concerns such as:
tenant identification
usage limits
subscription tiers
document creation
PDF generation workflows
transaction participation
instrumentation
upgrade flows
runtime policy checksInstead of treating Ambiten as an isolated database abstraction, the tutorial shows how the runtime coordinates execution state while leaving business behavior inside the application.
One of the most important ideas throughout the tutorials is that Ambiten context is execution-scoped.
An HTTP request is only one possible execution boundary.
Ambiten can also be used inside:
background jobs
queue consumers
scheduled tasks
workers
CLI processes
custom application workflowsFramework adapters normally establish the boundary automatically.
Outside an adapter, an application can establish one explicitly with AmbitenContext.run(...).
Conceptually:
Execution Begins
↓
AmbitenContext.run(...)
↓
Execution State Becomes Available
↓
Application Work
↓
Model Operations
↓
Execution CompletesThis is why the tutorials use the term execution rather than assuming every operation originates from an HTTP request.
The tutorials also distinguish tenant identity from tenant infrastructure.
These are related, but they are not the same responsibility.
Who is this execution for?
↓
TenantResolver
Carry tenant identity
↓
AmbitenContext
Where does this tenant run?
↓
TenantConfigResolver /
MultiTenantManager
Give me the MongoDB client
↓
TenantClientResolver /
MultiTenantManagerA typical tenant-aware flow therefore looks like:
Request / Invocation
↓
Tenant Resolution
↓
AmbitenContext.tenantId
↓
AmbitenModel
↓
Effective ModelContext
↓
MultiTenantManager
↓
Tenant MongoClient
↓
Tenant DatabaseThe tutorials show this separation explicitly so tenant routing does not become confused with authentication or authorization.
Tenant resolution answers:
Which tenant is this execution for?Authorization answers:
May this caller act for that tenant?Those are different concerns.
Transactions are taught as execution boundaries rather than as individual model features.
The transaction path is:
Transaction Boundary
↓
ClientSession
↓
AmbitenContext.session
↓
AmbitenModel.mergeCtx()
↓
ModelContext.session
↓
Participating Ambiten OperationsThe enclosing transaction boundary owns:
start
commit
rollback
completionIndividual models participate in the transaction but do not independently commit or roll back the surrounding workflow.
The tutorials demonstrate both supported patterns.
await AmbitenContext.withTransaction(async () => {
await DocumentModel.create({
title: "Quarterly Report"
});
await UsageModel.create({
operation: "pdf-generation"
});
});Where supported by the framework adapter:
enableTransactions: trueThese are alternative transaction strategies.
They are not two transaction layers that every application must combine.
The tutorials also make an important boundary explicit:
Ambiten transaction propagation
≠
automatic participation by every external operationParticipating Ambiten operations can inherit the active MongoDB session.
External APIs, file storage, email delivery, queue publishing, and unrelated raw driver operations are not automatically made atomic by that MongoDB transaction.
Tutorials use middleware to demonstrate behavior that belongs close to the persistence boundary.
A typical model flow is:
AmbitenModel
↓
Effective ModelContext
↓
Schema / Middleware
↓
Database OperationSchemas remain reusable definitions.
They can describe:
structure
validation
normalization
middleware
soft-delete behavior
persistence policy
lifecycle configurationExecution-specific state does not need to be embedded permanently into the schema.
The model supplies the Effective ModelContext for the active operation.
This keeps the distinction clear:
Static definition.
Dynamic execution.Tutorials also show how runtime metadata can support instrumentation.
AmbitenContextState can carry runtime information such as:
requestId
tenantId
loggerMeta
debug
meta
observer
budgetThis gives instrumentation a consistent execution context.
The runtime provides the metadata boundary.
How logs, traces, metrics, events, or telemetry are transported and stored remains the responsibility of the instrumentation backend being used.
The goal is not to place observability logic inside every business operation.
The goal is to make the execution information needed by instrumentation available at the runtime boundary.
Not every Ambiten application needs the complete runtime stack.
Some tutorials and examples may begin directly with AmbitenClient.
Application
↓
AmbitenClient
↓
MongoDBAdditional runtime capabilities can then be introduced progressively:
AmbitenClient
↓
AmbitenContext
↓
AmbitenSchema + AmbitenModel
↓
Framework Adapters
↓
Multi-Tenant Runtime
↓
Transactions and Advanced InfrastructureThis progression is intentional.
Ambiten does not require a small application, script, migration, educational example, or internal tool to adopt every runtime capability before it can perform useful work.
Many tutorials focus primarily on calling APIs.
Ambiten tutorials focus on execution architecture.
The emphasis is on understanding:
where execution begins
what state belongs to that execution
how model operations inherit runtime state
where persistence behavior belongs
how tenant infrastructure is resolved
who owns transaction completion
how reusable infrastructure stays separate from execution stateThat distinction matters because much of the complexity in growing systems comes from coordinating execution rather than from individual database calls.
Throughout the tutorials, the same responsibility model is used consistently:
Adapter
→ framework execution ingress
TenantResolver
→ tenant identity
AmbitenContext
→ execution-scoped state
Application
→ business behavior
AmbitenModel
→ operation coordination and context binding
ModelContext
→ persistence-facing operation state
AmbitenSchema
→ structure and persistence behavior
DbProvider
→ database, client, and session contract
MultiTenantManager
→ tenant infrastructure
AmbitenClient
→ MongoDB capability
Transaction Boundary
→ transaction lifecycle
MongoDB
→ persistenceKeeping those responsibilities separate makes larger examples easier to understand.
The tutorials also distinguish reusable process infrastructure from short-lived execution state.
PROCESS LIFETIME
AmbitenRuntime
AmbitenClient
MongoClient
MultiTenantManager
providers
runtime configurationEXECUTION LIFETIME
AmbitenContext
tenantId
requestId
dbName
collectionName
session
logger metadata
runtime metadataAnd during model execution:
OPERATION LIFETIME
Effective ModelContext
explicit overrides
model defaults
soft-delete controls
operation configurationThis separation allows infrastructure to be reused while execution state remains isolated to the work that created it.
Tutorials are most useful when you want to understand how multiple Ambiten concepts work together inside a complete system.
They are especially useful when you want to:
AmbitenContext becomes an Effective ModelContextFor individual API contracts and lower-level behavior, use the Core documentation and reference sections.
Tutorials are where the Ambiten runtime becomes concrete.
They show how execution boundaries, AmbitenContext, application logic, AmbitenModel, Effective ModelContext, schemas, middleware, tenant infrastructure, transactions, instrumentation, and MongoDB fit together.
The central model is:
Boundary creates execution.
Context carries execution.
Model binds execution to an operation.
ModelContext carries operation state.
Infrastructure resolves resources.
MongoDB performs persistence.The goal is not simply to teach individual methods.
It is to make the behavior of a complete Ambiten application understandable from ingress to persistence.