prizmkit 1.1.54 → 1.1.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/bundled/VERSION.json +3 -3
  2. package/bundled/rules/_rules-metadata.json +6 -1
  3. package/bundled/rules/general/cohesive-modeling.md +27 -0
  4. package/bundled/skills/_metadata.json +1 -1
  5. package/bundled/skills/app-planner/SKILL.md +152 -4
  6. package/bundled/skills/app-planner/references/rules/backend/derivation-rules.md +609 -0
  7. package/bundled/skills/app-planner/references/rules/backend/fixed-rules.md +285 -0
  8. package/bundled/skills/app-planner/references/rules/backend/question-bank.md +249 -0
  9. package/bundled/skills/app-planner/references/rules/backend/template.md +173 -0
  10. package/bundled/skills/app-planner/references/rules/database/derivation-rules.md +373 -0
  11. package/bundled/skills/app-planner/references/rules/database/fixed-rules.md +211 -0
  12. package/bundled/skills/app-planner/references/rules/database/question-bank.md +184 -0
  13. package/bundled/skills/app-planner/references/rules/database/template.md +158 -0
  14. package/bundled/skills/app-planner/references/rules/frontend/derivation-rules.md +810 -0
  15. package/bundled/skills/app-planner/references/rules/frontend/fixed-rules.md +188 -0
  16. package/bundled/skills/app-planner/references/rules/frontend/question-bank.md +302 -0
  17. package/bundled/skills/app-planner/references/rules/frontend/template.md +320 -0
  18. package/bundled/skills/app-planner/references/rules/mobile/derivation-rules.md +639 -0
  19. package/bundled/skills/app-planner/references/rules/mobile/fixed-rules.md +290 -0
  20. package/bundled/skills/app-planner/references/rules/mobile/question-bank.md +232 -0
  21. package/bundled/skills/app-planner/references/rules/mobile/template.md +175 -0
  22. package/bundled/skills/prizm-kit/SKILL.md +1 -1
  23. package/bundled/skills/prizmkit-code-review/SKILL.md +10 -5
  24. package/bundled/skills/prizmkit-implement/SKILL.md +1 -0
  25. package/bundled/skills/prizmkit-init/SKILL.md +47 -6
  26. package/bundled/skills/prizmkit-init/references/config-schema.md +7 -3
  27. package/bundled/skills/prizmkit-init/references/rules/layer-detection.md +41 -0
  28. package/package.json +1 -1
