Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions promptbook/prompts.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,26 @@
],
"formatNotes": "All three. Point the tool at the repository package, entity package, and the service/controller call sites first. Prefer fixing fetch plans and projections over enabling open-in-view. Copilot: apply path-scoped instructions for `**/*Repository.java` and entity packages.",
"body": "Task: Review and harden Spring Data JPA queries and fetch plans for the feature I specify. Eliminate N+1 and pagination traps; prefer DTO projections on read paths; keep @Query parameterized and transactional boundaries clear.\n\nContext placeholders (fill from the repo or ask only if missing):\n- Module / package root: {{PACKAGE_ROOT}} (e.g. com.example.orders)\n- Primary entities: {{ENTITIES}} (comma-separated)\n- Hot endpoints or use cases: {{USE_CASES}} (e.g. list orders, order detail, admin search)\n- Pagination style required: {{PAGINATION}} (Page | Slice | keyset | none)\n- Max page size: {{MAX_PAGE_SIZE}}\n- Open-in-view policy: {{OPEN_IN_VIEW}} (off | on-legacy | unknown)\n- Soft-delete in play: {{SOFT_DELETE}} (yes | no | unknown)\n- DB dialect: {{DB_DIALECT}} (PostgreSQL | MySQL | SQL Server | other)\n- Query-budget test harness available: {{QUERY_BUDGET}} (datasource-proxy | Hibernate statistics | none)\n\nRequirements:\n\n1. Inventory\n - Repositories under {{PACKAGE_ROOT}} touching {{ENTITIES}}\n - FetchType on associations; existing `@EntityGraph`, `JOIN FETCH`, `@BatchSize`\n - Call sites for {{USE_CASES}} (controller \u2192 service \u2192 repository)\n - Any `Pageable` + collection fetch combinations; `findAll` without bounds\n - Native/`@Query` strings; modifying queries; soft-delete filters if {{SOFT_DELETE}}=yes\n\n2. Design\n - Per {{USE_CASES}}: projection vs entity graph vs fetch join vs batch fetch\n - If {{PAGINATION}} needs collections: two-step ID page then fetch-by-ids (never collection JOIN FETCH + Pageable)\n - Cap page size at {{MAX_PAGE_SIZE}}; whitelist sort properties\n - Respect {{OPEN_IN_VIEW}}: if off/unknown, fetch or project inside `@Transactional(readOnly = true)`\n - Index notes for new WHERE/ORDER BY under {{DB_DIALECT}}\n - If {{QUERY_BUDGET}} \u2260 none: add or outline a statement-count assertion for the hottest list path\n\n3. Author artifacts (prefer concrete diffs)\n - Repository method changes (`@EntityGraph`, `@Query`, projections)\n - Service transaction + DTO mapping adjustments\n - Optional Flyway/Liquibase index stub only if filters changed (do not invent unrelated schema)\n - Test sketches: result correctness + query budget when {{QUERY_BUDGET}} allows\n\n4. Verification\n - Explain why N+1 is gone for {{USE_CASES}}\n - Confirm no HHH90003004-style in-memory pagination\n - Grep: no entity returns on public API for list paths; no string-concat query parameters\n - Soft-delete + uniqueness notes if {{SOFT_DELETE}}=yes\n\nConstraints:\n- Do not invent schema or indexes unrelated to {{USE_CASES}}.\n- Minimal diff; match existing repository style (derived vs `@Query`).\n- No enabling open-in-view as a \u201cfix\u201d for LazyInitializationException.\n- Optimize for GitHub Copilot, Claude Code, and Codex \u2014 concrete Java and checklists.\n\nOutput format:\n1. Plan (fetch strategy per use case)\n2. Code diffs (repository/service/DTO)\n3. Index / migration notes (if any)\n4. Verification checklist + query-budget evidence\n5. Residual risks (cartesian joins, soft-delete, count query cost)\n\nStart from repositories and entities under {{PACKAGE_ROOT}}. Prefer projections and explicit fetch plans over EAGER mappings or open-in-view.\n"
},
{
"id": "wire-spring-cache-redis",
"title": "Wire Spring Cache With Redis",
"whenToUse": "Scaffold or harden Redis-backed Spring Cache for a named service/module with concrete TTLs, serializers, and eviction.",
"tools": [
"copilot",
"claude-code",
"codex"
],
"tags": [
"java",
"spring-boot",
"redis",
"cache",
"performance",
"azure"
],
"formatNotes": "All three. Point the tool at the cache configuration package and the service methods to annotate. Prefer RedisCacheManagerBuilderCustomizer over an ad-hoc CacheManager bean that disables Boot's spring.cache.redis.* properties. Copilot: apply path-scoped instructions to cache config and @Cache* call sites. Claude Code: skill plus the config class. Codex: AGENTS.md cache section or docs/agents/spring-boot-cache-redis.md, then the diff.",
"body": "Task: Wire or harden Spring Cache backed by Redis for the module I specify. Produce a small diff: explicit Redis cache type, per-cache TTLs, a safe serializer, namespaced keys, targeted eviction, and tests that match the repo.\n\nContext placeholders (fill from the repo or ask only if missing):\n- Module / package: {{MODULE}}\n- Cache names: {{CACHE_NAMES}}\n- TTL per cache name: {{TTLS}} (for example catalog=10m, productById=5m)\n- Serializer: {{SERIALIZER}} (jackson-per-type | generic-jackson-allowlist | keep-existing)\n- Redis target: {{REDIS_TARGET}} (local | Azure Cache for Redis)\n- Fail mode: {{FAIL_MODE}} (fail-open | fail-closed)\n- Test style: {{TEST_STYLE}} (unit-noop | testcontainers | both)\n\nRequirements:\n\n1. Inventory\n - Starters present (`spring-boot-starter-cache`, `spring-boot-starter-data-redis`) and `spring.cache.type`\n - Where `@EnableCaching` lives (application class vs isolated `@Configuration`)\n - Existing `CacheManager`, `RedisCacheConfiguration`, or `RedisCacheManagerBuilderCustomizer` beans\n - `spring.cache.redis.*` and `spring.data.redis.*` (TTL, nulls, prefix, timeout, SSL, pool)\n - `@Cacheable` / `@CacheEvict` / `@CachePut` in {{MODULE}}: keys, `allEntries`, `unless`, `condition`, `sync`\n - How tests get a cache today (sliced context, embedded, shared host, none)\n - If {{REDIS_TARGET}} is Azure Cache for Redis: TLS, auth style already in repo (access key vs Entra), private endpoint or firewall notes. Do not read secret values.\n\n2. Design\n - `spring.cache.type=redis`. Move `@EnableCaching` onto an isolated `@Configuration` if it sits on the application class.\n - Global TTL floor plus per-cache TTL from {{TTLS}} via `RedisCacheManagerBuilderCustomizer`, derived from Boot's `RedisCacheConfiguration`. Do not add a `CacheManager` bean that drops Boot properties.\n - {{SERIALIZER}}: typed Jackson per cache when each name has one value class; generic Jackson only with an allowlisted polymorphic validator. String key serializer. Keep JDK serialization only when {{SERIALIZER}}=keep-existing, and say so.\n - Key prefix: application, environment, schema version. `use-key-prefix` stays true. SpEL keys stable and identical on read and evict. No secrets or PII in keys or values.\n - Evict with the same key. No `allEntries=true` unless the keyspace is tiny and the PR says why. Otherwise version the prefix or a SCAN-based writer.\n - Null policy: `unless` / `condition` or a short null TTL. Disabling null caching requires `unless` so ordinary null returns do not throw.\n - {{FAIL_MODE}}: fail-closed keeps the default error handler (Redis errors fail the call). Fail-open swallows cache-get errors only, logs them, and still runs the method. Do not swallow evict errors for data that must not stay stale.\n - {{REDIS_TARGET}}=Azure Cache for Redis: TLS on, password or Entra token from env / existing Key Vault reference, no public-network shortcut. {{REDIS_TARGET}}=local: localhost or Testcontainers only.\n\n3. Author config, annotations, and tests\n - Property and `RedisCacheManagerBuilderCustomizer` changes for {{CACHE_NAMES}}\n - Annotations on the service methods that own {{CACHE_NAMES}}, matching existing style\n - {{TEST_STYLE}}=unit-noop: `@AutoConfigureCache` or `spring.cache.type=none` on slices; no Redis socket\n - {{TEST_STYLE}}=testcontainers or both: pinned Redis image, hit, miss, and evict for the hottest cache\n - No new dependency unless the module cannot compile without it\n\n4. Verification checklist\n - [ ] `spring.cache.type=redis`; `@EnableCaching` not on the application class\n - [ ] Each name in {{CACHE_NAMES}} has the TTL from {{TTLS}}\n - [ ] Boot `spring.cache.redis.*` still apply (customizer, not a replacement manager)\n - [ ] Serializer matches {{SERIALIZER}}; prefix is namespaced; keys match on read and evict\n - [ ] No `allEntries=true` on a large keyspace; null policy cannot throw on a normal null\n - [ ] {{FAIL_MODE}} is implemented in `CacheErrorHandler` or explicitly left at the default\n - [ ] Tests match {{TEST_STYLE}} and do not point at Azure or a shared server\n - [ ] Diff contains no access keys, connection strings, or invented secret names\n - [ ] Run the module's existing test command and show the result\n\nConstraints:\n- Minimal diff. Match project style (annotations, property files, test base classes).\n- No secrets in the repo. Use placeholders or the app's existing secret mechanism.\n- Do not enable `spring.jpa.open-in-view` or any unrelated feature (security, actuator exposure, schema changes).\n- Do not call `FLUSHDB` / `FLUSHALL`. Do not disable key prefixes.\n- Optimize for GitHub Copilot, Claude Code, and Codex: concrete paths and checklists.\n\nOutput format:\n1. Plan (TTL map, serializer, prefix, fail mode, eviction)\n2. Diff (config, annotations, tests)\n3. Verification checklist with what you actually ran\n4. Residual risks (stampede across pods, transaction-aware gap, Azure memory policy)\n\nStart from {{MODULE}}. Prefer `RedisCacheManagerBuilderCustomizer` over a hand-built `CacheManager`.\n"
}
]
}
Loading
Loading