scaffold-write
Guide for adding a new write operation (command/mutation) to the Backend. Focuses on Event Sourcing, Wolverine commands, and Projections.
Installation
Suivez les instructions du dépôt pour votre agent. Consultez les fichiers et dépendances avant l’installation.
Voir la source ↗GuidesInstructions
Follow this guide to implement a state-changing operation in the Backend (ApiService) using strict project standards.
-
Define the Domain Event
- Create a
recordinsrc/BookStore.ApiService/Events/. -
Naming: Past tense (e.g.,
BookPublished, notPublishBook). -
Timestamps: MUST use
DateTimeOffset(neverDateTime). -
IDs: MUST use
Guid.CreateVersion7()(neverGuid.NewGuid()). -
Example:
public record BookPublished(Guid Id, DateTimeOffset Timestamp);
- Create a
-
Define the Command
- Create a
recordinsrc/BookStore.ApiService/Commands/{Resource}/(e.g.,Commands/Books/). -
Template:
templates/Command.cs
- Create a
-
Implement the Wolverine Handler
- Create/Update
src/BookStore.ApiService/Handlers/{Resource}/{Resource}Handlers.cs. -
Template:
templates/Handler.cs
- Create/Update
-
Expose the Endpoint (Backend)
- Open
src/BookStore.ApiService/Endpoints/{Resource}Endpoints.cs. -
Template:
templates/Endpoint.cs
- Open
-
Update Read Model (Projections)
- Open
src/BookStore.ApiService/Projections/{Resource}Projection.cs. - Implement
CreateorApplymethods.
- Open
-
Enable Real-time Updates (SSE)
-
Notification: Create
record {Event}Notificationinsrc/Shared/BookStore.Shared/Notifications/DomainEventNotifications.cs. -
Listener: Update
src/BookStore.ApiService/Infrastructure/MartenCommitListener.cs.- Add
case {Resource}Projection proj:inProcessDocumentChangeAsync. - Implement
Handle{Resource}ChangeAsyncto.NotifyAsync()the new notification.
- Add
- Reference: See real-time-notifications for the complete data flow.
-
Notification: Create
-
Client Integration
-
Interface: Create
src/Client/BookStore.Client/I{Action}{Resource}Endpoint.csmanually. -
DTOs: If a Request DTO is needed, create it in
src/Shared/BookStore.Shared/Models/(do not rely on auto-generation). -
Registration: Add to
BookStoreClientExtensions.cs.
-
Interface: Create
// turbo 8. Verify
- Run
/verify-featureto ensure build, format, and tests pass.
Related Skills
Prerequisites:
- For complex aggregates, consider
/scaffold-aggregatefirst to create the domain model
Next Steps:
-
/scaffold-read- Add query endpoints for the new resource -
/scaffold-frontend-feature- Create UI for the new feature -
/scaffold-test- Create integration tests -
/verify-feature- Complete verification
Specialized Skills:
-
/scaffold-aggregate- Generate event-sourced aggregates with Apply methods -
/scaffold-projection- Generate read model projections for queries
See Also:
- scaffold-aggregate - Detailed aggregate patterns
- scaffold-projection - Projection creation
- wolverine-guide - Wolverine command/handler patterns
- ApiService AGENTS.md - Backend patterns and conventions
Exemples
Consultez les exemples du dépôt source.
Voir la source ↗Historique source
- Date d’indexation
- 2026-01-20
- Mise à jour de l’index
- 2026-01-26
- Branch
- main
Les dates concernent ce répertoire. Consultez le dépôt pour l’historique du code.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!