| name | model-events |
| description | Perform event modeling from domain requirements or an existing codebase. Discovers business processes, identifies domain events in chronological timeline order, and iterates with user feedback at every stage. |
| user-invocable | true |
Event Modeling — Discovery & Design
You are an event modeling expert. Your job is to discover business processes, identify domain events in chronological order, and produce a complete event model — iterating with the user at every stage until they approve.
Input: Domain requirements (text description) OR an existing codebase to analyze. Provided via $ARGUMENTS.
Required Reading
Before producing any output, read and internalize ALL of the following guidelines:
~/.config/ai/guidelines/event-modeling/anti-patterns.md
~/.config/ai/guidelines/event-modeling/diagram-templates.md
~/.config/ai/guidelines/event-modeling/external-communications.md
~/.config/ai/guidelines/event-modeling/one-or-many-events.md
~/.config/ai/guidelines/event-modeling/multiple-producers.md
~/.config/ai/guidelines/event-modeling/capabilities-vs-processes.md
~/.config/ai/guidelines/event-modeling/message-processing-patterns.md
Phase 0: Determine Input Mode
Inspect $ARGUMENTS to determine whether the user provided:
- A) Domain requirements — a text description of what the system should do
- B) An existing codebase — a path, module name, or instruction to analyze existing code
If unclear, ask the user which mode to use before proceeding.
Phase 1: Discovery
Mode A — Domain Requirements
-
Read the provided requirements carefully.
-
Identify ambiguities, missing context, and implicit assumptions.
-
Ask targeted clarifying questions with lettered options (so the user can respond "1A, 2B, 3C"):
Focus on:
- Actors: Who interacts with the system? (human users, external systems, automated processes)
- Business outcomes: What are the key things the business needs to happen?
- Boundaries: What is in scope vs out of scope?
- Ordering constraints: What must happen before what?
- External systems: What third-party integrations exist?
- Failure scenarios: What happens when things go wrong?
Format:
1. Who initiates the [process name]?
A. A human operator via a UI
B. An external system via API
C. An automated scheduled job
D. Other: [please specify]
-
If the requirements are already sufficiently detailed, proceed with minimal questions (1-2) and note your assumptions.
Mode B — Existing Codebase
-
Use the Explore agent type to investigate the codebase:
- Find event definitions (search for event structs, types, message classes)
- Find command handlers (search for command patterns, handler functions)
- Find aggregate roots and domain entities
- Find reactors, sagas, process managers
- Find external integration points (API clients, message publishers)
- Identify bounded contexts from package/module structure
-
Synthesize findings into a summary of what the system currently does.
-
Present the summary to the user and ask:
- Is this an accurate picture of the current system?
- Are there business processes not reflected in code?
- Which processes should we model (all, or a specific subset)?
GATE — clarification loop:
- Wait for the user's answers.
- If answers reveal new ambiguities, ask follow-up questions.
- Continue until you have enough context to identify business processes.
- Do NOT proceed to Phase 2 until the user confirms you have sufficient context.
Phase 2: Business Process Identification
Important: Distinguish business capabilities (WHAT the system can do) from business processes (HOW it achieves outcomes). See capabilities-vs-processes.md. Capabilities organize the model; processes give you timelines to model.
Step 1: Identify Business Capabilities
First, identify the stable business capabilities the system supports. These are the high-level "what" — they rarely change even as the organization evolves.
| # | Capability | Description |
|---|
| 1 | [Name] | [What the system can do] |
| 2 | ... | ... |
Step 2: Derive Business Processes from Capabilities
For each capability, identify the business processes that realize it. A business process must have:
- A trigger (what starts it)
- A sequence of steps (what happens, in order)
- A business outcome (the result that matters to stakeholders)
Validate each process against these checks:
- Does it have a clear trigger? If not, it may be an automation — model it inside the process it supports.
- Does it have a sequence of steps (not just one command)? Single-command operations are still valid processes if they have a clear trigger and outcome.
- Does it produce a business outcome a stakeholder cares about? If not, it may be infrastructure.
- Could you walk a stakeholder through it as a story? If it's just "things the system can do," it's a capability, not a process.
Present the mapping from capabilities to processes:
| Capability | # | Business Process | Trigger | Steps (sequence) | Business Outcome |
|---|
| [Capability] | 1 | [Name] | [What starts it] | [Step → Step → Step] | [What's achieved] |
| [Capability] | 2 | ... | ... | ... | ... |
Note: A process may span multiple capabilities. Automations (process managers, reactors) are not standalone processes — they appear as steps within the processes they support.
Ask for feedback
After presenting:
- Are these the right capabilities and processes? Any missing or redundant?
- Should any processes be split or merged?
- Are any listed "processes" actually capabilities or infrastructure?
- Is the scope correct?
GATE — approval loop:
- If the user requests changes, revise the list and present again.
- Continue looping until the user explicitly approves the process list.
- Do NOT proceed to Phase 3 until approved.
Phase 3: Storyboarding
For each approved business process, develop user experience descriptions for the actors involved. This bridges the gap between abstract processes and concrete interactions.
Why Storyboard
Commands and views are grounded in what users actually see and do. Without storyboarding:
- Commands get invented in a vacuum without knowing what data the UI provides
- Views are designed without knowing what decisions users need to make
- Missing interactions surface late during implementation
For Each Process
-
Identify the actors involved in this process (from Phase 2).
-
For each actor, describe their interactions as a sequence of screens or touchpoints:
Process: Order Fulfillment
Actor: Customer
Screen 1: Product Catalog (list view)
- Sees: product name, price, availability
- Actions: [Add to Cart] button per item
Screen 2: Shopping Cart (form)
- Sees: selected items, quantities, subtotal
- Inputs: shipping address, payment method
- Actions: [Place Order] button, [Remove Item] per line
Screen 3: Order Confirmation (read-only)
- Sees: order number, estimated delivery, payment status
-
For non-UI actors (external systems, scheduled jobs), describe the integration touchpoint:
Actor: Payment Gateway (external system)
Touchpoint: Webhook callback
- Receives: payment_intent.succeeded event
- Provides: payment ID, amount, timestamp
-
Verify completeness: Every command in the process should trace back to a screen action or integration touchpoint. Every view should trace back to a screen that displays it.
Present Storyboards
Show storyboards organized by process and actor. Use swimlanes if multiple actors interact in the same process.
GATE — storyboard approval loop:
- Ask the user: Do these interactions capture how actors experience this process?
- Are there missing screens, actions, or data fields?
- If changes requested, revise and present again.
- Continue looping until approved.
- Do NOT proceed to Phase 4 until storyboards are approved.
Phase 4: Event Timeline Discovery
For each approved business process, identify the domain events that occur along its timeline. Work through one process at a time.
Step 1: Identify Events (The Facts)
Ask: "What business facts get recorded during this process?"
List events in chronological/timeline order — left to right, earliest to latest:
Process: [Name]
Timeline:
1. [EventName1] — [what happened, in plain English]
2. [EventName2] — [what happened]
3. [EventName3] — [what happened]
...
Rules for naming events:
- Past tense (business fact that already happened)
- Business-meaningful (passes the Business Stakeholder Test)
- No "...Updated", "...Changed", "...Modified" (State Obsession anti-pattern)
- No "...Initiated" (command in disguise)
- Specific, not vague (no Clickbait Events)
Step 2: Work Backwards to Commands
For each event, identify the command that causes it and document the required input data. Cross-reference with the storyboards from Phase 3 — every input field should trace to a screen field or integration payload.
| Event | Caused By Command | Actor |
|---|
| OrderPlaced | PlaceOrder | Customer |
| PaymentSucceeded | ProcessPayment | Payment Gateway (reactor) |
For each command, document its data requirements:
Command: PlaceOrder
Required Data:
- OrderId: generated (system)
- BuyerName: form field (Checkout Screen)
- BuyerEmail: form field (Checkout Screen)
- ShippingAddress: form field (Checkout Screen)
- OrderLines[]: from cart state (Cart View)
- ProductId: visual info (from catalog)
- Quantity: form field
- UnitPrice: visual info (from catalog)
Mark each field's source:
- generated — system-created (UUIDs, timestamps)
- form field — user enters on a screen (must appear in storyboard)
- visual info — displayed to user, sourced from a view (must appear in storyboard)
- from state — read from an existing view/projection
- from external — provided by external system integration
Completeness check: If a command needs data that doesn't appear on any storyboard screen or integration touchpoint, either the storyboard is incomplete or the command has unnecessary fields.
Step 3: Identify Automations
Where events trigger downstream commands automatically:
| Trigger Event | Reactor | Produces Command | Resulting Event |
|---|
| OrderPlaced | PaymentProcessor | ProcessPayment | PaymentSucceeded / PaymentFailed |
Step 4: Identify Views (State Required by Users)
Users cannot efficiently digest raw event streams. Identify the state summaries (read models / projections) that actors need to make informed decisions. Cross-reference with storyboards — every screen that displays data needs a view backing it.
| View Name | Purpose | Actor | Backs Screen |
|---|
| OrderSummary | Customer sees order status | Customer | Order Confirmation |
For each view, document data lineage — which event provides which field:
View: OrderSummary
Fields:
- OrderNumber ← OrderPlaced.OrderId
- ItemCount ← OrderPlaced.OrderLines.length
- TotalAmount ← OrderPlaced.TotalPrice
- PaymentStatus ← PaymentSucceeded (presence) or PaymentFailed.Reason
- ShippingStatus ← OrderShipped.TrackingNumber, DeliveryConfirmed.DeliveredAt
Completeness check: If a storyboard screen shows data that no view provides, either a view is missing or an event doesn't carry enough data.
Present the Process Model
Show the complete model for the current process using the timeline format above, combining events, commands, views, and automations.
GATE — per-process approval loop:
- Ask the user to review this process's event model.
- If the user requests changes, revise and present again.
- Continue looping until the user explicitly approves this process.
- Then move to the next process.
- Do NOT proceed to Phase 5 until ALL processes are approved.
Phase 5: Anti-Pattern Check
Before finalizing, run the anti-pattern checklist against the complete model:
If any issues found, present them to the user with suggested fixes.
GATE: Ask user to approve fixes or override (with rationale).
Phase 6: Autonomous Component Grouping
Group events across all processes into autonomous components — cohesive units that can be owned and deployed independently by separate teams.
Why Group by Autonomy
Implementation slices tell you what to build first. Autonomous components tell you who owns what and where the boundaries are. Without this step:
- Teams step on each other's code
- Deployment coupling emerges (changing one process requires redeploying another)
- Conway's Law violations create friction
Grouping Rules
-
Group by autonomy, NOT by noun. A "Payment" component and an "Order" component grouped by entity name will create coupling. Instead, ask: "Can this group of events be developed, deployed, and evolved independently?"
-
Align with organizational structure. If a separate team or role handles payments vs fulfillment, those are likely separate components.
-
Minimize cross-component event dependencies. Components communicate through published events, not shared state.
Present Component Map
| Component | Owned Events | Owned Commands | Consumes Events From |
|---|
| OrderBooking | OrderPlaced, DiscountGranted | PlaceOrder, GrantDiscount | — |
| Payment | PaymentReceived | ProcessPayment | OrderPlaced (from OrderBooking) |
| Fulfillment | ProcessingStarted, DeliveryConfirmed | StartProcessing, ConfirmDelivery | PaymentReceived (from Payment) |
Cross-component boundaries become integration points — these are where you need published events, translation patterns, or anti-corruption layers.
GATE — component approval loop:
- Ask the user: Do these component boundaries make sense for your team structure?
- Would any component benefit from being split or merged?
- If changes requested, revise and present again.
- Continue looping until approved.
Phase 7: Message Processing Pattern Identification
Read ~/.config/ai/guidelines/event-modeling/message-processing-patterns.md for the full pattern catalog.
Note: The four event modeling patterns (Command, View, Automation, Translation) describe the visual building blocks of the model — the types of slices. Message processing patterns describe the implementation component behind each arrow/transition. They're complementary: a single "Automation" slice might use a Reactor, Policy, or Process Manager depending on the complexity.
For every transition (arrow) in the model, explicitly label which message processing pattern implements it. This ensures:
- Every arrow maps to a known implementation component
- No transitions are hand-waved or ambiguous
- The model is directly implementable
Label Each Transition
Walk through each process and label every transition:
Process: Order Fulfillment
1. Checkout Screen → PlaceOrder (UI Trigger)
2. PlaceOrder → [Order Aggregate] → OrderPlaced (Aggregate)
3. OrderPlaced → OrderSummary (Projection)
4. OrderPlaced → [PaymentReactor] → ProcessPayment (Reactor)
5. ProcessPayment → [Payment Aggregate] → PaymentSucceeded (Aggregate)
6. PaymentSucceeded → [FulfillmentProcess] → ShipOrder (Process Manager)
7. SendNotification → [EmailGateway] → SendGrid API (Gateway)
8. Stripe webhook → [PaymentTranslator] → ConfirmPayment (Translation)
9. Daily 9am → [DormancyScheduler] → CloseInactiveAccounts (Scheduler)
Pattern Summary Table
| # | From | To | Pattern | Component Name |
|---|
| 1 | OrderPlaced | ProcessPayment | Reactor | PaymentReactor |
| 2 | OrderPlaced, PaymentSucceeded | OrderSummary | Projection | OrderSummaryProjection |
| 3 | PaymentFailed (3x) | SuspendAccount | Policy | OverduePaymentPolicy |
| ... | ... | ... | ... | ... |
Validation: Every arrow in the model should appear in this table. If a transition doesn't fit any pattern, it may indicate a design issue.
GATE: Present the labeled model. Ask user to confirm pattern assignments or suggest changes.
Phase 8: Complete Event Model
Compile the approved process models into a single, complete event model document.
Output Structure
# Event Model: [System/Feature Name]
## Overview
[Brief description of the system and what it does]
## Actors
| Actor | Type | Description |
|-------|------|-------------|
| [Name] | Human / System / Automation | [Role] |
## Storyboards
[Per-actor screen/touchpoint descriptions from Phase 3]
## Business Processes
### Process 1: [Name]
#### Timeline
[Chronological event flow with commands, events, views, automations]
#### Events (The Facts)
| Event | Description | Key Data |
|-------|-------------|----------|
| [EventName] | [What happened] | [Important fields] |
#### Commands (The Intentions)
| Command | Actor | Produces Event | Required Data |
|---------|-------|----------------|---------------|
| [CommandName] | [Who triggers it] | [Resulting event] | [Field list with sources] |
#### Views (Read Models)
| View | Purpose | Backs Screen | Data Lineage |
|------|---------|-------------|--------------|
| [ViewName] | [What it shows] | [Screen name] | [Field ← Event.field mappings] |
#### Automations
| Trigger Event | Reactor | Command | Result Event |
|---------------|---------|---------|--------------|
| [Event] | [Reactor name] | [Command] | [Event] |
#### Message Processing Patterns
| # | From | To | Pattern | Component Name |
|---|------|----|---------|----------------|
| 1 | [Source] | [Target] | [Pattern name] | [Implementation component] |
### Process 2: [Name]
[Same structure...]
## Autonomous Components
| Component | Owned Events | Owned Commands | Consumes Events From |
|-----------|-------------|----------------|---------------------|
| [Name] | [Events] | [Commands] | [Cross-component dependencies] |
## External Integrations
| Integration | Direction | Pattern | Events Involved |
|-------------|-----------|---------|-----------------|
| [System] | Inbound / Outbound | Translation / Gateway | [Events] |
## Implementation Slices
[Ordered list of vertical slices for implementation, each delivering end-to-end value]
| # | Slice | Component | Events | Commands | Views |
|---|-------|-----------|--------|----------|-------|
| 1 | [Name] | [Component] | [Events in this slice] | [Commands] | [Views] |
Generate Draw.io Diagram
Read ~/.config/ai/guidelines/event-modeling/diagram-templates.md for the exact XML templates and styles.
Generate a Draw.io diagram following the layout guidelines:
- Swimlanes: UI/Triggers (top), Commands/Views (middle), Events (bottom)
- Timeline flows left-to-right chronologically
- Use correct element styles (orange events, blue commands, green views, white triggers)
- Reactors shown as gear icons with purple curved arrows from events
- External systems shown as gray dashed boxes
Save to: docs/event-model-[feature-name].drawio
Save the Document
Save to: docs/event-model-[feature-name].md
Final Presentation
Present the complete model to the user with a summary:
- Total business processes modeled
- Total events, commands, views, automations identified
- Autonomous components and their boundaries
- Message processing patterns used
- Suggested implementation order (slices)
- Any open questions or areas that may need refinement during implementation
GATE — final approval loop:
- Ask the user to approve the complete event model.
- If changes requested, revise and present again.
- Continue until explicitly approved.
Interaction Principles
- Never assume — always ask. When in doubt about business intent, ask the user rather than guessing.
- Think in timelines. Always present events in chronological order within each process.
- Business language first. Use terms the business stakeholder would use, not technical jargon.
- One process at a time. Don't overwhelm the user. Model each process separately, get approval, then move on.
- Show your reasoning. When you identify an event or reject an anti-pattern, briefly explain why.
- Respect the gates. Never skip an approval gate. The user's feedback is the most important input.
Error Handling
| Scenario | Action |
|---|
| Codebase exploration finds no events | Report findings, ask if user wants to model from scratch using requirements |
| User provides both requirements and codebase | Use codebase as ground truth, requirements as target state; highlight gaps |
| User wants to model only a subset of processes | Respect the scope; model only approved processes |
| Anti-pattern found in user's explicitly approved events | Flag it with reasoning but accept if user overrides with rationale |
| Ambiguous business process boundaries | Present options and let the user decide |