@@ -0,0 +1,173 @@
1
+ # Backend Rules — {{ project_name }}
2
+
3
+ > This document was generated by the `backend-rules` skill on {{ generated_at }}
4
+ > Audience: All backend developers + all AI coding assistants on this project
5
+ >
6
+ > **Usage**:
7
+ > 1. All AI coding assistants must read this file before generating or modifying any backend code
8
+ > 2. This document takes precedence over "general best practices" in AI training data
9
+ > 3. Code conflicting with this document must not be committed
10
+
11
+ ---
12
+
13
+ ## 0. TL;DR — Key Decisions at a Glance
14
+
15
+ | Dimension | Decision |
16
+ |-----------|----------|
17
+ | Language | {{ language }} |
18
+ | Runtime Version | {{ runtime_version }} |
19
+ | Framework | {{ framework }} |
20
+ | Architecture Pattern | {{ architecture }} |
21
+ | API Style | {{ api_style }} |
22
+ | API Documentation | {{ api_docs }} |
23
+ | ORM | {{ orm }} |
24
+ | Database | {{ database }} |
25
+ | Authentication | {{ auth_scheme }} |
26
+ | Caching | {{ cache }} |
27
+ | Message Queue | {{ mq }} |
28
+ | Containerization | {{ container }} |
29
+ | Test Requirements | {{ test_requirement }} |
30
+ | Test Framework | {{ test_framework }} |
31
+ | Mock Strategy | {{ mock_strategy }} |
32
+ | Logging | {{ logging }} |
33
+ | Monitoring | {{ monitoring }} |
34
+
35
+ ---
36
+
37
+ ## 1. Project Structure
38
+
39
+ {{ FIXED_RULES_STRUCTURE }}
40
+
41
+ {{ arch_rules }}
42
+
43
+ ---
44
+
45
+ ## 2. API Design
46
+
47
+ {{ FIXED_RULES_API }}
48
+
49
+ {{ api_rules }}
50
+
51
+ ---
52
+
53
+ ## 3. Error Handling
54
+
55
+ {{ FIXED_RULES_ERROR }}
56
+
57
+ ---
58
+
59
+ ## 4. Security
60
+
61
+ {{ FIXED_RULES_SECURITY }}
62
+
63
+ {{ auth_rules }}
64
+
65
+ {{ FIXED_RULES_RATE_LIMITING }}
66
+
67
+ ---
68
+
69
+ ## 5. Database
70
+
71
+ For schema design standards (normalization, column types, indexing, migration management), refer to `database-rules.md` (generated separately by the `database-rules` skill). This section covers backend-perspective database concerns only.
72
+
73
+ {{ FIXED_RULES_DATABASE }}
74
+
75
+ {{ data_rules }}
76
+
77
+ ---
78
+
79
+ ## 6. Observability
80
+
81
+ {{ FIXED_RULES_OBSERVABILITY }}
82
+
83
+ {{ FIXED_RULES_TRACING }}
84
+
85
+ {{ observability_rules }}
86
+
87
+ ---
88
+
89
+ ## 7. Configuration Management
90
+
91
+ {{ FIXED_RULES_CONFIG }}
92
+
93
+ ---
94
+
95
+ ## 8. Async & Message Queues
96
+
97
+ {{ FIXED_RULES_ASYNC }}
98
+
99
+ {{ FIXED_RULES_MESSAGE_DELIVERY }}
100
+
101
+ {{ mq_rules }}
102
+
103
+ ---
104
+
105
+ ## 8b. Graceful Shutdown
106
+
107
+ {{ FIXED_RULES_GRACEFUL_SHUTDOWN }}
108
+
109
+ ---
110
+
111
+ ## 9. Testing
112
+
113
+ {{ FIXED_RULES_TEST }}
114
+
115
+ {{ test_rules }}
116
+
117
+ ---
118
+
119
+ ## 10. AI Vibecoding Behavior Constraints
120
+
121
+ ### 10.1 Baseline Constraints (project-agnostic, always active)
122
+
123
+ {{ FIXED_RULES_AI_BASE }}
124
+
125
+ ### 10.2 Project-Specific Hard Constraints
126
+
127
+ - **Adding dependencies**: {{ ai_dependency_rule }}
128
+ - **Modifying shared modules**: {{ ai_breaking_change_rule }}
129
+ - **Modifying configuration**: {{ ai_config_rule }}
130
+
131
+ ### 10.3 Mandatory Pre-Actions (before every code generation)
132
+
133
+ AI must complete the following in order before generating or modifying any backend code:
134
+
135
+ 1. Read this file (`backend-rules.md`)
136
+ 2. Read existing files in the target module's directory to confirm whether similar functionality already exists
137
+ 3. If modifying shared utils / middleware / service, search all callers
138
+ 4. If modifying API contracts, assess impact on frontend/clients
139
+
140
+ ---
141
+
142
+ ## 11. Tech Stack Lock-in
143
+
144
+ {{ tech_stack_rules }}
145
+
146
+ ---
147
+
148
+ ## 12. Containerization & Deployment
149
+
150
+ {{ deploy_rules }}
151
+
152
+ ## 13. Caching Strategy
153
+
154
+ {{ cache_rules }}
155
+
156
+ ---
157
+
158
+ ## Appendix A: Deny List (Quick Reference)
159
+
160
+ > This appendix is auto-generated by AI in Phase 4 by extracting all forbidden entries from each section.
161
+
162
+ {{ deny_list_summary }}
163
+
164
+ ## Appendix B: Recommended Libraries & Tools
165
+
166
+ > This appendix is auto-generated by AI in Phase 4 to recommend the supporting ecosystem based on the tech stack.
167
+
168
+ {{ recommended_libs }}
169
+
170
+ ---
171
+
172
+ **Version**: v1.0 — Generated on {{ generated_at }}
173
+ **Next review recommended**: before tech stack changes or infrastructure migrations
@@ -0,0 +1,373 @@
1
+ # Derivation Rules — Database Auto-Derivation Rule Mapping
2
+
3
+ > This file defines the mapping "Phase 2 answers → rule blocks auto-injected into database-rules.md". The AI reads this file in Phase 3 — **do not ask the user again**.
4
+
5
+ ---
6
+
7
+ ## Phase 2 Answer Direct-Fill Table
8
+
9
+ | Template Placeholder | Source | Example Fill |
10
+ |---------------------|--------|-------------|
11
+ | `{{ project_name }}` | Phase 0 auto-read | `my-project-db` |
12
+ | `{{ generated_at }}` | Phase 4, AI writes current date | `2026-05-24` |
13
+ | `{{ database }}` | Q1 answer | `PostgreSQL` |
14
+ | `{{ cache }}` | Q2 answer | `Redis` |
15
+ | `{{ pk_strategy }}` | Q3 answer | `UUID v7 / ULID / Auto-increment BIGINT + UUID mapping / Direct auto-increment` |
16
+ | `{{ soft_delete }}` | Q4 answer | `Using deleted_at` |
17
+ | `{{ normalization }}` | Q5 answer | `Strict 3NF` |
18
+ | `{{ migration_tool }}` | Q6 answer | `ORM built-in` |
19
+ | `{{ workload_type }}` | Q7 answer | `OLTP` |
20
+ | `{{ data_scale }}` | Q8 answer | `< 1M rows` |
21
+ | `{{ data_sensitivity }}` | Q9 answer | `Contains PII` |
22
+ | `{{ audit }}` | Q10 answer | `Audit tables needed / CDC needed / Both / None` |
23
+ | `{{ deployment }}` | Q11 answer | `RDS` |
24
+ | `{{ backup }}` | Q12 answer | `Daily full + continuous incremental` |
25
+ | `{{ ha }}` | Q13 answer | `Primary-replica replication` |
26
+ | `{{ ai_ddl_permission }}` | Q14 answer | `Migration only / Fully forbid / Free operation` |
27
+ | `{{ ai_safety_constraint }}` | Q15 answer | `Forbid destructive ops / No restriction but confirm` |
28
+
29
+ ---
30
+
31
+ ## Trigger Map
32
+
33
+ | Trigger (Phase 2 Answer) | Inject Rule Block ID | Inject Into Placeholder |
34
+ |--------------------------|---------------------|------------------------|
35
+ | Q1 = PostgreSQL | `D-PG-01` | `{{ tech_rules }}` |
36
+ | Q1 = MySQL | `D-MYSQL-01` | `{{ tech_rules }}` |
37
+ | Q1 = MongoDB | `D-MONGO-01` | `{{ tech_rules }}` |
38
+ | Q1 = SQLite | `D-SQLITE-01` | `{{ tech_rules }}` |
39
+ | Q2 = Redis | `D-REDIS-BACKEND-01` | `{{ cache_rules }}` |
40
+ | Q2 = Memcached | `D-MEMCACHED-DB-01` | `{{ cache_rules }}` |
41
+ | Q3 = UUID v7 | `D-UUID-01` | `{{ schema_rules }}` |
42
+ | Q3 = ULID | `D-ULID-01` | `{{ schema_rules }}` |
43
+ | Q3 = Auto-increment + UUID mapping | `D-AUTOINC-01` | `{{ schema_rules }}` |
44
+ | Q3 = Direct auto-increment | `D-DIRECT-AUTOINC-01` | `{{ schema_rules }}` |
45
+ | Q4 = deleted_at | `D-SOFTDELETE-01` | `{{ schema_rules }}` |
46
+ | Q5 = Strict 3NF | `D-3NF-01` | `{{ schema_rules }}` |
47
+ | Q5 = Allow partial denormalization | `D-PARTIAL-DENORM-01` | `{{ schema_rules }}` |
48
+ | Q6 = ORM built-in | `D-ORM-MIGRATE-01` | `{{ migration_rules }}` |
49
+ | Q6 = Standalone tool | `D-FLYWAY-01` | `{{ migration_rules }}` |
50
+ | Q6 = Manual SQL files | `D-MANUAL-MIGRATE-01` | `{{ migration_rules }}` |
51
+ | Q7 = OLTP | `D-OLTP-01` | `{{ performance_rules }}` |
52
+ | Q7 = OLAP | `D-OLAP-01` | `{{ performance_rules }}` |
53
+ | Q7 = Mixed | `D-MIXED-01` | `{{ performance_rules }}` |
54
+ | Q8 = > 10M rows | `D-PARTITION-01` | `{{ performance_rules }}` |
55
+ | Q8 = 1M-10M rows | `D-MEDIUM-SCALE-01` | `{{ performance_rules }}` |
56
+ | Q9 = Contains PII | `D-PII-01` | `{{ security_rules }}` |
57
+ | Q10 = Audit tables | `D-AUDIT-01` | `{{ audit_rules }}` |
58
+ | Q10 = CDC | `D-CDC-01` | `{{ audit_rules }}` |
59
+ | Q10 = Both audit tables + CDC | `D-AUDIT-01` + `D-CDC-01` | `{{ audit_rules }}` |
60
+ | Q11 = Cloud managed | `D-CLOUD-01` | `{{ ops_rules }}` |
61
+ | Q11 = Self-hosted | `D-SELFHOST-01` | `{{ ops_rules }}` |
62
+ | Q11 = Development environment Docker Compose | `D-DOCKER-DEV-01` | `{{ ops_rules }}` |
63
+ | Q12 = Daily full + continuous incremental | `D-PITR-01` | `{{ ops_rules }}` |
64
+ | Q12 = Daily full backup only | `D-FULL-BACKUP-01` | `{{ ops_rules }}` |
65
+ | Q12 = No automatic backup needed | `D-NO-BACKUP-01` | `{{ ops_rules }}` |
66
+ | Q13 = Primary-replica | `D-REPLICA-01` | `{{ ops_rules }}` |
67
+ | Q13 = Single instance is sufficient | `D-SINGLE-01` | `{{ ops_rules }}` |
68
+ | Q13 = Multi-master cluster | `D-MULTIMASTER-01` | `{{ ops_rules }}` |
69
+ | Q14 = Migration only | `D-AI-DDL-AUDIT-01` | `{{ ai_ddl_rule }}` |
70
+ | Q14 = Fully forbid | `D-AI-DDL-FORBID-01` | `{{ ai_ddl_rule }}` |
71
+ | Q14 = Free operation | `D-AI-DDL-FREE-01` | `{{ ai_ddl_rule }}` |
72
+ | Q15 = Forbid destructive | `D-AI-SAFETY-STRICT-01` | `{{ ai_safety_rule }}` |
73
+ | Q15 = No restriction but confirm | `D-AI-SAFETY-LOOSE-01` | `{{ ai_safety_rule }}` |
74
+
75
+ > **Multi-select note**: Q10 (Audit Requirements) supports multi-select. When user selects both A (Audit tables) and B (CDC), the trigger `Q10 = Both audit tables + CDC` fires, injecting both `D-AUDIT-01` and `D-CDC-01` into `{{ audit_rules }}`.
76
+
77
+ ---
78
+
79
+ ## Rule Block Definitions
80
+
81
+ ### D-PG-01
82
+ **Trigger**: Q1 = PostgreSQL | **Inject into**: `{{ tech_rules }}`
83
+
84
+ - Charset unified to `UTF8`. Collation use `en_US.UTF-8` or `C`.
85
+ - Use `TIMESTAMPTZ` for all timestamps. Do not use `TIMESTAMP`.
86
+ - JSON use `JSONB`, not `JSON`. Create GIN indexes for JSON field queries.
87
+ - Array types use `TEXT[]` / `INT[]`. Not comma-separated strings.
88
+ - Network addresses use `INET`. UUIDs use `UUID` type.
89
+ - Auto-increment primary keys use `BIGINT GENERATED ALWAYS AS IDENTITY`.
90
+
91
+ ### D-MYSQL-01
92
+ **Trigger**: Q1 = MySQL | **Inject into**: `{{ tech_rules }}`
93
+
94
+ - Charset unified to `utf8mb4`. Collation use `utf8mb4_unicode_ci`.
95
+ - Engine defaults to `InnoDB` (supports transactions, row locks, foreign keys).
96
+ - Timestamps use `DATETIME(3)` (millisecond precision). Don't use `TIMESTAMP` (2038 problem).
97
+ - JSON use `JSON` type (MySQL 8.0+). Don't store JSON as TEXT.
98
+ - Auto-increment primary keys use `BIGINT AUTO_INCREMENT`.
99
+
100
+ ### D-MONGO-01
101
+ **Trigger**: Q1 = MongoDB | **Inject into**: `{{ tech_rules }}`
102
+
103
+ - Document design prefers embedding over referencing (Embed over Reference), unless data needs independent querying.
104
+ - Every document must contain `_id` (auto-generated by MongoDB) and `createdAt`/`updatedAt`.
105
+ - Schema enforced via Mongoose Schema or JSON Schema Validation.
106
+ - Forbid full collection scan queries — every query must be index-covered.
107
+
108
+ ### D-SQLITE-01
109
+ **Trigger**: Q1 = SQLite | **Inject into**: `{{ tech_rules }}`
110
+
111
+ - SQLite column type notes: UUIDs stored as TEXT, no JSONB type (use TEXT with JSON functions).
112
+ - Enable WAL mode for concurrent reads. File-level write lock limits concurrent writes.
113
+ - Schedule periodic VACUUM for reclaiming space from deleted rows.
114
+ - Use `sqlite3` CLI or `.dump` for backup.
115
+
116
+ ### D-REDIS-BACKEND-01
117
+ **Trigger**: Q2 = Redis | **Inject into**: `{{ cache_rules }}`
118
+
119
+ - Key naming: `<service>:<resource>:<id>` (`user:session:abc123`).
120
+ - All keys must have TTL (`EXPIRE`). Forbid never-expiring keys.
121
+ - Batch operations use Pipeline or Lua scripts to avoid N network round trips.
122
+ - Forbid `KEYS *` in production. Use `SCAN` cursor traversal.
123
+
124
+ > **Note**: Key naming aligned with backend-rules D-REDIS-01 convention for cross-document consistency. Database-rules addresses cache-as-a-data-layer (key naming, TTL, batch operations); for cache update/invalidation patterns, refer to backend-rules.md.
125
+
126
+ ### D-MEMCACHED-DB-01
127
+ **Trigger**: Q2 = Memcached | **Inject into**: `{{ cache_rules }}`
128
+
129
+ - Memcached used as simple KV cache. Max value size 1MB. Key max 250 bytes.
130
+ - All keys must have TTL (EXPIRE). Default 300s. Forbid no-expiration keys.
131
+ - No persistence — data lost on restart. Only cache data that can be regenerated from the database.
132
+ - Client sharding across multiple memcached instances via consistent hashing.
133
+
134
+ ### D-UUID-01
135
+ **Trigger**: Q3 = UUID v7 | **Inject into**: `{{ schema_rules }}`
136
+
137
+ - Primary keys use UUID v7 (time-sortable, 128-bit, globally unique, dashed format).
138
+ - UUIDs use native database types (PostgreSQL `UUID`, MySQL `CHAR(36)`).
139
+ - API layer exposes UUID v7. Internal JOINs use UUID (modern database UUID JOIN performance is close to INT).
140
+
141
+ ### D-ULID-01
142
+ **Trigger**: Q3 = ULID | **Inject into**: `{{ schema_rules }}`
143
+
144
+ - Primary keys use ULID (26-character Crockford base32). URL-safe, lowercase, time-sortable.
145
+ - Database column type: CHAR(26). Forbid using ULID as VARCHAR (performance penalty).
146
+ - ULID generation: use application-side library (not database function).
147
+ - API layer exposes ULID directly.
148
+
149
+ ### D-AUTOINC-01
150
+ **Trigger**: Q3 = Auto-increment + UUID mapping | **Inject into**: `{{ schema_rules }}`
151
+
152
+ - Primary keys use `BIGINT AUTO_INCREMENT`. Do not expose to API.
153
+ - API layer uses UUID (ID mapping in service layer or an additional UUID column).
154
+ - Strictly forbid exposing auto-increment IDs in URLs or responses.
155
+
156
+ ### D-DIRECT-AUTOINC-01
157
+ **Trigger**: Q3 = Direct auto-increment | **Inject into**: `{{ schema_rules }}`
158
+
159
+ - Direct auto-increment IDs for internal use only.
160
+ - Forbid exposing auto-increment IDs in URLs, API responses, or any client-facing layer.
161
+ - Use UUIDs or opaque tokens for all external references.
162
+ - Auto-increment IDs must be BIGINT (never INT for production tables expected to grow).
163
+
164
+ ### D-SOFTDELETE-01
165
+ **Trigger**: Q4 = deleted_at | **Inject into**: `{{ schema_rules }}`
166
+
167
+ - Every table requiring soft delete adds `deleted_at TIMESTAMPTZ DEFAULT NULL`.
168
+ - All queries default to filtering `WHERE deleted_at IS NULL`.
169
+ - Unique indexes must include `deleted_at` (otherwise re-inserting the same unique key after deletion fails).
170
+ - Periodically archive soft-deleted data older than N days (N based on business agreement).
171
+
172
+ ### D-3NF-01
173
+ **Trigger**: Q5 = Strict 3NF | **Inject into**: `{{ schema_rules }}`
174
+
175
+ - All tables must satisfy 3NF: non-key columns depend directly on the primary key, not on other non-key columns.
176
+ - Denormalization must simultaneously satisfy: proven by load testing + documented reason in schema comments + documented consistency maintenance plan.
177
+
178
+ ### D-PARTIAL-DENORM-01
179
+ **Trigger**: Q5 = Allow partial denormalization | **Inject into**: `{{ schema_rules }}`
180
+
181
+ - Partial denormalization is permitted for OLAP, reporting, and performance-critical read paths.
182
+ - Each denormalized field must: (a) be documented in the schema comment with 'DENORM:' prefix and the source table/column, (b) have a defined consistency maintenance strategy (application-level update, materialized view, periodic reconciliation), (c) be listed in a project-level denormalization-registry.md file.
183
+ - Forbid denormalization on write-heavy OLTP paths.
184
+
185
+ ### D-ORM-MIGRATE-01
186
+ **Trigger**: Q6 = ORM built-in | **Inject into**: `{{ migration_rules }}`
187
+
188
+ - Migrations managed by ORM's built-in tool.
189
+ - Always generate via ORM CLI commands; never hand-edit auto-generated migration files.
190
+ - Version-control all migration files.
191
+ - Test migrations on a staging database before deployment.
192
+
193
+ ### D-FLYWAY-01
194
+ **Trigger**: Q6 = Standalone tool | **Inject into**: `{{ migration_rules }}`
195
+
196
+ - Use Flyway (Java/Go) or Alembic (Python) as a standalone migration tool.
197
+ - Migration file naming follows tool conventions. Each migration accompanied by a rollback file.
198
+ - CI validates: migration file numbers are non-duplicate, non-regressing, previously executed migrations are not modified.
199
+
200
+ ### D-MANUAL-MIGRATE-01
201
+ **Trigger**: Q6 = Manual SQL files | **Inject into**: `{{ migration_rules }}`
202
+
203
+ - Migration files follow naming convention: `V{YYYYMMDD}{HHmm}__{description}.sql` (forward) paired with `U{YYYYMMDD}{HHmm}__{description}.sql` (rollback).
204
+ - Each migration must have a matching rollback file.
205
+ - SQL review checklist: all statements idempotent where possible, no data loss in forward migration, rollback restores exact prior state.
206
+
207
+ ### D-OLTP-01
208
+ **Trigger**: Q7 = OLTP | **Inject into**: `{{ performance_rules }}`
209
+
210
+ - Slow query threshold set to 100ms.
211
+ - Every query must be index-covered (EXPLAIN output shows no full table scan / full index scan).
212
+ - Long transaction monitoring: transactions exceeding 5s trigger alerts.
213
+ - Connection pool config: `pool_size = CPU cores × 2`. Max wait time ≤ 30s.
214
+
215
+ ### D-OLAP-01
216
+ **Trigger**: Q7 = OLAP | **Inject into**: `{{ performance_rules }}`
217
+
218
+ - Slow query threshold relaxed to 500ms.
219
+ - Pre-aggregation tables / materialized views used for accelerating large queries.
220
+ - Batch ETL executed during low-traffic hours (2–6 AM).
221
+ - Forbid running DDL during OLAP query execution.
222
+
223
+ ### D-MIXED-01
224
+ **Trigger**: Q7 = Mixed | **Inject into**: `{{ performance_rules }}`
225
+
226
+ - Dual slow query thresholds: OLTP queries <= 100ms, OLAP queries <= 500ms.
227
+ - OLAP queries must use read replicas. Forbid running OLAP queries against the primary instance.
228
+ - Pre-aggregation via materialized views for common reporting queries. Refresh during low-traffic hours (2-6 AM).
229
+ - Forbid running DDL during OLAP query execution windows.
230
+
231
+ ### D-PARTITION-01
232
+ **Trigger**: Q8 = > 10M rows | **Inject into**: `{{ performance_rules }}`
233
+
234
+ - Large tables partitioned by time range (monthly or quarterly). Indexes per partition.
235
+ - New data written to the latest partition. Queries should include the partition key when possible.
236
+ - Expired partitions are auto-detached + archived without affecting online service.
237
+
238
+ ### D-MEDIUM-SCALE-01
239
+ **Trigger**: Q8 = 1M-10M rows | **Inject into**: `{{ performance_rules }}`
240
+
241
+ - Plan partitioning strategy now even if not immediately needed. Reserve partition key columns.
242
+ - Monitor table growth monthly. Trigger partition implementation at 5M rows.
243
+ - Index maintenance: monthly reindex for fragmented indexes. Monitor index hit rates.
244
+ - Archival strategy: identify cold data (> 90 days untouched) and plan archival path.
245
+
246
+ ### D-PII-01
247
+ **Trigger**: Q9 = Contains PII | **Inject into**: `{{ security_rules }}`
248
+
249
+ - Sensitive fields (password hashes, national IDs, bank card numbers, phone numbers, email) must be encrypted at rest.
250
+ - Passwords use bcrypt/argon2 hashing. Irreversible info uses AES-256-GCM encryption.
251
+ - Database logs / slow query logs are auto-desensitized.
252
+ - Database backup files must be encrypted at rest.
253
+ - GDPR "right to be forgotten": user data deletion must be true deletion (or irreversible anonymization), not soft delete.
254
+
255
+ ### D-AUDIT-01
256
+ **Trigger**: Q10 = Audit tables | **Inject into**: `{{ audit_rules }}`
257
+
258
+ - Every audited table gets a corresponding `<table>_audit` table recording all INSERT/UPDATE/DELETE.
259
+ - Audit table fields: `audit_id`, `operation` (I/U/D), `changed_by`, `changed_at`, `old_values`(JSONB), `new_values`(JSONB).
260
+ - Audit tables populated via triggers. Application code does not write directly to audit tables.
261
+ - Audit tables are partitioned and periodically archived.
262
+
263
+ ### D-CDC-01
264
+ **Trigger**: Q10 = CDC | **Inject into**: `{{ audit_rules }}`
265
+
266
+ - Use Debezium / Maxwell / PostgreSQL logical replication for CDC.
267
+ - CDC events pushed to Kafka/message queue. Downstream consumers handle (sync to ES, data warehouse, cache invalidation).
268
+ - CDC connectors must have dead letter queues configured. Failure must not obstruct primary database operation.
269
+
270
+ ### D-CLOUD-01
271
+ **Trigger**: Q11 = Cloud managed | **Inject into**: `{{ ops_rules }}`
272
+
273
+ - Automated backup enabled (default: retain 7+ days). Multi-AZ deployment.
274
+ - Security group: only whitelisted IPs can access the database port.
275
+ - Connections enforce SSL/TLS.
276
+ - Upgrade windows set during low-traffic periods.
277
+
278
+ ### D-SELFHOST-01
279
+ **Trigger**: Q11 = Self-hosted | **Inject into**: `{{ ops_rules }}`
280
+
281
+ - Database port not exposed to the public internet.
282
+ - Monitoring must be set up: connections, slow queries, disk usage, replication lag.
283
+ - Backup scripts run independently of application servers.
284
+ - Regular recovery drills (at least quarterly).
285
+
286
+ ### D-DOCKER-DEV-01
287
+ **Trigger**: Q11 = Development environment Docker Compose | **Inject into**: `{{ ops_rules }}`
288
+
289
+ - Docker Compose for local development only. Production deployment handled separately.
290
+ - Database data persisted via Docker volumes. Forbid losing data on container restart.
291
+ - docker-compose.yml committed to repository. Includes database service + cache service definitions.
292
+ - Health checks configured for all services. Startup order managed via depends_on + healthcheck conditions.
293
+
294
+ ### D-PITR-01
295
+ **Trigger**: Q12 = Daily full + continuous incremental | **Inject into**: `{{ ops_rules }}`
296
+
297
+ - PostgreSQL: enable WAL archiving + `pgBackRest` / `WAL-G`.
298
+ - MySQL: enable binlog + `XtraBackup` / `mysqlbackup`.
299
+ - PITR Recovery Time Objective (RTO) ≤ 1 hour. Recovery Point Objective (RPO) ≤ 5 minutes.
300
+ - Backups retained for 30 days, stored offsite.
301
+
302
+ ### D-FULL-BACKUP-01
303
+ **Trigger**: Q12 = Daily full backup only | **Inject into**: `{{ ops_rules }}`
304
+
305
+ - Daily full backup via pg_dump/mysqldump/mongodump.
306
+ - Backups retained for 7 days locally + 30 days offsite.
307
+ - Warning: without continuous incremental/WAL archiving, PITR is not available. RPO = up to 24 hours.
308
+ - Recovery drill: monthly restore test from latest backup.
309
+
310
+ ### D-NO-BACKUP-01
311
+ **Trigger**: Q12 = No automatic backup needed | **Inject into**: `{{ ops_rules }}`
312
+
313
+ - No automatic backup configured. Suitable for development environments only.
314
+ - Warning: production data without backups will be permanently lost on failure.
315
+ - Recommend configuring at minimum daily backups before any production deployment.
316
+
317
+ ### D-REPLICA-01
318
+ **Trigger**: Q13 = Primary-replica | **Inject into**: `{{ ops_rules }}`
319
+
320
+ - Read-write split: writes go to primary, reads go to replicas. Application code must explicitly distinguish read/write data sources.
321
+ - Replication lag monitoring: alert when exceeding 5s.
322
+ - Failover drills at least quarterly.
323
+ - Connection pool config: primary pool small (fewer writes), replica pool large (more reads).
324
+
325
+ ### D-SINGLE-01
326
+ **Trigger**: Q13 = Single instance is sufficient | **Inject into**: `{{ ops_rules }}`
327
+
328
+ - Single database instance. No replication or failover.
329
+ - Acceptable downtime window: defined by business (default: off-hours maintenance).
330
+ - Warning: single point of failure. Instance failure = full service outage until restored from backup.
331
+ - Connection pool sized for one instance. No read/write split needed.
332
+
333
+ ### D-MULTIMASTER-01
334
+ **Trigger**: Q13 = Multi-master cluster | **Inject into**: `{{ ops_rules }}`
335
+
336
+ - Multi-master replication. All nodes accept writes. Conflict resolution strategy must be explicitly chosen (last-write-wins / application-level merge / CRDT).
337
+ - Auto-increment IDs must use offset-step allocation to avoid collisions across masters.
338
+ - Application must handle replication lag (eventual consistency). Read-after-write may not see latest data.
339
+ - Connection pool: separate pool per master. Load-balanced writes across all masters.
340
+
341
+ ### D-AI-DDL-AUDIT-01
342
+ **Trigger**: Q14 = Migration only | **Inject into**: `{{ ai_ddl_rule }}`
343
+
344
+ - AI may generate migration files but must not execute them.
345
+ - Each AI-generated migration must include: forward SQL + rollback SQL + EXPLAIN output + lock table analysis.
346
+ - Migration files must be human-reviewed before execution.
347
+
348
+ ### D-AI-DDL-FORBID-01
349
+ **Trigger**: Q14 = Fully forbid | **Inject into**: `{{ ai_ddl_rule }}`
350
+
351
+ - AI must not generate any DDL statements.
352
+ - AI may only provide structural optimization suggestions (no concrete SQL generated).
353
+ - All database structure changes are fully human-managed.
354
+
355
+ ### D-AI-DDL-FREE-01
356
+ **Trigger**: Q14 = Free operation | **Inject into**: `{{ ai_ddl_rule }}`
357
+
358
+ - AI may freely generate and execute DDL in development environments.
359
+ - All DDL changes must still be version-controlled in migration files.
360
+ - Warning: free DDL operation is suitable for development only. Restrict before production deployment.
361
+
362
+ ### D-AI-SAFETY-STRICT-01
363
+ **Trigger**: Q15 = Forbid destructive | **Inject into**: `{{ ai_safety_rule }}`
364
+
365
+ - AI must not generate DROP TABLE, DROP COLUMN, TRUNCATE, or ALTER COLUMN TYPE statements.
366
+ - AI-proposed DDL must first assess: lock table duration? Impact on online service? Rollback plan?
367
+ - Any operation modifying existing structure must first pass human review.
368
+
369
+ ### D-AI-SAFETY-LOOSE-01
370
+ **Trigger**: Q15 = No restriction but confirm | **Inject into**: `{{ ai_safety_rule }}`
371
+
372
+ - AI may propose DDL changes (CREATE, ALTER, DROP) but must present the exact SQL and ask for explicit user confirmation before execution.
373
+ - No automatic DDL execution.