Rule
0 installs · 0 said it worked
Cursor rules for writing clean, tested Scala and Kafka code
A set of Cursor rule files guiding the assistant to write functional, immutable Scala 3 code with ScalaTest, Kafka stream testing, and scalafmt formatting conventions.
People use this for
- scala kafka cursor rules
- immutable scala 3 code style rules
- scalatest kafka streams testing prompt
- functional scala clean code guidelines
- scalafmt formatting conventions for scala
- Name
cursor-rules-for-writing-clean-tested-scala-and-kafka-code- Works with
- Cursor
- License
- CC0(as observed at the source)
- Version
- v1 · updated Nov 29, 2026
Imported on Nov 29, 2026 from github.com . License observed at the source on Nov 29, 2026: CC0.
Are you the author?Claim this profileRequest removal
Use this rule
$ curl -fsSL "https://promptcommunity.dev/api/v1/posts/cursor-rules-for-writing-clean-tested-scala-and-kafka-code-ut2k/export/mdc" -o .cursor/rules/cursor-rules-for-writing-clean-tested-scala-and-kafka-code.mdcThen open a new session; Cursor picks it up from .cursor/rules/.
Manual install
Save cursor-rules-for-writing-clean-tested-scala-and-kafka-code.mdc as .cursor/rules/cursor-rules-for-writing-clean-tested-scala-and-kafka-code.mdc for this project or ~/.cursor/rules/cursor-rules-for-writing-clean-tested-scala-and-kafka-code.mdc for every project, then start a new session.
Rule
description: "Cursor rules for Scala Kafka." globs: */ alwaysApply: false
general-scala-clean-code.mdc
- Declare vals/vars as close as possible to first use.
- Name length should be proportional to scope: 1-2 chars allowed only inside small lambdas.
- Avoid nested for-comprehensions deeper than two levels; factor out steps into helpers.
- Split a single source file by responsibility.
- Use tail-rec optimisation (
@tailrec) where appropriate. - Prefer immutable collections and avoid mutation during iteration.
- When interop with Java forces mutability, wrap it in a pure facade with the use of .asScala, to retain functional API.
- When something is nullable, wrap it into an Option, to retain functional API.
- Keep cyclomatic complexity below 10 for any method; IDE inspections should warn.
general-scala-development-practices.mdc
========== GENERAL PRINCIPLES ==========
- You are an experienced Senior Scala Developer.
- You always adhere to SOLID, DRY, KISS and YAGNI principles.
- Prefer pure functions; minimise side-effects. Where effects are required, make them explicit (e.g. using scala.util.Try, Either, or cats-effect IO/Task if adopted).
- Use val over var; collections must be immutable unless mutability is proven cheaper & safe.
- Replace null with Option, Either or a domain-specific ADT.
- Use pattern matching exhaustively and handle the default case only when truly open-ended.
- Prefer for-comprehensions, map/flatMap/fold, and higher-order functions over imperative loops.
- Prefer case classes and sealed traits for algebraic data types.
- Extract common logic into private or package-private helpers; avoid long methods (> 30 LOC).
- Prefer extension methods or type classes over inheritance when adding behaviour.
- Keep public APIs small, surface only what the module owns.
- Break every task into the smallest composable pure functions before wiring them together.
========== NAMING & SYNTAX ==========
- Class / object / trait names are UpperCamelCase nouns (e.g. NotificationStreamApp).
- Methods & vals are lowerCamelCase verbs or nouns (e.g. process, serde, productKey).
- Constants use
SCREAMING_SNAKE_CASE. - Similar to Java’s static final members, if the member is final, immutable and it belongs to a package object or an object, it may be considered a constant.
- Symbolic names (
|>) are allowed only when they align with widespread FP idioms. - Match expressions use
match/caseover nested if/else chains; for simple two-branch logic preferif … then … else …expressions.
========== ERROR HANDLING & LOGGING ==========
- Catch the most specific Exception first; convert checked Java exceptions to an ADT or
Try. - No empty
catchblocks; log at debug or error level with a meaningful message. - Leverage
scala.util.Using(or cats-effectResource) for auto-closing resources. - Avoid “defensive” logging or
println; use SLF4J (Logback) with the scala-logging wrapper.
========== TESTING ==========
- Use ScalaTest in a Given-When-Then layout with the use of AnyFlatSpec.
- Focus on critical paths and business invariants; do not over-test boilerplate.
- Property-based tests (ScalaCheck) for pure functions with non-trivial invariants.
- Set up integration tests as a subproject named “integration” and treat integration tests as standard tests
========== PERFORMANCE & SAFETY ==========
- Avoid blocking calls inside Kafka stream processing; if unavoidable, off-load to a dedicated thread-pool.
- Convert Java collections to Scala equivalents once at the boundary; never bounce back and forth.
- Use underscore-separated digits for large numeric literals (e.g.
val timeoutMs = 30_000).
========== MODERN SCALA 3 FEATURES ==========
- Use Enums for finite alternatives instead of Java-style enums.
- Embrace opaque types to avoid accidental misuse of primitive wrappers.
- Use context parameters (
using) for type-class evidence instead of classic implicit lists when convenient. - Prefer
given/usingsyntax overimplicitwhere supported.
========== CLEAN BUILD ==========
- The sbt build uses scalafmt for formatting; treat any scalafmt violation as a build error.
kafka-development-practices.mdc
- All topic names config values (Typesafe Config or pure-config).
- Use Format or Codec from the JSON or AVRO or another library that is being used in the project.
- Streams logic must be tested with
TopologyTestDriver(unit-test) plus an integration test against local Kafka.
linting-formatting.mdc
- scalafmt: Enforce Google-inspired scalafmt configuration with
maxColumn = 100.
No result recorded yet. Added it? File a Tried-it report so the next person knows how it went in your editor.
Tried it
Reports from people who added this rule to their editor. They roll up into the badges above.
No one has filed a report yet. Try the prompt and be the first.
Related rules
- Cursor rules enforcing clean, readable, maintainable code practices
A Cursor .mdc rule file that guides the assistant toward clean code: named constants, meaningful names, sparing comments, single-purpose functions, DRY, language style standards, extracted conditionals, continuous refactoring, and version control.
Coding · @patrickjs
- Agent that writes, runs, and repairs tests after code changes
A system prompt defining a test-writer-fixer agent that writes unit, integration, and end-to-end tests, runs suites, analyzes failures, and repairs tests without weakening them.
Coding · @ersinyilmaz
- Generate RAG-ready lifecycle phase documentation in Markdown
A meta-prompt that has the model write a production-grade, RAG-optimized Markdown artifact for a chosen enterprise lifecycle phase (01–16), with YAML frontmatter, phase-specific deliverables, and cross-cutting governance controls.
Data & Finance · @clicklynx2dspy
- Cursor rules for writing and testing Xian smart contracts in Python
A Cursor rules file that guides the assistant through writing Xian blockchain smart contracts in Python, covering naming, state, context variables, events, error handling, and unittest-based testing with security checks.
Coding · @patrickjs
- Find and plan refactoring of complex, frequently changed Python functions
Skill-style prompt that makes the model act as a Python maintainer's assistant: it scans code for high-complexity functions using a stdlib AST script, ranks hotspots by git churn, reads the top ones, and proposes small test-backed refactoring steps and a report.
Coding · @f
License: CC0v1 · published Nov 29, 2026
Comments
No comments yet. If you tried this prompt, say how it went.