todolist

command module
v0.0.0-...-b3aadbd Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Todo List

A small Connect-based service that exercises go-eventually's DDD / Event Sourcing primitives end-to-end with:

  • An aggregate root (todolist.TodoList) with a child entity (todolist.Item), built on aggregate.BaseRoot and aggregate.RecordThat.
  • Commands (todolist.CreateCommand, todolist.AddItemCommand) implementing command.Handler[Cmd], persisted through an aggregate.EventSourcedRepository backed by event.NewInMemoryStore.
  • A query (todolist.GetQuery) implementing query.Handler[Q, R], reusing the same repository's Get.
  • BDD-style test scenarios using aggregate.Scenario, command.Scenario, and (implicitly through the command scenarios) the event streaming plumbing.
  • A Connect service exposing the above over unencrypted HTTP/2, with gRPC health + gRPC reflection wired up.

Running

go run ./examples/todolist
# or from the example dir:
cd examples/todolist && go run .
# Server listens on :8080 by default

Hit it with a Connect client, grpcurl, or the built-in reflection:

grpcurl -plaintext localhost:8080 list
grpcurl -plaintext -d '{"todo_list_id":"...","title":"chores","owner":"me"}' \
  localhost:8080 todolist.v1.TodoListService/CreateTodoList

Design choices

  • Commands return google.protobuf.Empty. Clients generate IDs and pass them in; the server acknowledges. Idempotent on retries with the same ID.
  • Request/response messages colocated with the service in todo_list_service.proto; domain messages live in their own files. Small service surface benefits more from colocation than from strict one-message-per-file splitting.
  • Connect only. No HTTP/REST gateway, no google.api.http annotations. The Connect protocol itself already speaks gRPC, gRPC-Web, and Connect-over-HTTP; that's enough surface for an example.
  • In-memory store. State is lost on restart. The example is about wiring, not persistence; swap event.NewInMemoryStore() in main.go for a postgres.NewEventStore(...) to get durability.
  • Error handling is example-grade. Domain errors are mapped to Connect codes (InvalidArgument, AlreadyExists, NotFound, Internal) and the full error chain is propagated to the client. A real service would sanitize messages before they cross the wire.
  • Package by domain, not by layer. Everything TodoList-related — aggregate, events, commands, queries, handlers, Connect transport, proto conversion — lives in a single internal/todolist package. Names like CreateCommand, GetQuery, AddItemCommandHandler, ConnectServiceHandler, and ToProto ride on top of the package prefix to keep call sites terse and the domain boundary obvious at a glance.

Protobuf generation

cd examples/todolist
buf generate

Committed output lives under gen/; regenerate after any proto change. The buf configuration uses the v2 schema (see buf.yaml + buf.gen.yaml at the module root).

Documentation

Overview

Package main is the entrypoint for the TodoList Connect service example.

The service is backed by an in-memory event.Store: state is lost on restart. This example is about showcasing how to wire the go-eventually building blocks together, not about persistence.

Directories

Path Synopsis
gen
internal
todolist
Package todolist contains everything related to the TodoList bounded context: the aggregate root, its domain events, commands, queries, and their handlers.
Package todolist contains everything related to the TodoList bounded context: the aggregate root, its domain events, commands, queries, and their handlers.

Jump to

Keyboard shortcuts

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