saravanan-paramasivam/java-groq-assistant icon
public
Published on 7/14/2025
java_groq_assistant

java groq using ollama

Rules
Models
Context
40kinput·32koutput
200kinput·8.192koutput
200kinput·8.192koutput
1048kinput·8.192koutput
128kinput·16.384koutput

MCP Servers

Learn more
npx -y @modelcontextprotocol/server-github
npx -y @modelcontextprotocol/server-filesystem ${{ secrets.saravanan-paramasivam/java-groq-assistant/saravanan-paramasivam/filemcp/PATH }}
npx -y @benborla29/mcp-server-mysql
# Spring Boot Java Coding Rules and Best Practices

A comprehensive checklist and guide for writing clean, maintainable, and scalable Spring Boot applications.

---
## 🚀 1. Project Structure and Organization

- Use the standard package structure: `com.yourcompany.projectname`
- Organize by layer: `controller`, `service`, `repository`, `model`, `config`, `dto`, `exception`, `util`
- For large apps, consider **package-by-feature** (e.g., `user`, `order`, `payment`)
- Class Naming: `PascalCase`  
- Variable/Method Naming: `camelCase`  
- Avoid abbreviations and acronyms

---
## 🔧 2. Spring Boot Configuration

- Use `@ConfigurationProperties` over `@Value` for structured config
- Externalize all configuration in `application.yml` or `application.properties`
- Use Spring Profiles (`dev`, `test`, `prod`)
- Validate config with `@Validated`
- Fail fast on startup misconfigurations

---
## 🧠 3. Dependency Injection and Bean Management

- Prefer **constructor injection**
- Avoid field injection (`@Autowired` on fields)
- Be explicit with component scanning (define `basePackages`)
- Use `@Qualifier` when multiple beans of the same type exist

---
## 🧾 4. DTOs and Entities

- Never expose entity objects in API responses
- Use DTOs for both request and response payloads
- Use `ModelMapper` or `MapStruct` to handle mapping
- Validate incoming DTOs using `javax.validation` annotations and `@Valid`

---
## 🧰 5. Service and Repository Layer

- Keep services stateless
- Push reusable logic to utility/helper classes
- Use `interface + implementation` pattern for services and repositories
- Define transaction boundaries with `@Transactional` at the service layer

---
## 📡 6. Controller Layer

- Use `@RestController` for REST APIs
- Handle exceptions globally with `@ControllerAdvice`
- Always return DTOs or wrapper responses
- Use `ResponseEntity` for custom status codes and headers

---
## 🧪 7. Testing

- Unit test services and utilities with **JUnit + Mockito**
- Use `@SpringBootTest` for integration tests
- Test repositories using `@DataJpaTest`
- Use `MockMvc` or `WebTestClient` to test REST endpoints
- Isolate DB with Testcontainers if possible

---
## 🛡️ 8. Security and Validation

- Enable and configure **Spring Security**
- Use input validation to prevent injection and data corruption
- Hash passwords using `BCryptPasswordEncoder`
- Protect endpoints with proper authentication and authorization
- Enable CSRF and configure CORS as required

---
## 🧹 9. Code Quality and Maintainability

- Follow Java code conventions: indentation, braces, spacing, naming
- Use a linter and formatter (e.g., Checkstyle, Spotless)
- Use **Lombok** with care:
  - Avoid `@Data` on JPA entities
  - Prefer `@Getter`, `@Setter`, `@Builder` as needed
- Log using SLF4J: `LoggerFactory.getLogger(...)`
- Avoid using `System.out.println`
- Create and use custom exceptions

---
## ⚡ 10. Performance and Optimization

- Avoid N+1 query problems using `join fetch`, `@EntityGraph`
- Use caching with `@Cacheable`, Redis, or Caffeine
- Perform long-running tasks with `@Async` or Spring Batch
- Configure connection pooling (HikariCP is default)
- Profile and monitor the application with **Actuator**

---
## 🧭 Checklist Summary

- [ ] Use constructor injection
- [ ] Separate DTOs from entities
- [ ] Validate all incoming request data
- [ ] Write unit & integration tests
- [ ] Configure Spring Security properly
- [ ] Externalize all environment-specific config
- [ ] Avoid field injection and circular dependencies
- [ ] Use proper exception handling
- [ ] Monitor and profile using Actuator
- [ ] Document REST APIs with Swagger/OpenAPI

---

Prompts

Learn more

No Prompts configured

Context

Learn more
Reference all of the changes you've made to your current branch
Reference the most relevant snippets from your codebase
Reference the markdown converted contents of a given URL
Uses the same retrieval mechanism as @Codebase, but only on a single folder
Reference the last command you ran in your IDE's terminal and its output
Reference specific functions or classes from throughout your project
Reference any file in your current workspace