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.

install
source · Clone the upstream repo
git clone https://github.com/khumbal/ai-agent-instructions
Claude Code · Install into ~/.claude/skills/
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"
manifest: .copilot/skills/java-coding/SKILL.md
source content

Java 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

  1. Determine what you're building:

    New REST endpoint? → Controller (thin) → Service (logic) → Repository (data) Business logic? → Service layer with

    @Transactional
    , 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

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,
    @Transactional
    boundaries, orchestrate repository calls.
  • 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

PracticeDoDon't
DTOsSeparate request/response DTOs (Records)Expose JPA entities in API
Transactions
@Transactional
on service methods
@Transactional
on controllers
Validation
@Valid
on controller params
Manual null checks everywhere
LoggingSLF4J
@Slf4j
, structured context
System.out.println
Nulls
Optional
returns,
@NonNull
Return null from services
DependenciesConstructor injection (
@RequiredArgsConstructor
)
Field injection (
@Autowired
)

Performance rules

  • @Transactional(readOnly = true)
    for read operations
  • Avoid N+1: use
    @EntityGraph
    or JOIN FETCH
  • Pagination for list endpoints (
    Pageable
    )
  • @Cacheable
    for frequently accessed, rarely changed data
  • Profile before optimizing — don't guess

Feedback loop

After writing/modifying code:

  1. Run
    mvn compile
    → fix compile errors
  2. Run relevant tests → fix failures
  3. Check for missing error handling or edge cases
  4. If any step fails → fix → restart from step 1