Lesson Free

Through-line case: Audit Log Service

Aleksei Litvinau · ~10 min read· Route item 5 of 107

This is not a lesson, not a pattern, and not a methodology, but the running example of the whole program — a single teaching project on which all the lessons, patterns, and methodologies are demonstrated. One and the same service passes through every maturity level: from a bare prompt to a team of agents. This way the theory doesn’t hang in the air: every move is visible on one familiar domain, and the transition from level to level reads as a complication of one and the same task.

What this case is

audit-log-service is an internal compliance / audit log service (Compliance Event Service). It receives audit events from other systems (who did what, when, over which resource, and with what outcome) and stores them immutably. The service’s main value is trust: once an event is written, the system is obligated to keep it as evidence.

In the organization there are many services: authorization, internal portals, data export. Each of them, on every significant action, emits an event (“logged in here,” “exported this,” “was granted such-and-such role”). All these events flow into one store — our audit log. This is a realistic service, far from a toy todo, and that is exactly why it’s convenient for working through all the moves that you and I will be going through here.

Audit Log Service: events are written append-only, stored immutably, and read separately
Audit Log Service: events are written append-only, stored immutably, and read separately

Why audit log specifically

  • A realistic enterprise domain. Familiar to backend engineers, sitting at the intersection of compliance and security — where the cost of a mistake is immediately visible.
  • A strong hard invariant. The domain is append-only: events are only added, without update/delete. This is ideal material for showing invariants, architecture tests, and database-level protection.
  • Clear read/write separation. The write path and the read path sit separately, and this gives a structurally checkable rule (“query code only reads”), on which it’s convenient to teach ArchUnit (1) and blast-radius control.
  • Scalable depth. Simple enough to explain in two minutes, and capacious enough that specifications, multi-agent, and brownfield scenarios unfold on it.
  • A good brownfield substrate. On one and the same repository you can compare different methodologies: add the same feature using each of them.

The domain on one page

The key invariant — append-only. Events can only be inserted, no update/delete. It’s forbidden in two places at once: in the application (no methods or endpoints for modification) and in the database (a trigger throws an exception on UPDATE/DELETE). The server sets the write timestamp; the client does not send it. The fields actor and outcome are required.

The AuditEvent model:

The model describes the fields of one event. UUID identifies a record, Instant holds a point in time, enum specifies a choice from listed values, and jsonb stores additional data in JSON as name–value pairs.

FieldTypeRequiredWhat it means
idUUIDserverevent identifier, generated by the server
recordedAtInstantserverwrite timestamp, set by the server on append
actorstringyeswho performed the action
actionenumyesLOGIN, LOGOUT, EXPORT_DATA, DELETE_RECORD, ACCESS_PII, GRANT_ROLE, REVOKE_ROLE
resourceTypestringnoresource type
resourceIdstringnoresource identifier
outcomeenumyesALLOWED or DENIED
reasonstringnoexplanation of the outcome
metadatajsonbnoarbitrary key-value pairs

A terminology convention for the whole book: resource is shorthand for the pair (resourceType, resourceId); in the HTTP contract both fields are specified explicitly. The write timestamp is everywhere called recordedAt, and in SQL/DDL — recorded_at.

API:

  • POST /api/v1/audit-events — event ingestion (append).
  • GET /api/v1/audit-events — read-only: basic filters actor, from, to, pagination, sorting by recordedAt descending.

Architecture. Layers api → domain ← infrastructure, the domain depends on nothing. The write path and the read path are separated and do not intersect: query code never touches the write.

The domain on one page

How the case passes through the program

LevelWhat happens to the case
Module 1. FoundationBare prompt. For the first time you formulate the audit log task in an engineering way: by the prompt contract instead of going back and forth with the chat.
Module 2. Single agentThe first AGENTS.md appears with the append-only invariant. The agent assembles the scaffold (Spring Boot + Postgres + Flyway + Testcontainers) and the AuditEvent aggregate with an immutability test.
Module 3. Spec-driven deliveryYou drive the Query API feature (reading the log with filters) through the requirements → design → tasks trinity, with a Stop hook and self-eval. Next — the multi-actor filter.
Module 4. Agent team and scaleThe same repository expands: parallel features (retention policy, tamper-evidence, export with RBAC and PII masking) on isolated branches, hierarchical agent teams with shared memory, swarms. Brownfield scenario — adding optional outcome/action filters through characterization tests, an ArchUnit sensor, and an evidence PR.
Module 5. AdoptionThe case becomes the environment for a 30-day experiment in one product area: a set of comparable tasks, a baseline, outcome metrics, and a rollout decision by task class — not an evaluation of a single feature.

