iamp5/nx-starter/api-add-use-case
Claude Code and agent skill by iamp5/nx-starter
- community
Checking that the SKILL.md file is still in the repository.
Adding a new endpoint, use case, aggregate or adapter to the Spring Boot API in apps/api following the clean architecture slice (domain -> application -> infrastructure -> web) with tests. Use when asked to add or extend an API feature.
Install
npx vskill@latest install iamp5/nx-starter/api-add-use-caseSKILL.md
The same SKILL.md was published earlier as iamp5/nx-starter/api-add-use-case.
Add a Use Case to the API
Follow the greeting slice as the template and work inside-out. Read apps/api/docs/architecture-boundaries.md first; the naming rules there are enforced by ArchUnit and will fail the hooks if ignored.
Base package: com.example.nxstarter. Replace <aggregate> / <Aggregate> with the singular aggregate name and <Verb> with the action.
1. Domain (domain.<aggregate>)
<Aggregate>Id: record implementingIdentifier<String>(or another
type) with a static from(...).
<Aggregate>: extendsAggregateRoot<<Aggregate>Id>; private
constructor; factories newX(...) (validates, may registerEvent) and with(...) (rehydration, no events). Invariants via AssertionConcern.
- Value objects as records implementing
ValueObject. - Events (optional):
events/<Aggregate>Eventsealed interface plus
past-tense records implementing DomainEvent.
- Ports:
<Aggregate>Gatewayinterface (save,findById, ...) or a
narrower <Concern>Gateway. Return domain types, never JPA entities.
Template: domain/greeting/Greeting.java, GreetingId.java, HashGateway.java.
2. Application (application.<aggregate>)
<Verb><Aggregate>: abstract class extendingUseCase<Input, Output>
(NullaryUseCase without input, UnitUseCase without output) with nested record Input(...) and interface Output { ... }.
impl/Default<Verb><Aggregate>:@Service, constructor-injected ports,
execute builds the aggregate, calls the gateways and returns a package-private record StdOutput(...) implements Output.
Template: application/greeting/CreateGreeting.java, application/greeting/impl/DefaultCreateGreeting.java.
3. Infrastructure (infrastructure.gateway.<aggregate>)
- Adapter
<Aggregate>JpaGateway(@Repository) implementing
<Aggregate>Gateway, or <Aggregate><Technology>Gateway / <Vendor>Client (@Component) for non-persistence ports.
- Persistence types in
persistence/:<Aggregate>JpaEntity(@Entity)
with from(<Aggregate>) / toAggregate() mapping, and <Aggregate>JpaRepository extends JpaRepository<...>.
- Never let a JPA entity or repository escape
infrastructure.
Template: infrastructure/gateway/greeting/UuidHashGateway.java.
4. Web (web)
api/<Aggregate>Api: interface with@Tag,@RequestMapping, the
method mappings, @Operation/@ApiResponses and @Valid on bodies.
controllers/<Aggregate>Controller: `@RestController implements
<Aggregate>Api, injects the use-case abstraction, returns useCase.execute(new Input(...), <Aggregate>Response::from)`.
dto/request/<Verb><Aggregate>Request: record with Bean Validation.dto/response/<Aggregate>Response: record withstatic from(Output).- Add the path to
SecurityConfigurationif it must be public.
Template: web/api/GreetingApi.java, web/controllers/GreetingController.java, web/dto/response/GreetingResponse.java.
5. Tests (src/test/java/...)
domain/<aggregate>/<Aggregate>Test: pure JUnit, factories and
invariants.
application/<aggregate>/impl/Default<Verb><Aggregate>Test: pure JUnit,
hand-written fakes for the gateways (a lambda for single-method ports, an in-memory class otherwise).
web/controllers/<Aggregate>ControllerWebMvcTest:@WebMvcTest,
@Import({SecurityConfiguration.class, GlobalExceptionHandler.class}), @MockitoBean(answers = Answers.CALLS_REAL_METHODS) for the use case.
infrastructure/gateway/<aggregate>/<Aggregate>JpaGatewayIT: JPA slice
test for the adapter when persistence is involved.
6. Verify
Do not
- Put business rules in controllers or throw
ResponseStatusExceptionfor
them.
- Inject a gateway or a
Default*class into a controller. - Return a JPA entity from a gateway or expose it in a DTO.
- Use Lombok, field injection or
@Componentinsideapplication. - Edit
ArchitectureTest.javato make a rule pass.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingapps/api/.agents/skills/api-add-use-case/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/iamp5/nx-starter/api-add-use-case)