spring-boot-patterns

A set of preferred patterns and conventions for building Spring Boot services. Spring Boot is a Java framework for creating web services and applications.

In plain words
What is it for?
Use it when starting a Spring Boot service to choose its layers, Java or Kotlin usage, database setup, API generation, error responses, and build conventions.
Why use it?
It gives development work a consistent structure and recommends established choices for code organization, testing, persistence, and error handling.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/cagridursun/ai-peer-live-coding-agent/spring-boot-patterns
Clone the repo
git clone --depth 1 https://github.com/cagridursun/ai-peer-live-coding-agent

Made for: Cursor.

Per session 760 This file is loaded in full into every session.
When invoked 760 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00760 $0.00760
Opus 5 $0.00380 $0.00380
Sonnet 5 $0.00152 $0.00152
Haiku 4.5 $0.00076 $0.00076

Measured 2d ago against content hash 4870840e8950, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

spring-boot-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/spring-boot-patterns.mdc · 56 lines

How it starts

The opening of the file, as written. The whole thing — 56 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Spring Boot — Preferred Patterns & Conventions

Reference Code

When building a new service, look for proven patterns in your own practice projects or open-source Spring Boot examples:

  • [EXAMPLE_PROJECT_PATH/URL] conversational / workflow APIs (state machines, step validation)
  • [EXAMPLE_PROJECT_PATH/URL] CRUD REST APIs (standard controller → service → repository)
  • [EXAMPLE_PROJECT_PATH/URL] OpenAPI-first services (codegen for interfaces and DTOs)

Consult those references for project structure, Maven config, test patterns, and error handling — adapt to the interview scope, not copy wholesale.

Architecture

  • 3-layer max: Controller → Service → Repository
  • Kotlin for entity/model classes only (no Lombok); Java for all other code — optional, use when the problem fits
  • OpenAPI codegen for controller interfaces and DTOs (interfaceOnly=true) — optional
  • JPA + H2 in-memory with create-drop DDL — when persistence is required
  • @RestControllerAdvice for centralized error responses
  • BigDecimal for monetary values
  • ConcurrentHashMap for in-memory rate limiting or caches

Maven / Build

  • Kotlin compiler plugins: spring + jpa (allopen + noarg) — when using Kotlin entities
  • kotlin-maven-noarg dependency required for JPA entity no-arg constructors
  • Kotlin compiles before Java; OpenAPI generated sources in Kotlin sourceDirs
  • Java default-compile phase none, custom java-compile after Kotlin — when mixing Kotlin + Java
  • Set maven.compiler.source, maven.compiler.target, maven.compiler.release explicitly in <properties> for IDE compatibility
  • JaCoCo 0.8.14+ for Java 21+ (older versions may fail on newer class file versions)
  • Exclude generated API packages from JaCoCo coverage reports

Error Handling

  • Custom exceptions: NotFoundException (404), ConflictException (409), ValidationException (400), RateLimitException (429)
  • GlobalExceptionHandler maps to ErrorResponse with code, message, details (list of FieldError)
  • Filter-thrown exceptions: inject HandlerExceptionResolver, call resolveException() to route through @RestControllerAdvice
  • Always structured JSON, never plain text

Read the full file on GitHub · 56 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 56 lines · 760 tokens per session scan A 4870840e8950

Subscribe to this mod's changes

spring-boot-patterns is a cursor rule published in the GitHub repository cagridursun/ai-peer-live-coding-agent (14 stars, last pushed 21d ago), licensed MIT. It adds 760 tokens to every session, about $0.0038 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.