A comprehensive collection of instruction files for GitHub Copilot (and other AI coding assistants) to generate high-quality, production-ready Spring Boot code following industry best practices.
This repository contains curated best practices for building enterprise-grade Spring Boot applications. Each file provides DO/DON'T patterns with examples, focusing on:
- Memory Efficiency – Minimize allocations, use appropriate collection sizes
- Readability – Clear, self-documenting code following Google Java Style
- Maintainability – SOLID principles, clean architecture patterns
- Performance – Efficient queries, caching, virtual threads
| Technology | Version |
|---|---|
| Java | 21 (LTS) |
| Spring Boot | 3.5.x |
| Spring Framework | 6.x |
| Spring Security | 6.x |
| Spring Data JPA | 3.x |
spring-boot/
├── .github-copilot-instructions.md # Main instructions file (entry point)
├── README.md # This file
└── copilot-rules/
├── collections.md # Lists, Sets, Maps, immutability
├── concurrency.md # Virtual threads, async, thread safety
├── configuration.md # @ConfigurationProperties, profiles
├── data-access.md # JPA, repositories, transactions
├── date-time.md # java.time API, timezones, formatting
├── dependency-injection.md # DI patterns, bean scopes
├── error-handling.md # Exceptions, @ControllerAdvice
├── memory-management.md # Resource cleanup, optimization
├── observability.md # Logging, metrics, tracing
├── oop-principles.md # SOLID, composition, encapsulation
├── resilience.md # Circuit breakers, retries, timeouts
├── rest-api-design.md # Controllers, DTOs, versioning
├── security.md # Spring Security 6.x, JWT, CORS
├── streams-lambdas.md # Functional patterns, Optional
├── testing.md # JUnit 5, Testcontainers, slices
└── transactions.md # @Transactional, propagation, rollback
-
Copy the main instructions file to your project:
# Copy to your repository root cp .github-copilot-instructions.md /path/to/your/project/ -
Copy specific rule files you need:
# Copy all rules cp -r copilot-rules /path/to/your/project/ # Or copy specific files cp copilot-rules/data-access.md /path/to/your/project/copilot-rules/
-
Update file paths in
.github-copilot-instructions.mdif you placed files in different locations.
- Copy the files to your project's
.cursor/rules/directory:mkdir -p .cursor/rules cp .github-copilot-instructions.md .cursor/rules/ cp -r copilot-rules .cursor/rules/
Simply include the relevant markdown files in your project or paste the content into your assistant's context/instructions.
- OOP Principles – SOLID, sealed classes, pattern matching
- Collections – Right collection types, immutability, null safety
- Streams & Lambdas – Functional patterns, primitive streams
- Error Handling – Exception hierarchies, @ControllerAdvice
- Concurrency – Virtual threads, scoped values, CompletableFuture
- Memory Management – Resource cleanup, GC-friendly code
- Date & Time – java.time API, timezones, formatting
- Dependency Injection – Constructor injection, scopes
- REST API Design – Controllers, DTOs, RFC 7807 errors
- Data Access – JPA, repositories, N+1 prevention
- Transactions – @Transactional, propagation, isolation
- Configuration – Type-safe config, profiles
- Security – Spring Security 6.x, JWT, CORS
- Testing – JUnit 5, Testcontainers, slice tests
- Observability – Logging, metrics, tracing
- Resilience – Circuit breakers, retries, bulkheads
@Service
@RequiredArgsConstructor
public class OrderService {
private final OrderRepository repository;
private final PaymentService paymentService;
}public record CreateOrderRequest(
@NotBlank String customerId,
@NotEmpty List<OrderItem> items
) {}try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
List<Future<Result>> futures = tasks.stream()
.map(task -> executor.submit(() -> process(task)))
.toList();
}Feel free to:
- Add project-specific patterns to any file
- Remove files for technologies you don't use
- Adjust examples to match your coding conventions
- Add new topic files for additional frameworks
Each instruction file follows this structure:
# Topic Name
## 1. Category Name
### ✅ DO: Brief description
\`\`\`java
// Example code
\`\`\`
**When to use:**
- Guidance on when to apply this pattern
### ❌ DON'T: Anti-pattern description
\`\`\`java
// Anti-pattern code
\`\`\`
**Why it's wrong:** Explanation- Spring Boot Documentation
- Google Java Style Guide
- Effective Java (3rd Edition)
- Spring Security Reference
Contributions are welcome! Please:
- Follow the existing file format
- Include both DO and DON'T examples
- Add "When to use" guidance
- Test code examples conceptually
MIT License - feel free to use and modify for your projects.