An example Dogma application, which implements the features of a simple bank.
Start PostgreSQL:
docker run --rm -d --name dogma-example-postgres \
-e POSTGRES_PASSWORD=password -e POSTGRES_DB=bank \
-p 5432:5432 postgres:18-alpineOnce PostgreSQL is ready, run the example:
DOGMA_EXAMPLE_ENGINE_DSN='postgres://postgres:password@localhost:5432/bank?sslmode=disable' \
DOGMA_EXAMPLE_PROJECTION_DSN='postgres://postgres:password@localhost:5432/bank?sslmode=disable' \
go run ./cmd/bankThe application creates the engine and projection schemas on startup and
preserves state across restarts. Both DSNs can use the same PostgreSQL 18
database, as above, or separate databases. Use sslmode=disable only for local
databases.
Run go test ./... with Docker available. Projection tests use testcontainers
with PostgreSQL 18 and an isolated database per test. CGO is not required.
Runkit accepts commands asynchronously. The deposit, withdrawal, and transfer
handlers use WithEventObserver() to wait for outcome events, so the UI can
show a result such as a declined withdrawal. These waits are bounded by the
request deadline; a timeout does not cancel a command already accepted by the
engine.
An observed event does not mean the UI projections have caught up. Account
creation uses waitForAccount() before redirecting so the next page can read
the customer and account. This demonstrates one way to support a synchronous
UI; a UI that shows pending work and updates as projections arrive would avoid
holding the request open.