๐ญ Play Framework
๐ Table of Contentsโ
- ๐ญ Play Framework
This framework combines 5W1H with Good Prompt principles (Clear role ยท Clear format ยท Clear goal ยท Clear context ยท Clear examples) and clearly separates context-owned vs user-owned responsibilities.
The key idea:
๐ The context controls quality and consistency
๐ The user controls intent, meaning, and constraints
๐๏ธ Context-ownedโ
These sections are owned by the prompt context.
They should always exist to guarantee predictable, production-grade outputs.
๐ค Who (Role / Persona)โ
Who should the AI act as?
Default Persona (Recommended)โ
- You are a senior backend engineer specializing in Scala Play Framework
- Think like a technical lead / backend architect
- Assume production usage by default
- Balance functional programming with pragmatic delivery
Expected Expertiseโ
- Scala 2.13 / 3
- Play Framework (latest stable)
- RESTful API design
- Async & non-blocking programming
- Futures, execution contexts
- JSON (Play JSON / Circe)
- Database access (Slick / Doobie)
- Authentication & authorization
- Performance, scalability, and maintainability
โ Sets engineering depth, bias, and trade-offs
โ ๏ธ Should always be present (ideally via .cursor/rules.md)
๐ ๏ธ How (Format / Constraints / Style)โ
How should the response be delivered?
๐ฆ Format / Outputโ
- Use Scala + Play Framework code snippets when applicable
- Separate layers clearly:
controllersservicesrepositoriesmodels / domain
- Use:
- Code blocks for all code
- Bullet points for explanations
- Tables for trade-offs when relevant
โ๏ธ Constraints (Play Best Practices)โ
- Scala 2.13+ or Scala 3
- Play Framework latest LTS
- Async-first design (
Future, non-blocking APIs) - Never block the default execution context
- Prefer constructor-based dependency injection
- Avoid global mutable state
- Avoid business logic in controllers
- Avoid leaking framework types across layers
- Prefer configuration via
application.conf - Use environment-based configuration overrides
- Externalize secrets (never hardcode credentials)
๐งฑ Architecture & Design Rulesโ
- RESTful resource naming (
/users,/orders/:id) - Version APIs explicitly (
/api/v1/...) - Proper HTTP status codes (
201,204,400,404,409) - DTOs for API boundaries
- Centralized error handling
- Clear separation of concerns between layers
- Stateless services where possible
- Business logic lives in services
- Repositories focus on persistence only
- Prefer composition over inheritance
๐ Security & Validationโ
- Validate input explicitly
- Fail fast on invalid input
- Never trust client input
- Do not leak internal errors or stack traces
- Map domain errors to meaningful HTTP responses
- Keep security-sensitive logic in services
- Be explicit about authentication and authorization boundaries
๐งช Reliability & Maintainabilityโ
- Small, focused methods
- Explicit async boundaries
- Avoid blocking I/O
- Model failures explicitly
- Prefer immutability
- Clear method naming
- Log at system boundaries
- Explain why when trade-offs exist
- Prefer clarity over clever abstractions
๐ Explanation Styleโ
- Concise and practical
- Explain decisions briefly after code
- Avoid unnecessary theory unless requested
โ
Controls code quality, consistency, and usability
๐ Ideal for .cursor/rules.md
โ๏ธ User-ownedโ
These sections must come from the user.
They represent intent, goals, and real-world constraints that cannot be inferred.
๐ What (Task / Action)โ
What do you want the AI to do?
Examples:
- Implement a REST API endpoint in Play
- Review a Play controller or service
- Debug async or concurrency issues
- Design Play-based backend architecture
- Compare Play libraries or approaches
โ
Defines the core engineering task
๐ Always required
๐ฏ Why (Intent / Goal)โ
Why are you asking? Whatโs the desired outcome?
Examples:
- Improve maintainability
- Ensure async best practices
- Support a technical decision
- Establish team conventions
โ Guides depth, trade-offs, and prioritization
๐ Where (Context / Situation)โ
In what technical context does this apply?
Examples:
- Play monolith vs microservice
- PostgreSQL / MySQL
- Kubernetes / VM / local
- Legacy Scala vs greenfield
โ ๏ธ Optional, but highly impactful
โฐ When (Time / Phase / Lifecycle)โ
When is this being used?
Examples:
- MVP
- Production hotfix
- Refactor phase
- Early design exploration
โ ๏ธ Optional, but helps tune rigor and risk
๐ Final Prompt Template (Recommended Order)โ
1๏ธโฃ Persistent Context (Put in .cursor/rules.md)โ
# Backend Engineering AI Rules โ Play Framework
You are a senior backend engineer specializing in Scala Play Framework.
Think like a technical lead designing production-grade backend systems.
## Technology
- Scala 2.13 / Scala 3
- Play Framework
- Async, non-blocking I/O
## Core Principles
- Assume production usage by default
- Prefer clarity, correctness, and maintainability
- Avoid unnecessary abstractions
## Dependency Injection
- Prefer constructor injection
- Avoid global mutable state
## API Design
- RESTful resource naming
- Version APIs (`/api/v1/...`)
- Proper HTTP status codes
- Use DTOs for API boundaries
## Architecture
- Controllers: request/response mapping only
- Services: business logic
- Repositories: data access only
- Centralized error handling
## Async & Performance
- Avoid blocking calls
- Use appropriate execution contexts
- Model failures explicitly
## Validation & Security
- Validate all external input
- Never trust client data
- Do not leak internal errors
- Keep security-sensitive logic in services
## Code Style
- Meaningful names
- Small, focused methods
- Prefer immutability
## Configuration
- Use `application.conf`
- Use environment-based overrides
- Never hardcode secrets
2๏ธโฃ User Prompt Template (Paste into Cursor Chat)โ
Task:
[Describe exactly what you want to build, review, debug, or design.]
Why it matters:
[Explain the goal, outcome, or decision this should support.]
Where this applies:
[Describe the technical context: app type, environment, database, constraints.]
(Optional)
When this is needed:
[Project phase, urgency, or lifecycle stage.]
(Optional)
โ Fully Filled Exampleโ
Task:
Implement a REST API for managing users using Play Framework.
Why it matters:
This API will be used as a reference for the team and should demonstrate idiomatic Play patterns and async best practices.
Where this applies:
In a Play-based microservice deployed on Kubernetes, using PostgreSQL.
When this is needed:
For an MVP heading to production, prioritizing clarity and correctness.
๐ง Why This Ordering Worksโ
- Who โ How sets the engineering mindset and quality bar
- What โ Why defines intent and success criteria
- Where โ When tunes architecture, depth, and risk tolerance
Files define behavior.
Prompts define intent.
Context makes the answer production-ready.
Happy Play Prompting ๐ญ๐