Skip to content

Instantly share code, notes, and snippets.

@nathanaelabel
Forked from abdkadirozer/global_rules.md
Last active September 15, 2025 04:59
Show Gist options
  • Select an option

  • Save nathanaelabel/3b2614998748700a48bc44b2475062c9 to your computer and use it in GitHub Desktop.

Select an option

Save nathanaelabel/3b2614998748700a48bc44b2475062c9 to your computer and use it in GitHub Desktop.
Windsurf rules for Spring Boot Developers

Global Rules

General Principles

  • Speak in a clear, concise, and easy-to-understand manner. Use English.
  • Follow coding conventions and best practices for Java development.
  • Write clean, efficient, and well-documented code.
  • Adhere to Java best practices and utilize Java 17+ features effectively.
  • Follow the SOLID principles and maintain high cohesion and low coupling in design.
  • After your changes, run ./gradlew build to validate your code. If there are any errors, fix them before committing.

Build and CI/CD

  • Use Gradle as the primary build system.
  • Automate builds, tests, and deployments using GitHub Actions.
  • Ensure CI/CD pipelines are optimized for speed and reliability.

Code Style

  • Code style should be rely on checkstyle.xml file that is located in config/checkstyle/checkstyle.xml if it exists.
  • Use the ./gradlew checkstyleMain and ./gradlew checkstyleTest command to check code formatting and style.
  • Use camelCase for variables and methods, PascalCase for classes, and ALL_CAPS for constants.
  • Avoid static imports except for constants.
  • Don't add comment lines to generated code.

Dependency Management

  • Rely on Spring Boot starters for core dependencies.
  • Lock versions for critical dependencies to ensure stability.

Spring Boot Guidelines

  • Structure the application using controllers, services, repositories, and configurations.
  • Leverage Spring Boot's auto-configuration features effectively.
  • Use Spring Data JPA for ORM and database access.

Testing

  • Write unit tests with JUnit 5, ensuring at least 80% code coverage.
  • Use MockMvc for testing controllers and Mockito for mocking dependencies.
  • Write meaningful test names describing expected behavior.

Performance and Optimization

  • Optimize database queries with proper indexing and pagination.
  • Implement caching using Spring Cache abstraction for repetitive operations.
  • Avoid N+1 query issues by configuring fetch strategies in JPA.

Security

  • Enforce authentication and authorization using Spring Security.
  • Always hash passwords using BCrypt or similar algorithms.
  • Enable CSRF protection and enforce HTTPS in production environments.

Logging and Monitoring

  • Use SLF4J with Logback for structured logging.
  • Set appropriate log levels (ERROR, WARN, INFO) for clarity.
  • Monitor and expose metrics using Spring Boot Actuator.

API Documentation

  • Use Springdoc OpenAPI to generate interactive API documentation.

On Save

  • Run checkstyleMain for main source files.
  • Run checkstyleTest for test files.

On Commit

  • Run all checks (checkstyleMain, checkstyleTest, test, lint) before commit.
  • Ensure the repository is in a clean state before executing checks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment