Ai-agent-instructions java-coding
Expert Java development covering Spring Boot applications, REST APIs, service layer patterns, dependency injection, error handling, and production-ready code. Applies clean architecture, proper exception handling, logging, and performance best practices. Use this skill when writing Java code, creating Spring Boot services, designing REST APIs, implementing business logic, or working with any .java files — including controllers, services, repositories, DTOs, and configuration classes.
git clone https://github.com/khumbal/ai-agent-instructions
T=$(mktemp -d) && git clone --depth=1 https://github.com/khumbal/ai-agent-instructions "$T" && mkdir -p ~/.claude/skills && cp -r "$T/.copilot/skills/java-coding" ~/.claude/skills/khumbal-ai-agent-instructions-java-coding && rm -rf "$T"
.copilot/skills/java-coding/SKILL.mdJava Coding
When to use this skill
Use when writing or modifying Java code, creating Spring Boot services, designing REST APIs, implementing business logic, or working with any .java files.
Conditional workflow
-
Determine what you're building:
New REST endpoint? → Controller (thin) → Service (logic) → Repository (data) Business logic? → Service layer with
, proper error handling New entity/DTO? → Records for DTOs, entities separate from API surface Bug fix? → Read existing code first, understand the flow, fix with tests@Transactional
Architecture rules
Follow strict layered architecture:
Request → Controller → Service → Repository → Database ↓ ↓ Validate Business logic Map DTO Transactions HTTP status Error handling
- Controller: Thin — validate input, map DTOs, return HTTP status. No business logic.
- Service: Business rules,
boundaries, orchestrate repository calls.@Transactional - Repository: Data access only. Spring Data JPA methods.
Code patterns
See Spring Boot patterns for complete Controller, Service, Exception Handler, and Business Exception templates.
Mandatory conventions
| Practice | Do | Don't |
|---|---|---|
| DTOs | Separate request/response DTOs (Records) | Expose JPA entities in API |
| Transactions | on service methods | on controllers |
| Validation | on controller params | Manual null checks everywhere |
| Logging | SLF4J , structured context | |
| Nulls | returns, | Return null from services |
| Dependencies | Constructor injection () | Field injection () |
Performance rules
for read operations@Transactional(readOnly = true)- Avoid N+1: use
or JOIN FETCH@EntityGraph - Pagination for list endpoints (
)Pageable
for frequently accessed, rarely changed data@Cacheable- Profile before optimizing — don't guess
Feedback loop
After writing/modifying code:
- Run
→ fix compile errorsmvn compile - Run relevant tests → fix failures
- Check for missing error handling or edge cases
- If any step fails → fix → restart from step 1