agents-templated 2.2.19 → 2.2.21

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 (56) hide show
  1. package/package.json +1 -1
  2. package/templates/CLAUDE.md +17 -17
  3. package/templates/agents/commands/README.md +144 -0
  4. package/templates/agents/commands/SCHEMA.md +42 -0
  5. package/templates/agents/commands/arch-check.md +58 -0
  6. package/templates/agents/commands/audit.md +58 -0
  7. package/templates/agents/commands/debug-track.md +58 -0
  8. package/templates/agents/commands/docs.md +58 -0
  9. package/templates/agents/commands/fix.md +58 -0
  10. package/templates/agents/commands/learn-loop.md +58 -0
  11. package/templates/agents/commands/perf.md +58 -0
  12. package/templates/agents/commands/plan.md +58 -0
  13. package/templates/agents/commands/pr.md +58 -0
  14. package/templates/agents/commands/problem-map.md +58 -0
  15. package/templates/agents/commands/release-ready.md +58 -0
  16. package/templates/agents/commands/release.md +58 -0
  17. package/templates/agents/commands/risk-review.md +58 -0
  18. package/templates/agents/commands/scope-shape.md +58 -0
  19. package/templates/agents/commands/task.md +58 -0
  20. package/templates/agents/commands/test-data.md +56 -0
  21. package/templates/agents/commands/test.md +58 -0
  22. package/templates/agents/commands/ux-bar.md +58 -0
  23. package/templates/agents/rules/ai-integration.md +54 -0
  24. package/templates/agents/rules/core.md +173 -0
  25. package/templates/agents/rules/database.md +305 -0
  26. package/templates/agents/rules/frontend.md +217 -0
  27. package/templates/agents/rules/guardrails.md +97 -0
  28. package/templates/agents/rules/hardening.md +52 -0
  29. package/templates/agents/rules/intent-routing.md +54 -0
  30. package/templates/agents/rules/lessons-learned.md +44 -0
  31. package/templates/agents/rules/planning.md +69 -0
  32. package/templates/agents/rules/security.md +278 -0
  33. package/templates/agents/rules/style.md +344 -0
  34. package/templates/agents/rules/system-workflow.md +63 -0
  35. package/templates/agents/rules/testing.md +371 -0
  36. package/templates/agents/rules/workflows.md +56 -0
  37. package/templates/agents/skills/README.md +198 -0
  38. package/templates/agents/skills/api-design/SKILL.md +59 -0
  39. package/templates/agents/skills/app-hardening/SKILL.md +45 -0
  40. package/templates/agents/skills/bug-triage/SKILL.md +36 -0
  41. package/templates/agents/skills/debug-skill/SKILL.md +39 -0
  42. package/templates/agents/skills/emilkowalski-skill/SKILL.md +51 -0
  43. package/templates/agents/skills/error-patterns/SKILL.md +70 -0
  44. package/templates/agents/skills/feature-delivery/SKILL.md +38 -0
  45. package/templates/agents/skills/feature-forge/SKILL.md +39 -0
  46. package/templates/agents/skills/find-skills/SKILL.md +133 -0
  47. package/templates/agents/skills/llm-integration/SKILL.md +64 -0
  48. package/templates/agents/skills/raphaelsalaja-userinterface-wiki/SKILL.md +51 -0
  49. package/templates/agents/skills/secure-code-guardian/SKILL.md +39 -0
  50. package/templates/agents/skills/shadcn-ui/SKILL.md +1932 -0
  51. package/templates/agents/skills/shadcn-ui/references/chart.md +306 -0
  52. package/templates/agents/skills/shadcn-ui/references/learn.md +145 -0
  53. package/templates/agents/skills/shadcn-ui/references/official-ui-reference.md +1729 -0
  54. package/templates/agents/skills/shadcn-ui/references/reference.md +586 -0
  55. package/templates/agents/skills/shadcn-ui/references/ui-reference.md +1578 -0
  56. package/templates/agents/skills/ui-ux-pro-max/SKILL.md +386 -0
