Kitchen — version 1
Kitchen bounded context — turning a placed order into a cooked pizza. It watches the orders Ordering publishes and runs each one through the kitchen workflow: a ticket is queued, prepped, baked, and put up on the pass. Kept in its own context so “how the kitchen cooks” evolves independently of “how an order is taken”.
Domain Model
Section titled “Domain Model”classDiagram
class Station {
<<enumeration>>
OvenA
OvenB
Cold
}
class TicketStage {
<<enumeration>>
Queued
Prepping
Baking
Ready
Served
Scrapped
}
class TicketOpened {
<<event>>
+TicketId ticketId
+OrderId order
}
class TicketStartedBaking {
<<event>>
+TicketId ticketId
+Station station
}
class KitchenTicket {
<<aggregate root>>
+TicketId id
+OrderId order
+Station station
+TicketStage stage
+Int pizzas
+List~Topping~ toppings
+Instant startedAt
+Bool /isCooking
+Bool /isDone
+Bool /started
+open(OrderId order, Station station, Int pizzas, List~Topping~ toppings) KitchenTicket
+prep()
+bake()
+putUp()
+serve()
}
TicketOpened --> KitchenTicket
TicketStartedBaking --> KitchenTicket
TicketStartedBaking *-- Station
KitchenTicket *-- Station
KitchenTicket *-- TicketStage
Aggregates
Section titled “Aggregates”Cooking
Section titled “Cooking”The kitchen-ticket aggregate: one ticket per order on the line. Being an aggregate root it gains an IKitchenTicketRepository and joins the context UoW; the repository block adds intention-revealing finders.
Root entity: KitchenTicket (identified by TicketId)
Repository finders:
atStation(station: Station): List<KitchenTicket>inProgress(): List<KitchenTicket>
Repository operations: getById, add, update
Domain Events
Section titled “Domain Events”TicketOpened
Raised inside the aggregate when a ticket is opened by the factory.
| Field | Type | Description |
|---|---|---|
| ticketId | TicketId | |
| order | OrderId |
TicketStartedBaking
Raised when a ticket goes into the oven.
| Field | Type | Description |
|---|---|---|
| ticketId | TicketId | |
| station | Station |
Lifecycle
Section titled “Lifecycle”stateDiagram-v2
[*] --> Queued
Queued --> Prepping
Queued --> Scrapped
Prepping --> Baking
Prepping --> Scrapped
Baking --> Ready
Baking --> Scrapped
Ready --> Served
Ready --> Scrapped
Served --> [*]
Scrapped --> [*]
| From | To | Guard |
|---|---|---|
Queued | Prepping | |
Queued | Scrapped | |
Prepping | Baking | |
Prepping | Scrapped | |
Baking | Ready | |
Baking | Scrapped | |
Ready | Served | |
Ready | Scrapped | |
Served | (terminal) | |
Scrapped | (terminal) |
Commands
Section titled “Commands”prep()
Section titled “prep()”Start prepping a queued ticket.
Preconditions:
- only a queued ticket can be prepped
Effects:
stage -> Prepping
bake()
Section titled “bake()”Put a prepped ticket into the oven, stamping the time.
Preconditions:
- only a prepped ticket can be baked
Effects:
stage -> BakingstartedAt -> now
Events:
TicketStartedBaking(ticketId: id, station: station)
putUp()
Section titled “putUp()”Pull a baked ticket out and put it up on the pass.
Preconditions:
- only a baking ticket can be put up
Effects:
stage -> Ready
serve()
Section titled “serve()”Hand a ready ticket off to the front of house or the driver.
Preconditions:
- only a ready ticket can be served
Effects:
stage -> Served
Factory Operations
Section titled “Factory Operations”open(order: OrderId, station: Station, pizzas: Int, toppings: List<Topping>)
Section titled “open(order: OrderId, station: Station, pizzas: Int, toppings: List<Topping>)”Open a ticket for a placed order. The same-named parameters auto-bind the required fields (order, station, pizzas, toppings); stage defaults to Queued.
Preconditions:
- a ticket must cook at least one pizza
Events:
TicketOpened(ticketId: id, order: order)
Invariants
Section titled “Invariants”Business rules
- a ticket must cook at least one pizza
Domain Types
Section titled “Domain Types”Station — enum
Section titled “Station — enum”The station a ticket is routed to. A plain enum used for load-balancing.
Values: OvenA, OvenB, Cold
TicketStage — enum
Section titled “TicketStage — enum”The lifecycle state of a kitchen ticket. Drives the states stage { … } machine on the entity, so only the declared transitions are legal at runtime.
Values: Queued, Prepping, Baking, Ready, Served, Scrapped
Events
Section titled “Events”Integration Events
Section titled “Integration Events”TicketReady
Section titled “TicketReady”Raised when a ticket is finished and put up on the pass. A delivery / dine-in handler reacts to it; kept primitive as a published fact.
| Field | Type | Description |
|---|---|---|
| ticketId | TicketId | |
| order | OrderId | |
| readyAt | Instant |
Published by this context.
Coverage
Section titled “Coverage”| Kind | Covered | Total |
|---|---|---|
| aggregate | 1 | 1 |
| entity | 1 | 1 |
| enum | 2 | 2 |
| event | 2 | 2 |
| integrationEvent | 1 | 1 |
| query | 0 | 1 |
| readModel | 0 | 1 |
⚠️ 2 not documented