The multi-actor filter lets you select events for multiple actors.

Teaching episode: a decision about metadata.supportContact

This is a synthetic development episode with change_id: audit-log/export-support-contact/example-01. All role names, versions, and check results are defined for the exercise. The core domain, API, read/write separation, and event immutability remain intact.

An optional supportContact key appears in the existing metadata. Under the teaching description source-contract@v1, its value may contain [email protected], the service identifier queue-7, or a combination in free text. This is an example of metadata content, without a new model field or a change to the base API.

The accepted redaction-policy@v1 prohibits returning the raw value of this key. Its representation has not yet been chosen. The decision export-support-contact@v1 is whether to omit the key from JSON output and its corresponding column from CSV, or, when the key exists in the source event, replace its entire value with the constant string [MASKED] in both formats. The latter reveals that the field exists; the former requires consumers to work without it. Partial recognition of an address inside the string is outside these options.

The rule owner is redaction-owner. Under the teaching access-policy@v1, this role may choose the redaction rule; redaction-reviewer may answer on its behalf only with explicit delegation for this question. export-owner decides release compatibility with consumers. The source and export agents may propose a solution, prepare code, and run synthetic checks, but may not authorize field disclosure or change these powers themselves.

For the exercise, assume that event immutability, access, and both prepared options have been checked on test data. This condition neither determines which option to choose nor authorizes a release. The decision is presented with source-contract@v1, redaction-policy@v1, access-policy@v1, the corresponding diff, and reports from those exact checks.

A separate branch demonstrates a deferred decision. While the authorized redaction-reviewer defers the answer, redaction-owner approves redaction-policy@v2, requiring supportContact to be omitted entirely from output. The decision export-support-contact@v2 now concerns releasing without the field or postponing the release to coordinate with consumers; it goes to export-owner. A late answer for v1 authorizes neither the previous [MASKED] option nor a release under the new conditions. Changing the form of the previous question without changing its meaning changes only its presentation version.

The story has four states: a decision is prepared with intent, accepted conditions, a delta, and evidence; the reviewer explicitly defers the question; the underlying basis changes during the wait and a new decision version is shown on return; a separate specialist role examines the recurring difficulty and proposes a verifiable process change. In the negative branch, no applicable new rule exists: the system does not invent one or treat silence as consent.

Redaction applies to output; stored audit events are not rewritten. Agent execution and human approval history are distinct from the domain events of Audit Log Service. The exercise introduces no hidden API or schema changes; task, run, and decision IDs are linked at the development-process level.

A joint solution by two participants’ agents

This synthetic example uses the same metadata.supportContact, rule versions, and powers. It compares ways of working on one task.

The first participant owns the event source; their agent knows the allowed supportContact content and prepares synthetic examples. The second owns reading and export; their agent knows the JSON and CSV contracts and checks output against the chosen rule. The participants may work in one team. Their shared task is a consistent field representation for consumers without disclosing the original value.

In isolated work, the source agent describes the field as a “support contact,” while the export agent, without clarifying its contents, prepares removal of only a recognized address. When people compare results, they discover that the remaining free text may also reveal a contact. The release stays blocked until agreement and verification.

Automatically passing the description and examples to the export agent removes manual forwarding. However, the source still treats describing input data as its entire task, and export continues a separate implementation. The parties have no accepted common output approach; receiving a file does not establish one.

When defining the work jointly, the agents discover their overlap around supportContact. The source agent explains why removing a single recognized address is insufficient; the export agent shows the risk of different JSON and CSV rules. Together they propose a shared function that prepares a safe representation before conversion to the response format, and one example set for checking both formats. The source agent takes responsibility for the examples; the export agent takes the function and checks. The choice between full omission and [MASKED] remains with an authorized person.

The new joint result is a common output-preparation approach and joint verification that were absent from the separate assignments. Accepting it requires explicit participant commitments and result checks. Interaction may change the chosen solution, not just task order. The actual magnitude of the effect must be evaluated separately.

Counterexamples include messages without a shared change, identical words hiding different goals, and agents agreeing on an option beyond their powers. Message frequency or a shared folder does not establish a joint result. If a human decision is needed, its preparation and resumption follow the previous section’s conditions. Agent interaction and a human pause are distinct parts of the work. Redaction applies to output; the original event history is not rewritten.

External sources

  1. ArchUnit — a library of architecture tests for Java
After reading

Your notes, a self-check, and the next step

Mostly clear