Adapters
Overview
Bounda decouples domain logic from storage through adapters. Your commands, events, policies, and queries never reference a specific database — they work against abstract interfaces that Bounda resolves at boot time based on your configuration.
Adapters are configured in two places within bounda.config.ts:
domain— per aggregate: event stores, scheduling, policy storage, and process manager storageread— per read model: the backing store for projections and queries
Available Adapters
| Adapter | Event Store | Read Model | Policy DLQ | Process Manager DLQ | Scheduling |
|---|---|---|---|---|---|
| In-Memory | Yes | — | — | — | — |
| SQLite ¹ | Yes | Yes | Yes | Yes | Yes |
| PostgreSQL ¹ | Yes | Yes | Yes | Yes | Yes |
| MongoDB ¹ | Yes | Yes | Yes | Yes | Yes |
¹ Requires a separate package install. See each adapter’s documentation for the installation command. The only adapter built into core is In-Memory.
Choosing an Adapter
For development and testing, the in-memory adapter gives the fastest feedback loop with no setup. SQLite is a good middle ground when you need persistence across restarts without running a database server.
For production, PostgreSQL and MongoDB provide full durability and concurrent access. PostgreSQL is recommended for relational query patterns, while MongoDB is ideal for document-oriented queries. Read models can use whichever adapter best fits the query patterns — SQLite for simple lookups, PostgreSQL for relational queries, or MongoDB for document-style queries.
Mixing Adapters
Bounda allows different adapters for different concerns within the same application. A single aggregate can use PostgreSQL for its event store while its read models use SQLite or MongoDB Memory. This flexibility lets you pick the right tool for each storage concern.
import type { Config } from "@bounda-dev/config";
export default {
domain: {
user: {
eventStore: { type: "postgresql", url: process.env.DATABASE_URL, schema: "bounda" },
},
},
read: {
"user-details": { type: "sqlite", path: "./db/user-details.db" },
"users-directory": { type: "mongodb", url: process.env.MONGODB_URL, dbName: "bounda" },
},
} satisfies Config;
Related
- Configuration Reference — Full reference for all config options