code-structure

Applies canonical Java Spring Boot package hierarchy and design patterns when creating or refactoring microservices.

Updated Jun 25, 2026
One-click install
npx skills add https://github.com/oriddd/ai-toolkit --skill code-structure-oriddd
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: code-structure
Source: https://github.com/oriddd/ai-toolkit/tree/main/copilot/public/skills/code-structure
Command: npx skills add https://github.com/oriddd/ai-toolkit --skill code-structure-oriddd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Java microservices often drift into inconsistent package layouts, fat service classes, and tangled dependencies that are hard to test and maintain. This Skill enforces a canonical package hierarchy and proven design patterns so every class stays small, focused, and independently testable. ## Core Features & Use Cases - Canonical Package Hierarchy: Defines the standard layout (controller, operation, service, client, repository, analyzer, scheduler, and more) with strict layering rules from controller down to client. - Reference Design Patterns: Provides Strategy + Registry, OncePerRequestFilter metrics recorders, and Operation/Service layering patterns, plus a catalogue covering Template Method, Decorator, Adapter, Builder, and others. - Architecture Enforcement: Ships ArchUnit test templates that turn layering and naming conventions into build failures, plus a package skeleton and application.yaml template for bootstrapping. - Use Case: When scaffolding a new Spring Boot microservice or refactoring a legacy service, apply this Skill to generate the package skeleton, wire permissions and metrics via strategy registries, and add an ArchUnit test that blocks layering violations in CI. ## Quick Start Apply the code-structure skill to scaffold a new Spring Boot microservice with the canonical package hierarchy and an ArchUnit architecture test.

Frequently Asked Questions about code-structure

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

FAQPage Schema
How do I structure a Spring Boot microservice package hierarchy?

Organize code under a root package into controller, operation, service, client, repository, model, exception, and cross-cutting packages like permission and monitor. Controllers delegate to one Operation, Operations orchestrate Services, and Clients wrap external systems.

How to implement the strategy pattern with a registry in Spring?

Define a strategy interface with a supports or canHandle method, implement concrete @Component strategies, and inject List<Strategy> into a registry or handler that routes by calling canHandle. Adding behavior means adding one new component without touching the handler.

Can ArchUnit enforce package layering rules in Java?

Yes, ArchUnit JUnit 5 tests can assert layered architecture rules, such as controllers not accessing clients directly and services only being accessed by controllers or operations. Violations become build failures instead of code review feedback.

When should I split a large Java service class?

Split when a class exceeds roughly 100 to 200 lines, needs internal section comments, or mixes concerns like validation, transformation, and persistence. Extract each concern into its own small named component such as a Validator, Transformer, or Repository.

What are the limitations of package-level monolith modularization?

Package-level isolation with Spring Modulith prevents direct cross-module calls but relies on discipline and ArchUnit tests rather than true deployment boundaries. Use it as an intermediate step before extracting modules into separate microservices.