service-guard

Add a Layer 3 service-layer guard that reads the DB before mutations.

5|2|Updated Jun 28, 2023
One-click install
npx skills add https://github.com/socialsoftware/microservices-simulator --skill service-guard
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: service-guard
Source: https://github.com/socialsoftware/microservices-simulator/tree/main/.claude/skills/service-guard
Command: npx skills add https://github.com/socialsoftware/microservices-simulator --skill service-guard

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Adds a Layer 3 service-layer guard that reads the DB and throws before any mutation. This approach helps preserve domain integrity by validating preconditions prior to state changes.

Core Features & Use Cases

  • Reads the database to validate preconditions before a mutation.
  • Runs inside the same unit of work and only reads the service's own aggregate.
  • Guides developers on repository queries, error constants, and test coverage for guards.

Quick Start

Implement the guard in the target service's operation so that it runs before the mutation.

Frequently Asked Questions about service-guard

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate microservice preconditions before a database mutation?

To validate microservice preconditions before a database mutation, implement an in-process service guard that reads the database and throws an error prior to executing any state changes. This ensures domain integrity by checking preconditions inside the same unit of work.

What is a service-layer guard in domain-driven design?

A service-layer guard in domain-driven design is a precondition check that reads the database within the same unit of work to verify an aggregate's state. It throws an error before any mutation occurs, preserving domain integrity by preventing invalid state transitions.

How do I add error handling for service preconditions that read the database?

To add error handling for service preconditions, define a corresponding error constant and implement a guard that queries your repository. The guard reads the service's own aggregate within the transaction and throws the error before the mutation step begins.

Can I use a service guard to check aggregates outside its own microservice?

No, you cannot use this service guard to check aggregates outside its own microservice. The guard runs inside the same unit of work and is restricted to only reading the service's own aggregate to validate preconditions before throwing.

How do I test service-layer guards for microservices?

To test service-layer guards for microservices, write tests that verify the guard queries the repository correctly and throws the defined error constant when preconditions fail. Testing must confirm the guard executes before the mutation step within the unit of work.

When do I need a database read for microservice error handling?

You need a database read for microservice error handling when validating preconditions before a mutation. By reading the service's own aggregate inside the same unit of work, the guard checks current state and throws to prevent invalid data changes.