@@ -0,0 +1,54 @@
1
+ ---
2
+ title: "AI / LLM Integration"
3
+ description: "Apply when integrating LLMs, RAG pipelines, prompt engineering, or building AI-powered features. Covers safety, cost, and quality"
4
+ version: "3.0.0"
5
+ tags: ["ai", "llm", "openai", "anthropic", "rag", "prompt-engineering", "safety"]
6
+ alwaysApply: false
7
+ globs: ["**/*llm*", "**/*openai*", "**/*anthropic*", "**/*langchain*", "**/*rag*", "**/ai/**"]
8
+ ---
9
+
10
+ ## Purpose
11
+
12
+ Govern LLM integrations safely: prevent prompt injection, enforce cost boundaries, define fallback behavior, and ensure model outputs are validated before use in any user-facing or downstream context.
13
+
14
+ ## Security Requirements
15
+
16
+ 1. **Prompt injection prevention** — Never interpolate raw user input directly into system prompts. Delimit user content explicitly (e.g., `<user_input>…</user_input>` tags or equivalent structural separation).
17
+ 2. **Output validation** — Treat all LLM outputs as untrusted data. Validate schema, sanitize before rendering in UI, and never execute LLM-generated code without a human or automated review gate.
18
+ 3. **Secret isolation** — API keys must live in environment variables only. Never log full request/response payloads that may contain sensitive user data.
19
+ 4. **Rate limiting** — Apply per-user and global rate limits on all LLM-backed endpoints to prevent abuse and runaway costs.
20
+
21
+ ## Cost Controls
22
+
23
+ - Set explicit `max_tokens` on every API call — never rely on model defaults.
24
+ - Log token usage per request; alert on anomalies (> 2× rolling baseline).
25
+ - Prefer streaming for long generations to enable early cancellation.
26
+ - Use smaller/cheaper models for classification, routing, or validation tasks; reserve large models for generation.
27
+
28
+ ## Model Selection
29
+
30
+ | Task | Preferred approach |
31
+ |------|--------------------|
32
+ | Classification / intent detection | Small fast model or fine-tuned classifier |
33
+ | Retrieval-augmented generation | Embed → retrieve → generate pipeline |
34
+ | Code generation | Model with strong code benchmarks; always review output |
35
+ | Summarization | Mid-tier model with explicit length constraints |
36
+ | Production generation | Model with provider SLA; never experimental endpoints in prod |
37
+
38
+ ## Fallback & Reliability
39
+
40
+ - Every LLM call must have a timeout and retry with exponential backoff (max 3 retries).
41
+ - Define a graceful degradation path for every LLM-powered feature (static response, cached answer, or user-facing degradation message).
42
+ - Do not block critical user flows on LLM availability.
43
+
44
+ ## RAG Pipeline Rules
45
+
46
+ - Chunk documents at semantic boundaries (paragraph, section), not arbitrary byte offsets.
47
+ - Score retrieved chunks; discard chunks below relevance threshold before injecting into prompt.
48
+ - Cite sources in output when content is retrieved — never present retrieved facts as model-generated knowledge.
49
+
50
+ ## Evaluation Requirements
51
+
52
+ - New LLM features must include an evaluation suite before production: minimum 20 representative examples with expected outputs.
53
+ - Track: accuracy, latency (p50/p95), token cost per request, failure rate.
54
+ - Accuracy regressions > 5% block promotion to production.
@@ -0,0 +1,173 @@
1
+ ---
2
+ title: "Core Project Guidelines"
3
+ description: "Apply to all architecture, type safety, code organization, and enterprise quality standards. Foundation for every feature"
4
+ alwaysApply: true
5
+ version: "3.0.0"
6
+ tags: ["architecture", "core", "enterprise", "technology-agnostic"]
7
+ globs:
8
+ - "*"
9
+ ---
10
+
11
+ ## Developer Identity
12
+
13
+ - The AI assistant should provide clear, step-by-step solutions
14
+ - Focus on security-first thinking in all recommendations
15
+ - Provide concise but comprehensive instructions
16
+ - Adapt all patterns to the chosen technology stack
17
+
18
+ ## Architecture Principles
19
+
20
+ ### Security-First Development
21
+ - **Validate all inputs** at application boundaries with appropriate validation libraries
22
+ - **Authenticate and authorize** every protected endpoint with secure session management
23
+ - **Rate limit** public endpoints to prevent abuse and DoS attacks
24
+ - **Sanitize outputs** to prevent injection attacks and data leaks
25
+ - **Use encryption** for sensitive data in transit and at rest
26
+ - **Log security events** appropriately without exposing sensitive information
27
+
28
+ ### Performance-Focused
29
+ - **Optimize asset delivery** with compression, caching, and lazy loading
30
+ - **Monitor performance metrics** specific to your platform (Web Vitals, response times, etc.)
31
+ - **Implement appropriate caching strategies** for your data freshness requirements
32
+ - **Optimize critical paths** - database queries, API responses, asset loading
33
+ - **Profile and benchmark** before and after optimization changes
34
+
35
+ ### Type Safety & Validation
36
+ - **Use strong typing systems** available in your chosen language
37
+ - **Implement runtime validation** for all external/user-provided data
38
+ - **Validate at boundaries** - API endpoints, form submissions, configuration
39
+ - **Document type contracts** between system components
40
+ - **Generate types** from schemas when possible (OpenAPI, GraphQL, database schemas)
41
+
42
+ ### Testing Strategy
43
+ - **Unit tests** for business logic and utility functions (80% of test effort)
44
+ - **Integration tests** for API endpoints and data access layers (15% of test effort)
45
+ - **E2E tests** for critical user journeys and workflows (5% of test effort)
46
+ - **Accessibility tests** for all user-facing interfaces
47
+ - **Performance tests** for critical paths and known bottlenecks
48
+ - **Security tests** for authentication, authorization, and validation flows
49
+
50
+ ## Code Quality Standards
51
+
52
+ ### Architecture & Organization
53
+ - **Feature-based structure** - organize code by business domain, not just technical layer
54
+ - **Separation of concerns** - keep UI, business logic, and data access separate
55
+ - **DRY principle** - don't repeat yourself, extract common patterns
56
+ - **SOLID principles** - single responsibility, open/closed, Liskov substitution, interface segregation, dependency inversion
57
+ - **Consistent naming** conventions throughout the codebase
58
+
59
+ ### Code Style
60
+ - **Consistent formatting** with automated tools (prettier, black, gofmt, rustfmt, etc.)
61
+ - **Linting rules** enforced via pre-commit hooks or CI/CD
62
+ - **Clear comments** for complex logic, architectural decisions, and gotchas
63
+ - **Self-documenting code** with meaningful variable and function names
64
+ - **No magic numbers** - extract constants with descriptive names
65
+
66
+ ### Component/Module Standards (Framework-Specific)
67
+ - **Single responsibility** - each component/module should have one clear purpose
68
+ - **Reusable units** - build components/modules that can be used in multiple places
69
+ - **Proper error handling** for production resilience
70
+ - **Accessibility attributes** included for user-facing components
71
+ - **Proper documentation** of public APIs and interfaces
72
+
73
+ ### Database Standards
74
+ - **Choose ONE approach** and maintain consistency (SQL with ORM, NoSQL, managed service, etc.)
75
+ - **Schema migrations only** for schema changes (never manual database edits in production)
76
+ - **ORM/ODM patterns** to prevent injection attacks (no raw SQL unless performance-critical)
77
+ - **Connection pooling** for all production deployments
78
+ - **Audit logs** for sensitive data operations
79
+ - **Proper indexing** to prevent N+1 query problems
80
+
81
+ ## Development Workflow
82
+
83
+ ### Quality Gates
84
+ - **Automated formatting** checks before code submission
85
+ - **Type checking** must pass (strict mode where available)
86
+ - **Linting** must pass with zero critical violations
87
+ - **Unit tests** must pass with adequate coverage (>80% for business logic)
88
+ - **Integration tests** must pass for API and data layer changes
89
+ - **Security scans** must pass without high-severity issues
90
+ - **Code review** approval required before merging
91
+
92
+ ### Environment Management
93
+ - **Environment variables** with runtime validation at startup
94
+ - **Secrets management** never in code, version control, or logs
95
+ - **Database migrations** applied consistently across environments
96
+ - **Feature flags** for gradual rollouts and A/B testing
97
+ - **Health checks** for deployment validation and monitoring
98
+
99
+ ### Performance Standards
100
+ - **Monitor resource usage** - memory, CPU, disk, network
101
+ - **Track performance metrics** specific to your platform
102
+ - **Profile critical paths** regularly to identify bottlenecks
103
+ - **Implement caching** appropriately for your use case
104
+ - **Alert on regressions** when performance degrades
105
+
106
+ ## Technology Stack Selection
107
+
108
+ This template is technology-agnostic. Choose your stack based on:
109
+ - **Team expertise** and preferred languages/frameworks
110
+ - **Project requirements** - performance needs, scalability, real-time features
111
+ - **Deployment environment** - cloud platform, container requirements, resources
112
+ - **Time constraints** - rapid prototyping vs. long-term maintenance
113
+
114
+ ### Frontend Tiers
115
+ - **Full-stack frameworks**: Next.js, Nuxt, SvelteKit, Remix
116
+ - **Component libraries**: React, Vue, Angular, Svelte, Solid
117
+ - **Traditional**: Server-side rendering with templates (Django, Rails, Laravel)
118
+ - **Mobile-first**: React Native, Flutter, Kotlin, Swift
119
+
120
+ ### Backend Tiers
121
+ - **Node.js**: Express, Fastify, NestJS, Koa
122
+ - **Python**: Django, FastAPI, Flask
123
+ - **Go**: Gin, Echo, Fiber
124
+ - **Rust**: Actix-web, Axum, Rocket
125
+ - **Java**: Spring Boot, Quarkus, Ktor
126
+ - **Other**: Ruby on Rails, C#/.NET, PHP, etc.
127
+
128
+ ### Database Tiers
129
+ - **SQL**: PostgreSQL, MySQL, SQLite, SQL Server
130
+ - **NoSQL**: MongoDB, DynamoDB, CouchDB, Firestore
131
+ - **Cloud-native**: Supabase, Firebase, AWS RDS, Azure SQL
132
+ - **Search**: Elasticsearch, Meilisearch, Algolia
133
+
134
+ ### Authentication
135
+ - **Self-managed**: Custom implementation with JWT, sessions, or cookies
136
+ - **Framework-integrated**: NextAuth, Passport, Django's auth system
137
+ - **SaaS**: Auth0, Firebase Auth, AWS Cognito, Supabase Auth
138
+
139
+ ## Maintenance & Evolution
140
+
141
+ ### Regular Reviews
142
+ - **Dependency updates** - keep packages current with security patches
143
+ - **Security audits** - regular vulnerability scanning and code review
144
+ - **Performance monitoring** - track metrics and address regressions
145
+ - **Code quality** - refactoring and technical debt management
146
+ - **Documentation** - keep docs current with code changes
147
+
148
+ ### Technology Updates
149
+ - **Framework versions** - planned upgrades with migration strategies
150
+ - **Critical patches** - immediate application of security updates
151
+ - **Feature adoption** - stay current with language/framework improvements
152
+ - **Deprecation management** - handle deprecated APIs and patterns
153
+
154
+ ## Documentation and Research
155
+
156
+ When deciding what to recommend or implement:
157
+
158
+ - **Local rules** (this file and other `agents/rules/*.mdc`): Use as the primary source for architecture, security, testing, and style. Follow these when the stack is generic or already covered.
159
+ - **Context7 MCP**: Use for **up-to-date library and framework documentation**. When suggesting or implementing patterns for a specific stack (e.g. Next.js, Express, React), query Context7 (`resolve-library-id` then `query-docs`) so recommendations match current APIs and official guidance.
160
+ - **NotebookLM MCP**: Use for **research and best-practice discourse** (e.g. OWASP, building-systems advice, template design). Query when adding or changing guidelines, or when the audit/planning needs external best practices. Not for real-time API docs—use Context7 for that.
161
+
162
+ ## Communication & Collaboration
163
+
164
+ - When providing solutions, be explicit about what to change
165
+ - Show code examples in the language/framework being used
166
+ - Focus on actionable steps, minimize unnecessary explanation
167
+ - Explain security implications of code changes
168
+ - Flag performance implications of design decisions
169
+
170
+ ---
171
+
172
+ Remember: This template adapts to **any modern technology stack** while maintaining **enterprise-grade quality standards**.
173
+ Choose your technologies wisely, apply these principles consistently, and keep your codebase maintainable.
@@ -0,0 +1,305 @@
1
+ ---
2
+ title: "Database and Data Layer Guidelines"
3
+ description: "Apply when designing schema, building data access layers, optimizing queries, or managing database operations"
4
+ alwaysApply: true
5
+ version: "3.0.0"
6
+ tags: ["database", "backend", "data", "orm", "schema"]
7
+ globs:
8
+ - "src/models/**/*"
9
+ - "src/data/**/*"
10
+ ---
11
+
12
+ # Database and Data Layer Guidelines
13
+
14
+ Technology-agnostic patterns for secure, maintainable data access.
15
+
16
+ ## Core Principles
17
+
18
+ ### Design First
19
+ - **Schema design** - Think through relationships and constraints
20
+ - **Normalization** - Minimize data duplication and anomalies
21
+ - **Scalability** - Design for growth and performance
22
+ - **Consistency** - ACID transactions when needed (SQL) or eventual consistency patterns (NoSQL)
23
+ - **Security** - Access controls at database and application level
24
+
25
+ ### Access Patterns
26
+ - **ORM/ODM only** - Use abstraction layer, never raw SQL/queries
27
+ - **Parameterized queries** - Prevent injection attacks
28
+ - **Query optimization** - Avoid N+1 problems and slow queries
29
+ - **Connection pooling** - Manage resources efficiently
30
+ - **Error handling** - Graceful degradation when database unavailable
31
+
32
+ ### Migration Strategy
33
+ - **Version control** - All schema changes tracked
34
+ - **Idempotent migrations** - Can run multiple times safely
35
+ - **Reversible migrations** - Can rollback if needed
36
+ - **Testing** - Test migrations in all environments
37
+ - **Documentation** - Document significant schema decisions
38
+
39
+ ## Database Strategy Options
40
+
41
+ ### SQL Databases (PostgreSQL, MySQL, SQLite, SQL Server)
42
+
43
+ Characteristics:
44
+ - Structured schema with defined tables and relationships
45
+ - ACID transactions for data consistency
46
+ - Powerful querying with SQL
47
+ - Good for relational data
48
+ - Mature tooling and libraries
49
+
50
+ Tools:
51
+ - ORM: Sequelize (Node.js), SQLAlchemy (Python), Hibernate (Java), Entity Framework (.NET)
52
+ - Query Builder: Knex.js (Node.js), SqlAlchemy Core (Python), QueryDSL (Java)
53
+ - Migration tools: Prisma Migrate, Flyway, Liquibase, Alembic
54
+
55
+ Best for:
56
+ - Complex relationships between entities
57
+ - Strong consistency requirements
58
+ - Transactional integrity
59
+ - Complex queries
60
+ - Team comfortable with SQL
61
+
62
+ ### NoSQL Databases (MongoDB, DynamoDB, CouchDB, Firestore)
63
+
64
+ Characteristics:
65
+ - Flexible/schemaless documents
66
+ - Eventual consistency
67
+ - Good horizontal scaling
68
+ - Fast for simple lookups
69
+ - Dev-friendly for rapid iteration
70
+
71
+ Tools:
72
+ - ODM: Mongoose (MongoDB), AWS SDK (DynamoDB), Firebase SDK (Firestore)
73
+ - Schema validation: JSONSchema, Zod, Joi
74
+
75
+ Best for:
76
+ - Flexible/evolving data structures
77
+ - Horizontal scaling
78
+ - Fast document lookups
79
+ - Real-time updates
80
+ - Prototyping and MVPs
81
+
82
+ ### Managed Database Services (Supabase, Firebase, AWS RDS)
83
+
84
+ Characteristics:
85
+ - Hosted by cloud provider
86
+ - Automatic backups and scaling
87
+ - Built-in authentication
88
+ - Real-time subscriptions (some)
89
+ - Reduced infrastructure complexity
90
+
91
+ Best for:
92
+ - Rapid prototyping
93
+ - Teams without DevOps expertise
94
+ - Projects needing built-in features
95
+ - Compliance-heavy requirements
96
+ - Teams preferring managed services
97
+
98
+ ## Schema Design Patterns
99
+
100
+ ### Core Tables/Collections
101
+
102
+ Base entities:
103
+ - **Users**: Authentication and identity data
104
+ - **Roles**: Permission groups
105
+ - **Audit logs**: Track changes for compliance
106
+
107
+ Related data:
108
+ - Define relationships clearly
109
+ - Use appropriate constraints (foreign keys, unique constraints)
110
+ - Add indexes for common queries
111
+ - Document connection between tables
112
+
113
+ ### Timestamps
114
+
115
+ Include timestamps:
116
+ - **Created at**: When record created (immutable)
117
+ - **Updated at**: When record last modified
118
+ - **Deleted at**: For soft deletes (when applicable)
119
+
120
+ ### IDs and Keys
121
+
122
+ ID strategy:
123
+ - **Primary key**: Uniquely identifies record
124
+ - **Foreign key**: References another table (relational)
125
+ - **Unique constraints**: Prevent duplicates
126
+ - **Non-sequential IDs**: Use UUID or similar for security
127
+
128
+ ### Data Validation
129
+
130
+ At database level:
131
+ - Required fields (NOT NULL)
132
+ - Data type constraints
133
+ - Length constraints (for strings)
134
+ - Enum constraints (for limited values)
135
+ - Range constraints (for numbers)
136
+
137
+ At application level:
138
+ - Validate before insert/update
139
+ - Validate format (email, URL, etc.)
140
+ - Validate business rules
141
+ - Return clear error messages
142
+
143
+ ## Query Patterns
144
+
145
+ ### Efficient Queries
146
+
147
+ Do:
148
+ - Use WHERE clauses to filter
149
+ - Use indexes on filtered fields
150
+ - Use SELECT specific columns
151
+ - Use LIMIT for pagination
152
+ - Use JOIN for related data
153
+ - Use aggregation functions
154
+ - Batch operations when possible
155
+
156
+ Don't:
157
+ - SELECT * (select all columns)
158
+ - N+1 queries (query in loop)
159
+ - Unindexed large scans
160
+ - Complex JOINs without indexes
161
+ - Missing WHERE clause
162
+ - Fetching unused data
163
+
164
+ ### Pagination
165
+
166
+ Pagination pattern:
167
+ 1. Accept limit and offset parameters
168
+ 2. Validate reasonable limit (max 100-1000)
169
+ 3. Query with LIMIT and OFFSET
170
+ 4. Return total count optionally
171
+ 5. Include nextPage/previousPage links
172
+
173
+ ### Relationships
174
+
175
+ Query related data:
176
+ - One-to-many: JOIN or separate queries
177
+ - Many-to-many: Junction table with JOINs
178
+ - One-to-one: JOIN or embed in document
179
+ - Hierarchical: Recursive queries or denormalization
180
+
181
+ ## Security
182
+
183
+ ### Access Control
184
+
185
+ Implement at database:
186
+ - Row-level security (RLS in PostgreSQL, Firestore)
187
+ - Column-level access restrictions
188
+ - Database-level user permissions
189
+
190
+ Implement at application:
191
+ - Verify user owns resource before returning
192
+ - Check permissions before allowing modifications
193
+ - Log access to sensitive data
194
+ - Rate limit database operations
195
+
196
+ ### Sensitive Data
197
+
198
+ Protect sensitive data:
199
+ - Hash passwords (never store plaintext)
200
+ - Encrypt PII at rest
201
+ - Never log sensitive data
202
+ - Mask sensitive data in backups
203
+ - Use parameterized queries to prevent injection
204
+
205
+ ### Backup & Recovery
206
+
207
+ Backup strategy:
208
+ - Automated daily backups
209
+ - Test recovery procedures
210
+ - Retain backups for compliance period
211
+ - Encrypt backups at rest
212
+ - Store backups separately from primary database
213
+
214
+ ## Performance
215
+
216
+ ### Indexing
217
+
218
+ Index columns that are:
219
+ - Frequently filtered (WHERE clause)
220
+ - Used in JOINs
221
+ - Used in ORDER BY
222
+ - Used in DISTINCT
223
+
224
+ Don't over-index:
225
+ - Too many indexes slow down writes
226
+ - Indexes require storage space
227
+ - Maintain only used indexes
228
+
229
+ ### Connection Management
230
+
231
+ Connection pooling:
232
+ - Reuse connections across requests
233
+ - Configure reasonable pool size (10-20 connections)
234
+ - Set idle timeout
235
+ - Monitor connection usage
236
+ - Alert on connection exhaustion
237
+
238
+ ### Query Optimization
239
+
240
+ Optimize slow queries:
241
+ 1. Profile query execution time
242
+ 2. Check execution plan
243
+ 3. Add missing indexes
244
+ 4. Rewrite queries if needed
245
+ 5. Consider denormalization if needed
246
+ 6. Verify schema design
247
+
248
+ ## Monitoring & Maintenance
249
+
250
+ ### Health Checks
251
+
252
+ Monitor:
253
+ - Database connectivity
254
+ - Query performance (slow query logs)
255
+ - Connection pool status
256
+ - Storage space usage
257
+ - Backup completion
258
+ - Replication lag (if applicable)
259
+
260
+ ### Database Maintenance
261
+
262
+ Regular tasks:
263
+ - Update statistics/analyze
264
+ - Vacuum/compact (depending on DB)
265
+ - Rebuild indexes if needed
266
+ - Clean up old audit logs
267
+ - Review and optimize slow queries
268
+
269
+ ## Testing
270
+
271
+ ### Test Data
272
+
273
+ Setup:
274
+ - Use separate test database
275
+ - Reset data before each test
276
+ - Use factories for consistent test data
277
+ - Seed with realistic data
278
+
279
+ Testing patterns:
280
+ - Test CRUD operations
281
+ - Test relationships
282
+ - Test constraints
283
+ - Test error cases
284
+ - Test performance
285
+
286
+ ### Test Examples
287
+
288
+ Test: Create and retrieve user
289
+ 1. Create user with valid data
290
+ 2. Retrieve by ID
291
+ 3. Verify data matches
292
+
293
+ Test: Enforce unique constraint
294
+ 1. Create user with email
295
+ 2. Attempt to create another with same email
296
+ 3. Verify error is returned
297
+
298
+ Test: Cascade delete
299
+ 1. Create parent and child records
300
+ 2. Delete parent
301
+ 3. Verify child is deleted
302
+
303
+ ---
304
+
305
+ Remember: Good database design prevents bugs, improves performance, and makes your application maintainable.