prizmkit 1.1.54 → 1.1.55

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 (26) 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 +114 -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-init/SKILL.md +47 -6
  24. package/bundled/skills/prizmkit-init/references/config-schema.md +7 -3
  25. package/bundled/skills/prizmkit-init/references/rules/layer-detection.md +41 -0
  26. package/package.json +1 -1
@@ -0,0 +1,211 @@
1
+ # Fixed Rules — Complete Database Fixed Rules
2
+
3
+ > This file is read by the `database-rules` skill in Phase 1 and injected directly into `database-rules.md`.
4
+ > These rules are industry consensus / best practices — **do not ask the user**.
5
+ > Every rule includes RATIONALE so the AI understands intent, not just constraints.
6
+
7
+ ---
8
+
9
+ ## F1. Schema Design
10
+
11
+ ### F1.1 Naming Conventions (Mandatory)
12
+
13
+ - **Table names**: snake_case plural (`users`, `order_items`), not camelCase. Junction tables use alphabetical concatenation (`user_roles`).
14
+ - **Column names**: snake_case (`created_at`, `user_id`), not camelCase.
15
+ - **Primary keys**: use `id` for single tables, or concatenated names for junction tables (`user_id`, `role_id`).
16
+ - **Foreign keys**: `<referenced_table>_id` (`user_id`, `order_id`).
17
+ - **Indexes**: prefix `idx_` + table + columns (`idx_users_email`).
18
+ - **Unique constraints**: prefix `uq_` + table + columns (`uq_users_email`).
19
+ - **Forbidden**: Pinyin names, reserved keywords as table/column names (`order`, `group`, `user`).
20
+ - **RATIONALE**: Consistent naming makes ORM mapping accurate, SQL readable, and AI code generation precise when guessing field names.
21
+
22
+ ### F1.2 Required Fields
23
+
24
+ - **Rule**: Every business table must have:
25
+ - `id` — primary key
26
+ - `created_at` — `NOT NULL DEFAULT NOW()`
27
+ - `updated_at` — `NOT NULL DEFAULT NOW()` with auto-update (or trigger)
28
+ - **Rule**: Tables requiring soft delete must add `deleted_at` (NULL = not deleted). Unique indexes must include `deleted_at`.
29
+ - **Forbidden**: Using `is_deleted` boolean instead of `deleted_at` — losing the deletion timestamp loses audit information.
30
+ - **RATIONALE**: Consistent timestamps are the foundation of all auditing, synchronization, and CDC.
31
+
32
+ ### F1.3 Primary Key Strategy
33
+
34
+ - **Rule**: Prefer UUID v4/v7 or ULID as the business primary key exposed to APIs.
35
+ - **Rule**: Primary key strategy is determined by Q3 (Primary Key Strategy). If UUID/ULID is chosen, UUIDs are used both internally and in the API layer. If auto-increment is chosen, BIGINT may be used internally, but the API layer must expose UUID (via an additional UUID column or ID mapping).
36
+ - **Forbidden**: Exposing auto-increment IDs directly to the frontend (enumerable, leaks data volume).
37
+ - **Forbidden**: Using business fields as primary keys (e.g., national ID, phone number) — business rules change.
38
+ - **RATIONALE**: UUIDs prevent enumeration, support distributed generation, and avoid merge conflicts. Exposing auto-increment IDs is information leakage.
39
+
40
+ ### F1.4 Normalization vs. Denormalization
41
+
42
+ - **Rule**: Default to 3NF (Third Normal Form) to reduce data redundancy.
43
+ - **Denormalization exception**: Only allowed when query performance is a proven bottleneck AND index optimization has been exhausted. Must be documented with rationale in schema comments.
44
+ - **Forbidden**: Denormalizing without load testing.
45
+ - **RATIONALE**: Denormalization is a double-edged sword — queries get faster but writes and consistency maintenance costs skyrocket.
46
+
47
+ ### F1.5 Enum Values
48
+
49
+ - **Rule**: Status columns must list all possible values in schema comments.
50
+ - **Rule**: Prefer database ENUM types (PostgreSQL use CHECK constraint + string) or enum tables.
51
+ - **Forbidden**: Using `status TINYINT` without comments — nobody knows what 2 means.
52
+ - **RATIONALE**: Enum values are the easiest thing to rot — every status addition requires a full code scan to confirm compatibility.
53
+
54
+ ---
55
+
56
+ ## F2. Column Types
57
+
58
+ - **Rule**: Monetary amounts always use `DECIMAL(19,4)` or `NUMERIC`. Forbid `FLOAT`/`DOUBLE`.
59
+ - **Rule**: Date/time use `TIMESTAMP WITH TIME ZONE` (PostgreSQL) / `DATETIME` (MySQL). Forbid string-stored dates.
60
+ - **Rule**: JSON data use `JSONB` (PostgreSQL) / `JSON` (MySQL 8+). Forbid storing TEXT and parsing in application layer.
61
+ - **Rule**: Character set unified to `UTF8MB4` (MySQL) / `UTF8` (PostgreSQL). Collation unified.
62
+ - **Rule**: IP addresses use `INET` (PostgreSQL) / `VARBINARY(16)` (MySQL), not VARCHAR.
63
+ - **Forbidden**: Using VARCHAR to store arrays (e.g., `"a,b,c"`) — use array types or junction tables.
64
+ - **RATIONALE**: The right type lets the database do validation and index optimization for you. Wrong types mean you're throwing away the database's self-protection.
65
+
66
+ ---
67
+
68
+ ## F3. Index Strategy
69
+
70
+ - **Rule**: Primary keys are auto-indexed. Foreign keys must be manually indexed.
71
+ - **Rule**: Columns involved in WHERE/JOIN/ORDER BY/DISTINCT must be evaluated for index need.
72
+ - **Rule**: Multi-column queries use composite indexes with the leftmost prefix rule — equality columns first, range columns last.
73
+ - **Rule**: Adding indexes to large tables must use `CONCURRENTLY` (PostgreSQL) / `ALGORITHM=INPLACE` (MySQL) to avoid table locks.
74
+ - **Rule**: Regularly analyze slow query logs and remove unused indexes.
75
+ - **Forbidden**: Indexing low-cardinality columns alone (e.g., `gender`, `status` with < 5 values).
76
+ - **Forbidden**: Redundant indexes — `idx(a,b)` already covers `idx(a)` scenarios.
77
+ - **RATIONALE**: Indexes are the core lever of database performance, but every additional index slows writes by a bit.
78
+
79
+ ---
80
+
81
+ ## F3b. Transaction Isolation
82
+
83
+ ### F3b.1 Transaction Isolation
84
+
85
+ - **Rule**: Explicitly set transaction isolation level for each transaction. Do not rely on database defaults.
86
+ - **Rule**: Default isolation for OLTP: READ COMMITTED (balances consistency and performance). For financial operations: REPEATABLE READ or SERIALIZABLE.
87
+ - **Rule**: Document the chosen isolation level per business operation in code comments.
88
+ - **Forbidden**: Using SERIALIZABLE for high-throughput read operations (causes unnecessary contention).
89
+ - **RATIONALE**: PostgreSQL defaults to READ COMMITTED, MySQL to REPEATABLE READ. Different defaults cause different behaviors in the same application code.
90
+
91
+ ---
92
+
93
+ ## F4. Migration Management
94
+
95
+ - **Rule**: All database structure changes must go through versioned migration files. Forbid executing SQL directly against production databases.
96
+ - **Rule**: Migration file naming: `V<number>__<description>.sql` (Flyway format) or `<timestamp>_<description>.sql` (custom format).
97
+ - **Rule**: Each migration file must include both `up` (forward) and corresponding `down` (rollback).
98
+ - **Rule**: Schema changes must avoid table locks (choose the correct method per database):
99
+ - MySQL: `ALGORITHM=INPLACE, LOCK=NONE` (when conditions allow)
100
+ - PostgreSQL: `ALTER TABLE ... ADD COLUMN` without DEFAULT (add column first, then backfill defaults).
101
+ - **Forbidden**: Dropping columns in migrations — mark as deprecated first, remove in the next version after confirming zero references.
102
+ - **Forbidden**: Changing column types — must follow the pattern: add new column → dual-write transition → migrate data → switch reads → drop old column.
103
+ - **RATIONALE**: Migrations are the most dangerous production operations. It's not just "does it run" — it's about online tables, rollback windows, and data consistency.
104
+
105
+ ---
106
+
107
+ ## F5. Query Standards
108
+
109
+ - **Rule**: All SQL must be parameterized. Forbid string concatenation with user input.
110
+ - **Rule**: SELECT must explicitly list column names. Forbid `SELECT *`.
111
+ - **Rule**: Queries must have LIMIT (unless the business explicitly requires full results and data volume is controllable).
112
+ - **Rule**: Bulk write operations (UPDATE/DELETE) must be batched (≤ 1000 rows per batch) with transaction intervals.
113
+ - **Rule**: Transactions must be as short as possible — no external API calls, message sends, or user input waits inside transactions.
114
+ - **Rule**: Complex queries must first run `EXPLAIN` / `EXPLAIN ANALYZE` to verify index usage.
115
+ - **Forbidden**: Concatenating dynamic SQL strings in application code (use whitelist for dynamic sort fields, query builder for dynamic conditions).
116
+ - **RATIONALE**: Query standards aren't about "writing prettier code" — every rule here corresponds to a real production incident.
117
+
118
+ ---
119
+
120
+ ## F6. Security & Permissions
121
+
122
+ - **Rule**: Application accounts get minimum privileges — separate read and write accounts. Read accounts only get SELECT.
123
+ - **Rule**: Forbid using root/superuser accounts for application connections.
124
+ - **Rule**: Connections must enforce TLS/SSL.
125
+ - **Rule**: Sensitive fields (passwords, tokens, national IDs, phone numbers) must be encrypted at rest.
126
+ - **Rule**: Database ports must not be exposed to the public internet. Internal/VPC whitelist access only.
127
+ - **RATIONALE**: The database is the attacker's ultimate target. Enough layers of defense is what keeps you safe.
128
+
129
+ ---
130
+
131
+ ## F7. Backup & Recovery
132
+
133
+ - **Rule**: Automated backup strategy — daily full + continuous incremental/archiving (WAL archiving / binlog).
134
+ - **Rule**: Backup files must be stored offsite and encrypted.
135
+ - **Rule**: Regular recovery drills are mandatory (at least quarterly) to verify backup usability.
136
+ - **Rule**: PITR (Point-in-Time Recovery) must be available — recovering only to the last full backup is not sufficient.
137
+ - **RATIONALE**: A database whose backups have never been verified is a database without backups.
138
+
139
+ ---
140
+
141
+ ## F8. Performance
142
+
143
+ - **Rule**: Connection pool limit ≤ 80% of database `max_connections`, leaving headroom for admin connections.
144
+ - **Rule**: Slow query threshold set to 100ms (for OLTP workloads). Alert on exceeding.
145
+ - **Rule**: Large tables (>10M rows) must plan a partitioning strategy (range partition by time or business key).
146
+ - **Rule**: Historical data must have an archival strategy that doesn't impact online query performance.
147
+ - **Forbidden**: Running DDL, bulk data migrations, or creating large indexes during peak hours.
148
+ - **RATIONALE**: Database performance issues are "boiling the frog" — unnoticeable at first, then suddenly crashing three times a day once data volume grows.
149
+
150
+ ---
151
+
152
+ ## F8b. Connection Pooling
153
+
154
+ ### F8b.1 Connection Pooling
155
+
156
+ - **Rule**: Every application service must use connection pooling. Forbid opening a new connection per request.
157
+ - **Rule**: Pool size = CPU cores x 2 per service instance (for OLTP). Max pool size <= 80% of database max_connections / number of service instances.
158
+ - **Rule**: Connection timeout: acquire <= 30s, idle <= 10min, max lifetime <= 1hour.
159
+ - **Rule**: Pool must have health check (validation query on borrow).
160
+ - **Forbidden**: Using hardcoded pool sizes without accounting for the number of service instances.
161
+ - **RATIONALE**: Connection pooling misconfiguration is the #1 cause of "database is up but application can't connect" incidents.
162
+
163
+ ---
164
+
165
+ ## F9. AI Vibecoding Baseline Constraints (project-agnostic, always active)
166
+
167
+ ### F9.1 Migration Files
168
+ - **Rule**: AI generating a new migration must also produce the corresponding rollback migration.
169
+ - **Forbidden**: Dropping columns, changing column types, or renaming columns in migrations (unless a complete transition plan exists).
170
+ - **Rule**: New migrations must pass `EXPLAIN` review before submission.
171
+
172
+ ### F9.2 SQL Safety
173
+ - **Rule**: All AI-written SQL in application code must be parameterized queries.
174
+ - **Forbidden**: AI generating string-concatenated SQL code.
175
+
176
+ ### F9.3 Search First
177
+ - **Rule**: Before writing SQL/migrations, AI must read existing migration files and schema.
178
+ - **Rule**: Before adding a new column, AI must confirm that a column with the same name doesn't already exist in that table.
179
+
180
+ ### F9.4 Context Honesty
181
+ - **Rule**: When uncertain about database version, field names, or constraint names, AI must explicitly say "I'm not sure." Forbid inventing.
182
+ - **Rule**: AI must understand the target database type before generating SQL (MySQL and PostgreSQL syntax differ).
183
+
184
+ ### F9.5 Irreversible Operations
185
+ - **Rule**: AI must not execute any DROP/TRUNCATE statements (unless the user explicitly provides both the target object and the reason).
186
+ - **Rule**: AI-proposed DDL must include a migration strategy assessment: online execution or maintenance window? How long is the table locked? What's the rollback plan?
187
+
188
+ ---
189
+
190
+ ## Injection Instructions (for the AI executing this skill)
191
+
192
+ Each chapter in this file corresponds to a `{{ FIXED_RULES_* }}` placeholder in the template:
193
+
194
+ | Chapter | Inject Into Placeholder | Template Section |
195
+ |---------|------------------------|-------------------|
196
+ | F1 Schema Design | `{{ FIXED_RULES_SCHEMA }}` | §1 Schema Design |
197
+ | F2 Column Types | `{{ FIXED_RULES_TYPES }}` | §2 Column Types |
198
+ | F3 Index Strategy | `{{ FIXED_RULES_INDEX }}` | §3 Index Strategy |
199
+ | F3b Transaction Isolation | `{{ FIXED_RULES_TRANSACTION }}` | §3b Transaction Isolation |
200
+ | F4 Migration Management | `{{ FIXED_RULES_MIGRATION }}` | §4 Migration Management |
201
+ | F5 Query Standards | `{{ FIXED_RULES_QUERY }}` | §5 Query Standards |
202
+ | F6 Security & Permissions | `{{ FIXED_RULES_SECURITY }}` | §6 Security & Permissions |
203
+ | F7 Backup & Recovery | `{{ FIXED_RULES_BACKUP }}` | §7 Backup & Recovery |
204
+ | F8 Performance | `{{ FIXED_RULES_PERFORMANCE }}` | §8 Performance |
205
+ | F8b Connection Pooling | `{{ FIXED_RULES_CONNECTION }}` | §8b Connection Pooling |
206
+ | F9 AI Constraints | `{{ FIXED_RULES_AI_BASE }}` | §9 AI Behavior Constraints |
207
+
208
+ **Rendering rules**:
209
+ 1. Copy each chapter's full body (including RATIONALE) directly into the corresponding placeholder.
210
+ 2. RATIONALE must be preserved — it lets AI understand intent rather than follow mechanically.
211
+ 3. Keep the original markdown list structure. Do not rewrite as prose paragraphs.
@@ -0,0 +1,184 @@
1
+ # Question Bank — Database Interactive Question Bank
2
+
3
+ > This file is read on demand by SKILL.md in Phase 2. The AI must strictly follow the group order defined in this file, asking **one group at a time (1–3 questions)**, never dumping all questions at once.
4
+ > For every question, show the user: question number, question text, options, **recommended choice (marked "Recommended")**, and a one-line description.
5
+ > After each user response, immediately record the choice to internal state `answers[Qx] = ...` and proceed to the next group.
6
+
7
+ ---
8
+
9
+ ## Asking Rules
10
+
11
+ 1. **Group order**: G1 → G2 → G3 → G4 → G5 → G6 → G7. Do not skip.
12
+ 2. **Shortcut commands** (respond immediately when user types these at any point):
13
+ - `recommended` / `default` → skip current group, adopt all recommended options
14
+ - `all recommended` / `one-click` → skip all remaining groups, adopt all recommended options
15
+ - `strict` / `strictest` → adopt the strictest option for the current group
16
+ - `skip` / `don't need this` → mark current group as N/A
17
+ - `custom: xxx` → record user's custom content
18
+ 3. **Abbreviation recognition**: `A` / `a` / `1` all mean option A.
19
+ 4. **Follow-up rule**: If the user gives an answer outside the options, first confirm whether to classify as an "other" branch.
20
+ 5. **Forbidden behaviors**:
21
+ - Must not make choices for the user before they explicitly answer.
22
+ - Must not fabricate user preferences to complete the answer set.
23
+ - Must not output more than 3 questions in a single message.
24
+
25
+ ---
26
+
27
+ ## Group Overview
28
+
29
+ | Group | Topic | Questions | Count |
30
+ |-------|-------|-----------|-------|
31
+ | G1 | Database Selection | Q1–Q2 | 2 |
32
+ | G2 | Data Modeling | Q3–Q5 | 3 |
33
+ | G3 | Migration | Q6 | 1 |
34
+ | G4 | Index & Performance | Q7–Q8 | 2 |
35
+ | G5 | Security & Compliance | Q9–Q10 | 2 |
36
+ | G6 | High Availability & Ops | Q11–Q13 | 3 |
37
+ | G7 | AI Constraints | Q14–Q15 | 2 |
38
+
39
+ Total: 15 questions.
40
+
41
+ ---
42
+
43
+ ## G1 — Database Selection
44
+
45
+ ### Q1. Primary Database
46
+ - **Options**:
47
+ - A) PostgreSQL **【Recommended: most feature-complete】**
48
+ - B) MySQL
49
+ - C) MongoDB
50
+ - D) SQLite (development/small projects)
51
+ - **Note**: Determines all subsequent column type, index syntax, and migration tool options.
52
+ - **Maps to**: `{{ database }}` + `{{ tech_rules }}`
53
+
54
+ ### Q2. Cache Layer Needed?
55
+ - **Options**:
56
+ - A) Redis **【Recommended: when caching is needed】**
57
+ - B) Memcached
58
+ - C) No cache layer needed
59
+ - **Note**: Determines cache key naming conventions, TTL requirements, and batch operation rules.
60
+ - **Maps to**: `{{ cache }}` + `{{ cache_rules }}`
61
+
62
+ ---
63
+
64
+ ## G2 — Data Modeling
65
+
66
+ ### Q3. Primary Key Strategy
67
+ - **Options**:
68
+ - A) UUID v7 (time-sortable, 128-bit with dashes) **【Recommended】**
69
+ - B) ULID (lowercase, URL-safe, 26-char, time-sortable)
70
+ - C) Auto-increment BIGINT + UUID mapping for external use
71
+ - D) Direct auto-increment IDs
72
+ - **Note**: Choosing D injects the rule "forbid exposing auto-increment IDs to the frontend."
73
+ - **Maps to**: `{{ pk_strategy }}` + `{{ schema_rules }}`
74
+
75
+ ### Q4. Soft Delete
76
+ - **Options**:
77
+ - A) Use `deleted_at` field **【Recommended】**
78
+ - B) No soft delete needed (data is irrecoverably deleted)
79
+ - **Note**: Determines whether audit fields and unique indexes with `deleted_at` rules are needed.
80
+ - **Maps to**: `{{ soft_delete }}` + `{{ schema_rules }}`
81
+
82
+ ### Q5. Normalization Level
83
+ - **Options**:
84
+ - A) Strict 3NF; denormalization requires comments explaining why **【Recommended】**
85
+ - B) Allow partial denormalization (OLAP/reporting scenarios)
86
+ - **Note**: Determines the threshold for data redundancy.
87
+ - **Maps to**: `{{ normalization }}` + `{{ schema_rules }}`
88
+
89
+ ---
90
+
91
+ ## G3 — Migration
92
+
93
+ ### Q6. Migration Tool
94
+ - **Options**:
95
+ - A) ORM's built-in migration tool **【Recommended: when consistent with ORM】**
96
+ - B) Flyway / golang-migrate / Alembic (standalone migration tool)
97
+ - C) Manually managed SQL files
98
+ - **Note**: Determines migration file format, naming conventions, and rollback requirements.
99
+ - **Maps to**: `{{ migration_tool }}` + `{{ migration_rules }}`
100
+
101
+ ---
102
+
103
+ ## G4 — Index & Performance
104
+
105
+ ### Q7. Query Complexity
106
+ - **Options**:
107
+ - A) OLTP (high-frequency small queries, ≤ 10ms each) **【Recommended: web apps】**
108
+ - B) OLAP (low-frequency large queries, ≥ 100ms each)
109
+ - C) Mixed (has reporting/analytics needs)
110
+ - **Note**: Determines slow query thresholds, index strategy strictness, and partitioning rules.
111
+ - **Maps to**: `{{ workload_type }}` + `{{ performance_rules }}`
112
+
113
+ ### Q8. Estimated Data Volume (per table)
114
+ - **Options**:
115
+ - A) < 1M rows (small scale, no partitioning needed) **【Recommended: early-stage projects】**
116
+ - B) 1M-10M rows (medium scale, recommend reserving partition expansion space)
117
+ - C) > 10M rows (large scale, partitioning strategy is mandatory)
118
+ - **Note**: Determines the urgency of partitioning and archival rules.
119
+ - **Maps to**: `{{ data_scale }}` + `{{ performance_rules }}`
120
+
121
+ ---
122
+
123
+ ## G5 — Security & Compliance
124
+
125
+ ### Q9. Data Sensitivity Level
126
+ - **Options**:
127
+ - A) Contains PII (Personally Identifiable Information), encryption at rest required **【Recommended: privacy-first, safest default】**
128
+ - B) Business data only, no special encryption needed
129
+ - **Note**: Choosing A auto-injects "encrypt sensitive fields", "log desensitization", and other strict rules.
130
+ - **Maps to**: `{{ data_sensitivity }}` + `{{ security_rules }}`
131
+
132
+ ### Q10. Audit Requirements
133
+ - **Options**:
134
+ - A) Need audit tables + operation logs **【Recommended: enterprise-grade projects】**
135
+ - B) Need CDC (Change Data Capture, for sync/analytics)
136
+ - C) Both audit tables + CDC (for comprehensive compliance + real-time sync)
137
+ - D) No audit needed
138
+ - **Note**: **Multi-select allowed** — audit tables (A) and CDC (B) serve different purposes and can be used together. Determines audit table structure and trigger rules.
139
+ - **Maps to**: `{{ audit }}` + `{{ audit_rules }}`
140
+
141
+ ---
142
+
143
+ ## G6 — High Availability & Operations
144
+
145
+ ### Q11. Deployment Method
146
+ - **Options**:
147
+ - A) Cloud managed service (RDS / Cloud SQL / Supabase) **【Recommended】**
148
+ - B) Self-hosted
149
+ - C) Development environment Docker Compose
150
+ - **Note**: Determines backup strategy and high availability rules.
151
+ - **Maps to**: `{{ deployment }}` + `{{ ops_rules }}`
152
+
153
+ ### Q12. Backup Strategy
154
+ - **Options**:
155
+ - A) Daily full + continuous incremental (PITR available) **【Recommended: production environments】**
156
+ - B) Daily full backup only
157
+ - C) No automatic backup needed (development environment)
158
+ - **Note**: Determines backup frequency, retention period, and recovery drill requirements.
159
+ - **Maps to**: `{{ backup }}` + `{{ ops_rules }}`
160
+
161
+ ### Q13. High Availability Requirements
162
+ - **Options**:
163
+ - A) Primary-replica replication / read-write split **【Recommended: production environments】**
164
+ - B) Single instance is sufficient
165
+ - C) Multi-master cluster
166
+ - **Note**: Determines connection pool configuration and failover strategy.
167
+ - **Maps to**: `{{ ha }}` + `{{ ops_rules }}`
168
+
169
+ ---
170
+
171
+ ## G7 — AI Constraints
172
+
173
+ ### Q14. AI Permission to Modify Database Structure
174
+ - **Options**:
175
+ - A) AI may only generate migration files; human reviews before execution **【Recommended】**
176
+ - B) AI may not generate any DDL (fully human-managed)
177
+ - C) AI may operate freely (development environment)
178
+ - **Maps to**: `{{ ai_ddl_rule }}`
179
+
180
+ ### Q15. AI Safety Constraints
181
+ - **Options**:
182
+ - A) AI must not execute DROP/TRUNCATE/drop column/change type **【Recommended】**
183
+ - B) No restriction, but explicit confirmation required
184
+ - **Maps to**: `{{ ai_safety_rule }}`
@@ -0,0 +1,158 @@
1
+ # Database Rules — {{ project_name }}
2
+
3
+ > This document was generated by the `database-rules` skill on {{ generated_at }}
4
+ > Audience: All project developers + DBAs + all AI coding assistants
5
+ >
6
+ > **Usage**:
7
+ > 1. All AI coding assistants must read this file before generating or modifying any database-related code
8
+ > 2. This document takes precedence over "general best practices" in AI training data
9
+ > 3. Operations conflicting with this document must not be executed
10
+
11
+ ---
12
+
13
+ ## 0. TL;DR — Key Decisions at a Glance
14
+
15
+ | Dimension | Decision |
16
+ |-----------|----------|
17
+ | Primary Database | {{ database }} |
18
+ | Cache Layer | {{ cache }} |
19
+ | Primary Key Strategy | {{ pk_strategy }} |
20
+ | Soft Delete | {{ soft_delete }} |
21
+ | Normalization Level | {{ normalization }} |
22
+ | Migration Tool | {{ migration_tool }} |
23
+ | Workload Type | {{ workload_type }} |
24
+ | Data Scale | {{ data_scale }} |
25
+ | Data Sensitivity | {{ data_sensitivity }} |
26
+ | Audit Requirements | {{ audit }} |
27
+ | Deployment Method | {{ deployment }} |
28
+ | Backup Strategy | {{ backup }} |
29
+ | High Availability | {{ ha }} |
30
+ | AI DDL Permission | {{ ai_ddl_permission }} |
31
+ | AI Safety Constraints | {{ ai_safety_constraint }} |
32
+
33
+ ---
34
+
35
+ ## 1. Schema Design
36
+
37
+ {{ FIXED_RULES_SCHEMA }}
38
+
39
+ {{ schema_rules }}
40
+
41
+ ---
42
+
43
+ ## 2. Column Types
44
+
45
+ {{ FIXED_RULES_TYPES }}
46
+
47
+ {{ tech_rules }}
48
+
49
+ ---
50
+
51
+ ## 3. Index Strategy
52
+
53
+ {{ FIXED_RULES_INDEX }}
54
+
55
+ ---
56
+
57
+ ## 3b. Transaction Isolation
58
+
59
+ {{ FIXED_RULES_TRANSACTION }}
60
+
61
+ ---
62
+
63
+ ## 4. Migration Management
64
+
65
+ {{ FIXED_RULES_MIGRATION }}
66
+
67
+ {{ migration_rules }}
68
+
69
+ ---
70
+
71
+ ## 5. Query Standards
72
+
73
+ {{ FIXED_RULES_QUERY }}
74
+
75
+ > **Note**: For data access method rules (ORM/Query Builder/Raw SQL organization), refer to `backend-rules.md` §5 (Database). This document covers SQL-level query standards only.
76
+
77
+ ---
78
+
79
+ ## 6. Security & Permissions
80
+
81
+ {{ FIXED_RULES_SECURITY }}
82
+
83
+ {{ security_rules }}
84
+
85
+ ---
86
+
87
+ ## 7. Backup & Recovery
88
+
89
+ {{ FIXED_RULES_BACKUP }}
90
+
91
+ {{ ops_rules }}
92
+
93
+ ---
94
+
95
+ ## 8. Performance
96
+
97
+ {{ FIXED_RULES_PERFORMANCE }}
98
+
99
+ {{ performance_rules }}
100
+
101
+ ---
102
+
103
+ ## 8b. Connection Pooling
104
+
105
+ {{ FIXED_RULES_CONNECTION }}
106
+
107
+ ---
108
+
109
+ ## 9. AI Vibecoding Behavior Constraints
110
+
111
+ ### 9.1 Baseline Constraints (project-agnostic, always active)
112
+
113
+ {{ FIXED_RULES_AI_BASE }}
114
+
115
+ ### 9.2 Project-Specific Hard Constraints
116
+
117
+ - **Database structure change permission**: {{ ai_ddl_rule }}
118
+ - **Safety operation constraints**: {{ ai_safety_rule }}
119
+
120
+ ### 9.3 Mandatory Pre-Actions (before generating any SQL/Migration)
121
+
122
+ AI must complete the following in order before performing any database-related operation:
123
+
124
+ 1. Read this file (`database-rules.md`)
125
+ 2. Read existing schema or migration files to confirm table structure
126
+ 3. Confirm the target database type and version
127
+ 4. If involving indexes/DDL, first assess EXPLAIN and estimated execution time
128
+
129
+ ---
130
+
131
+ ## 10. Audit & Compliance
132
+
133
+ {{ audit_rules }}
134
+
135
+ ---
136
+
137
+ ## 11. Caching
138
+
139
+ {{ cache_rules }}
140
+
141
+ ---
142
+
143
+ ## Appendix A: Deny List (Quick Reference)
144
+
145
+ > This appendix is auto-generated by AI in Phase 4 by extracting all forbidden entries from each section.
146
+
147
+ {{ deny_list_summary }}
148
+
149
+ ## Appendix B: Recommended Tools
150
+
151
+ > This appendix is auto-generated by AI in Phase 4 to recommend supporting tools based on database selection.
152
+
153
+ {{ recommended_libs }}
154
+
155
+ ---
156
+
157
+ **Version**: v1.0 — Generated on {{ generated_at }}
158
+ **Next review recommended**: before database upgrades or architecture changes