Here's a robust prompt format optimized for DeepSeek-R1 and similar models when learning Java/Spring Boot. This structure provides clear context, constraints, and output requirements to get high-quality responses:
### Role
You are a senior Java Spring Boot developer mentoring a beginner. Your responses must prioritize:
- Industry best practices
- Spring Boot 3 conventions
- Java 17+ features
- Clear explanations of core concepts
### Context
I'm building a [describe functionality] application. Current setup:
- Spring Boot 3.x
- Java 17
- Maven
- [Add other relevant tech: e.g., Spring Data JPA, H2 DB]
### Task
Create a [component type] that:
- [Key function 1] (e.g., "Exposes REST endpoint for X")
- [Key function 2] (e.g., "Validates Y using Z")
- [Key requirement] (e.g., "Follows DDD principles")
### Constraints
- Use annotations over XML config
- Apply SOLID principles
- Handle errors using [specify approach]
- [Add specific constraints: e.g., "No field injection", "Use records for DTOs"]
- Explain complex Spring annotations
### Output Format
```java
// Complete code implementation
Explanation (bullet points):
- Why this approach is recommended for beginners
- How [key annotation] works (e.g., @RestController vs @Controller)
- Alternative approaches to avoid
---
### Example Prompt (User Query)
```markdown
### Role
Senior Java developer specializing in Spring Boot education
### Context
Building a book inventory API. Current setup:
- Spring Boot 3.2
- Java 17
- Spring Data JPA
- H2 in-memory database
### Task
Create a BookController that:
1. Exposes GET /api/books endpoint returning all books
2. Uses DTO pattern to hide entity details
3. Implements proper error handling for 404 cases
### Constraints
- Use constructor injection only
- Return ResponseEntity with proper HTTP status
- Use records for DTOs
- Explain why DTO pattern is essential
- Avoid @Autowired on fields
### Output Format
```java
// Complete controller implementation
Explanation (bullet points):
- Purpose of each annotation
- Why DTOs are used
- How error handling works in this context
---
### Why This Works Well
1. **Structured Context**
- Clearly defines tech stack versions (critical for Spring Boot)
- Specifies persistence/DB choices (avoids generic examples)
2. **Task Precision**
- Uses action verbs ("Exposes", "Implements")
- Specifies exact endpoint details
- Mentions patterns to apply (DTO pattern)
3. **Beginner-Friendly Constraints**
- Bans anti-patterns (field injection)
- Enforces modern practices (records for DTOs)
- Requires explanations of "why"
4. **Output Formatting**
- Enforces compilable code blocks
- Mandates conceptual explanations
- Separates code from theory
---
### Tips for Best Results
1. **Gradual Complexity**
Start with simple tasks (single controller) before requesting full services
2. **Explicit Versioning**
Always specify Spring Boot/Java versions (behavior differs significantly)
3. **Error Handling Focus**
Always include error handling requirements (most tutorials skip this)
4. **Anti-Pattern Calls**
Explicitly ban outdated practices:
`- Avoid: @Autowired fields, mutable DTOs, Thymeleaf for APIs`
5. **Request Explanations For**
- Explain: How dependency injection works here
- Explain: What @Transactional does in this context
This format gives the AI precise boundaries while creating teaching-focused output. For advanced topics (security, transactions), add specific constraint sections like:
Security
- Use method security @PreAuthorize
- Explain role-based access control