example

package module
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 6 Imported by: 1

README

Dogma Example Application

An example Dogma application, which implements the features of a simple bank.

Build Status Code Coverage

Running locally

Start PostgreSQL:

docker run --rm -d --name dogma-example-postgres \
  -e POSTGRES_PASSWORD=password -e POSTGRES_DB=bank \
  -p 5432:5432 postgres:18-alpine

Once 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/bank

The 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.

Commands and the UI

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.

Documentation

Overview

Package example is an example Dogma application with the features of a simple bank.

Index

Constants

View Source
const AppKey = "22028264-0bca-43e1-8d9d-cd094efb10b7"

AppKey is the example application's identity key.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	AccountAggregate         domain.AccountHandler
	CustomerAggregate        domain.CustomerHandler
	DailyDebitLimitAggregate domain.DailyDebitLimitHandler
	TransactionAggregate     domain.TransactionHandler

	DepositProcess                   domain.DepositProcessHandler
	OpenAccountForNewCustomerProcess domain.OpenAccountForNewCustomerProcessHandler
	TransferProcess                  domain.TransferProcessHandler
	WithdrawalProcess                domain.WithdrawalProcessHandler

	ThirdPartyBank integrations.ThirdPartyBankIntegrationHandler

	ReadDB             *sql.DB
	CustomerProjection projections.CustomerProjectionHandler
	LedgerProjection   projections.LedgerProjectionHandler
}

App is a dogma.Application implementation for the example "bank" domain.

func (*App) Configure

func (a *App) Configure(c dogma.ApplicationConfigurer)

Configure configures the Dogma engine for this application.

Directories

Path Synopsis
cmd
bank command
Package main is the entry-point for the banking example application.
Package main is the entry-point for the banking example application.
Package domain contains the business logic for the banking application.
Package domain contains the business logic for the banking application.
Package integrations implements Dogma integration handlers that communicate with external systems on behalf of the application.
Package integrations implements Dogma integration handlers that communicate with external systems on behalf of the application.
internal
databasetest
Package databasetest provides PostgreSQL databases for tests.
Package databasetest provides PostgreSQL databases for tests.
idletimeout
Package idletimeout manages engine lifetime for the public demo hosted at https://example.dogmatiq.io.
Package idletimeout manages engine lifetime for the public demo hosted at https://example.dogmatiq.io.
Package messages contains extra types used by the application's message definitions.
Package messages contains extra types used by the application's message definitions.
commands
Package commands contains the application's command message definitions.
Package commands contains the application's command message definitions.
events
Package events contains the application's event message definitions.
Package events contains the application's event message definitions.
internal/validation
Package validation contains some message validation helpers.
Package validation contains some message validation helpers.
ui
projections
Package projections implements Dogma projection handlers that build the read-models used by the UI.
Package projections implements Dogma projection handlers that build the read-models used by the UI.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL