maestro-bundle 1.3.1 → 1.4.0
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.
- package/package.json +1 -1
- package/templates/bundle-ai-agents/skills/agent-orchestration/SKILL.md +107 -41
- package/templates/bundle-ai-agents/skills/agent-orchestration/references/graph-patterns.md +50 -0
- package/templates/bundle-ai-agents/skills/agent-orchestration/references/routing-strategies.md +47 -0
- package/templates/bundle-ai-agents/skills/api-design/SKILL.md +125 -16
- package/templates/bundle-ai-agents/skills/api-design/references/pydantic-patterns.md +72 -0
- package/templates/bundle-ai-agents/skills/api-design/references/rest-conventions.md +51 -0
- package/templates/bundle-ai-agents/skills/clean-architecture/SKILL.md +113 -21
- package/templates/bundle-ai-agents/skills/clean-architecture/references/dependency-injection.md +60 -0
- package/templates/bundle-ai-agents/skills/clean-architecture/references/layer-rules.md +56 -0
- package/templates/bundle-ai-agents/skills/context-engineering/SKILL.md +104 -36
- package/templates/bundle-ai-agents/skills/context-engineering/references/compression-techniques.md +76 -0
- package/templates/bundle-ai-agents/skills/context-engineering/references/context-budget-calculator.md +45 -0
- package/templates/bundle-ai-agents/skills/database-modeling/SKILL.md +146 -19
- package/templates/bundle-ai-agents/skills/database-modeling/references/index-strategies.md +48 -0
- package/templates/bundle-ai-agents/skills/database-modeling/references/naming-conventions.md +27 -0
- package/templates/bundle-ai-agents/skills/docker-containerization/SKILL.md +124 -15
- package/templates/bundle-ai-agents/skills/docker-containerization/references/compose-patterns.md +97 -0
- package/templates/bundle-ai-agents/skills/docker-containerization/references/dockerfile-checklist.md +37 -0
- package/templates/bundle-ai-agents/skills/eval-testing/SKILL.md +113 -25
- package/templates/bundle-ai-agents/skills/eval-testing/references/eval-types.md +52 -0
- package/templates/bundle-ai-agents/skills/eval-testing/references/golden-dataset-template.md +59 -0
- package/templates/bundle-ai-agents/skills/memory-management/SKILL.md +112 -28
- package/templates/bundle-ai-agents/skills/memory-management/references/memory-tiers.md +41 -0
- package/templates/bundle-ai-agents/skills/memory-management/references/namespace-conventions.md +41 -0
- package/templates/bundle-ai-agents/skills/prompt-engineering/SKILL.md +139 -47
- package/templates/bundle-ai-agents/skills/prompt-engineering/references/anti-patterns.md +59 -0
- package/templates/bundle-ai-agents/skills/prompt-engineering/references/prompt-templates.md +75 -0
- package/templates/bundle-ai-agents/skills/rag-pipeline/SKILL.md +104 -27
- package/templates/bundle-ai-agents/skills/rag-pipeline/references/chunking-strategies.md +27 -0
- package/templates/bundle-ai-agents/skills/rag-pipeline/references/embedding-models.md +31 -0
- package/templates/bundle-ai-agents/skills/rag-pipeline/references/rag-evaluation.md +39 -0
- package/templates/bundle-ai-agents/skills/testing-strategy/SKILL.md +127 -18
- package/templates/bundle-ai-agents/skills/testing-strategy/references/fixture-patterns.md +81 -0
- package/templates/bundle-ai-agents/skills/testing-strategy/references/naming-conventions.md +69 -0
- package/templates/bundle-base/skills/branch-strategy/SKILL.md +134 -21
- package/templates/bundle-base/skills/branch-strategy/references/branch-rules.md +40 -0
- package/templates/bundle-base/skills/code-review/SKILL.md +123 -38
- package/templates/bundle-base/skills/code-review/references/review-checklist.md +45 -0
- package/templates/bundle-base/skills/commit-pattern/SKILL.md +98 -39
- package/templates/bundle-base/skills/commit-pattern/references/conventional-commits.md +40 -0
- package/templates/bundle-data-pipeline/skills/data-preprocessing/SKILL.md +110 -19
- package/templates/bundle-data-pipeline/skills/data-preprocessing/references/pandas-cheatsheet.md +63 -0
- package/templates/bundle-data-pipeline/skills/data-preprocessing/references/pandera-schemas.md +44 -0
- package/templates/bundle-data-pipeline/skills/docker-containerization/SKILL.md +132 -16
- package/templates/bundle-data-pipeline/skills/docker-containerization/references/compose-patterns.md +82 -0
- package/templates/bundle-data-pipeline/skills/docker-containerization/references/dockerfile-best-practices.md +57 -0
- package/templates/bundle-data-pipeline/skills/feature-engineering/SKILL.md +143 -45
- package/templates/bundle-data-pipeline/skills/feature-engineering/references/encoding-guide.md +41 -0
- package/templates/bundle-data-pipeline/skills/feature-engineering/references/scaling-guide.md +38 -0
- package/templates/bundle-data-pipeline/skills/mlops-pipeline/SKILL.md +156 -37
- package/templates/bundle-data-pipeline/skills/mlops-pipeline/references/mlflow-commands.md +69 -0
- package/templates/bundle-data-pipeline/skills/model-training/SKILL.md +152 -33
- package/templates/bundle-data-pipeline/skills/model-training/references/evaluation-metrics.md +52 -0
- package/templates/bundle-data-pipeline/skills/model-training/references/model-selection-guide.md +41 -0
- package/templates/bundle-data-pipeline/skills/rag-pipeline/SKILL.md +127 -39
- package/templates/bundle-data-pipeline/skills/rag-pipeline/references/chunking-strategies.md +51 -0
- package/templates/bundle-data-pipeline/skills/rag-pipeline/references/embedding-models.md +49 -0
- package/templates/bundle-frontend-spa/skills/authentication/SKILL.md +196 -13
- package/templates/bundle-frontend-spa/skills/authentication/references/jwt-security.md +41 -0
- package/templates/bundle-frontend-spa/skills/component-design/SKILL.md +191 -41
- package/templates/bundle-frontend-spa/skills/component-design/references/accessibility-checklist.md +41 -0
- package/templates/bundle-frontend-spa/skills/component-design/references/tailwind-patterns.md +65 -0
- package/templates/bundle-frontend-spa/skills/e2e-testing/SKILL.md +241 -79
- package/templates/bundle-frontend-spa/skills/e2e-testing/references/playwright-selectors.md +66 -0
- package/templates/bundle-frontend-spa/skills/e2e-testing/references/test-patterns.md +82 -0
- package/templates/bundle-frontend-spa/skills/integration-api/SKILL.md +221 -31
- package/templates/bundle-frontend-spa/skills/integration-api/references/api-patterns.md +81 -0
- package/templates/bundle-frontend-spa/skills/react-patterns/SKILL.md +195 -70
- package/templates/bundle-frontend-spa/skills/react-patterns/references/component-checklist.md +22 -0
- package/templates/bundle-frontend-spa/skills/react-patterns/references/hook-patterns.md +63 -0
- package/templates/bundle-frontend-spa/skills/responsive-layout/SKILL.md +162 -22
- package/templates/bundle-frontend-spa/skills/responsive-layout/references/breakpoint-guide.md +63 -0
- package/templates/bundle-frontend-spa/skills/state-management/SKILL.md +158 -30
- package/templates/bundle-frontend-spa/skills/state-management/references/react-query-config.md +64 -0
- package/templates/bundle-frontend-spa/skills/state-management/references/state-patterns.md +78 -0
- package/templates/bundle-jhipster-microservices/skills/ci-cd-pipeline/SKILL.md +135 -45
- package/templates/bundle-jhipster-microservices/skills/ci-cd-pipeline/references/gitlab-ci-templates.md +93 -0
- package/templates/bundle-jhipster-microservices/skills/clean-architecture/SKILL.md +87 -21
- package/templates/bundle-jhipster-microservices/skills/clean-architecture/references/layer-rules.md +78 -0
- package/templates/bundle-jhipster-microservices/skills/ddd-tactical/SKILL.md +94 -25
- package/templates/bundle-jhipster-microservices/skills/ddd-tactical/references/ddd-patterns.md +48 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-angular/SKILL.md +63 -21
- package/templates/bundle-jhipster-microservices/skills/jhipster-angular/references/angular-microservices.md +40 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-angular/references/angular-structure.md +59 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-docker-k8s/SKILL.md +125 -91
- package/templates/bundle-jhipster-microservices/skills/jhipster-docker-k8s/references/docker-k8s-commands.md +68 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-entities/SKILL.md +72 -20
- package/templates/bundle-jhipster-microservices/skills/jhipster-entities/references/cross-service-entities.md +36 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-entities/references/jdl-types.md +56 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-gateway/SKILL.md +80 -8
- package/templates/bundle-jhipster-microservices/skills/jhipster-gateway/references/gateway-config.md +43 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-kafka/SKILL.md +115 -22
- package/templates/bundle-jhipster-microservices/skills/jhipster-kafka/references/kafka-events.md +39 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-registry/SKILL.md +92 -23
- package/templates/bundle-jhipster-microservices/skills/jhipster-registry/references/consul-config.md +61 -0
- package/templates/bundle-jhipster-microservices/skills/jhipster-service/SKILL.md +81 -18
- package/templates/bundle-jhipster-microservices/skills/jhipster-service/references/service-patterns.md +40 -0
- package/templates/bundle-jhipster-microservices/skills/testing-strategy/SKILL.md +101 -20
- package/templates/bundle-jhipster-microservices/skills/testing-strategy/references/test-naming.md +55 -0
- package/templates/bundle-jhipster-monorepo/skills/clean-architecture/SKILL.md +87 -21
- package/templates/bundle-jhipster-monorepo/skills/clean-architecture/references/layer-rules.md +78 -0
- package/templates/bundle-jhipster-monorepo/skills/ddd-tactical/SKILL.md +94 -25
- package/templates/bundle-jhipster-monorepo/skills/ddd-tactical/references/ddd-patterns.md +48 -0
- package/templates/bundle-jhipster-monorepo/skills/jhipster-angular/SKILL.md +99 -52
- package/templates/bundle-jhipster-monorepo/skills/jhipster-angular/references/angular-structure.md +59 -0
- package/templates/bundle-jhipster-monorepo/skills/jhipster-entities/SKILL.md +89 -36
- package/templates/bundle-jhipster-monorepo/skills/jhipster-entities/references/jdl-types.md +56 -0
- package/templates/bundle-jhipster-monorepo/skills/jhipster-liquibase/SKILL.md +123 -23
- package/templates/bundle-jhipster-monorepo/skills/jhipster-liquibase/references/liquibase-operations.md +95 -0
- package/templates/bundle-jhipster-monorepo/skills/jhipster-security/SKILL.md +106 -19
- package/templates/bundle-jhipster-monorepo/skills/jhipster-security/references/security-checklist.md +47 -0
- package/templates/bundle-jhipster-monorepo/skills/jhipster-spring/SKILL.md +84 -16
- package/templates/bundle-jhipster-monorepo/skills/jhipster-spring/references/spring-layers.md +41 -0
- package/templates/bundle-jhipster-monorepo/skills/testing-strategy/SKILL.md +101 -20
- package/templates/bundle-jhipster-monorepo/skills/testing-strategy/references/test-naming.md +55 -0
|
@@ -1,19 +1,55 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: database-modeling
|
|
3
|
-
description:
|
|
3
|
+
description: Model PostgreSQL databases with migrations, indexes, and pgvector. Use when creating tables, defining schemas, writing migrations, or optimizing queries.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
author: Maestro
|
|
4
6
|
---
|
|
5
7
|
|
|
6
|
-
#
|
|
8
|
+
# Database Modeling
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
Design PostgreSQL schemas with proper conventions, Alembic migrations, performant indexes, pgvector for semantic search, and full-text search capabilities.
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
12
|
+
## When to Use
|
|
13
|
+
- Creating new database tables or modifying existing schemas
|
|
14
|
+
- Writing Alembic migrations
|
|
15
|
+
- Adding indexes to optimize slow queries
|
|
16
|
+
- Setting up pgvector for embedding storage
|
|
17
|
+
- Configuring full-text search
|
|
18
|
+
- Reviewing schema design for anti-patterns
|
|
19
|
+
|
|
20
|
+
## Available Operations
|
|
21
|
+
1. Design tables following naming conventions
|
|
22
|
+
2. Create Alembic migrations (upgrade and downgrade)
|
|
23
|
+
3. Add indexes for query optimization
|
|
24
|
+
4. Set up pgvector for semantic search
|
|
25
|
+
5. Configure full-text search with tsvector
|
|
26
|
+
6. Analyze and optimize slow queries with EXPLAIN
|
|
27
|
+
|
|
28
|
+
## Multi-Step Workflow
|
|
29
|
+
|
|
30
|
+
### Step 1: Design the Table Schema
|
|
31
|
+
|
|
32
|
+
Follow these naming conventions strictly:
|
|
33
|
+
|
|
34
|
+
- Table names: `snake_case`, plural (`demands`, `tasks`, `agents`)
|
|
35
|
+
- Primary keys: `id UUID DEFAULT gen_random_uuid()`
|
|
36
|
+
- Foreign keys: `<singular_table>_id` (e.g., `demand_id`)
|
|
37
|
+
- Timestamps: `created_at`, `updated_at` with default `NOW()`
|
|
14
38
|
- Soft delete: `deleted_at TIMESTAMP NULL`
|
|
15
39
|
|
|
16
|
-
|
|
40
|
+
### Step 2: Create the Alembic Migration
|
|
41
|
+
|
|
42
|
+
Generate and write the migration file.
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Generate a new migration
|
|
46
|
+
alembic revision --autogenerate -m "create_demands_table"
|
|
47
|
+
|
|
48
|
+
# Or create manually
|
|
49
|
+
alembic revision -m "create_demands_table"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Write the migration:
|
|
17
53
|
|
|
18
54
|
```python
|
|
19
55
|
# alembic/versions/001_create_demands.py
|
|
@@ -32,28 +68,119 @@ def downgrade():
|
|
|
32
68
|
op.drop_table('demands')
|
|
33
69
|
```
|
|
34
70
|
|
|
35
|
-
|
|
71
|
+
Run the migration:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Apply migration
|
|
75
|
+
alembic upgrade head
|
|
76
|
+
|
|
77
|
+
# Verify the table was created
|
|
78
|
+
psql $DATABASE_URL -c "\d demands"
|
|
79
|
+
|
|
80
|
+
# Check migration history
|
|
81
|
+
alembic history
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Step 3: Add Performance Indexes
|
|
85
|
+
|
|
86
|
+
Index columns used in WHERE clauses, JOINs, and ORDER BY.
|
|
36
87
|
|
|
37
88
|
```sql
|
|
38
|
-
--
|
|
89
|
+
-- Partial index for active records (most queries filter by status)
|
|
39
90
|
CREATE INDEX idx_tasks_status ON tasks(status) WHERE status != 'completed';
|
|
91
|
+
|
|
92
|
+
-- Foreign key index for JOIN performance
|
|
40
93
|
CREATE INDEX idx_tasks_demand ON tasks(demand_id);
|
|
94
|
+
|
|
95
|
+
-- Composite index for common query patterns
|
|
41
96
|
CREATE INDEX idx_tracking_events_demand_agent ON tracking_events(demand_id, agent_id, created_at DESC);
|
|
97
|
+
```
|
|
42
98
|
|
|
43
|
-
|
|
99
|
+
### Step 4: Set Up pgvector for Semantic Search
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Enable pgvector extension
|
|
103
|
+
psql $DATABASE_URL -c "CREATE EXTENSION IF NOT EXISTS vector;"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```sql
|
|
107
|
+
-- Create embeddings table
|
|
108
|
+
CREATE TABLE bundle_embeddings (
|
|
109
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
110
|
+
content TEXT NOT NULL,
|
|
111
|
+
embedding vector(1536) NOT NULL,
|
|
112
|
+
metadata JSONB,
|
|
113
|
+
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
-- HNSW index for fast cosine similarity search
|
|
44
117
|
CREATE INDEX idx_embeddings_vector ON bundle_embeddings
|
|
45
118
|
USING hnsw (embedding vector_cosine_ops) WITH (m = 16, ef_construction = 200);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Step 5: Configure Full-Text Search
|
|
46
122
|
|
|
47
|
-
|
|
123
|
+
```sql
|
|
124
|
+
-- Add generated tsvector column
|
|
48
125
|
ALTER TABLE bundles ADD COLUMN search_vector tsvector
|
|
49
|
-
GENERATED ALWAYS AS (to_tsvector('
|
|
126
|
+
GENERATED ALWAYS AS (to_tsvector('english', name || ' ' || description)) STORED;
|
|
127
|
+
|
|
128
|
+
-- GIN index for full-text search
|
|
50
129
|
CREATE INDEX idx_bundles_search ON bundles USING GIN(search_vector);
|
|
51
130
|
```
|
|
52
131
|
|
|
53
|
-
|
|
132
|
+
### Step 6: Analyze and Optimize Queries
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
# Run EXPLAIN ANALYZE on slow queries
|
|
136
|
+
psql $DATABASE_URL -c "EXPLAIN ANALYZE SELECT * FROM tasks WHERE demand_id = 'abc-123' AND status = 'pending';"
|
|
137
|
+
|
|
138
|
+
# Check for missing indexes
|
|
139
|
+
psql $DATABASE_URL -c "SELECT schemaname, tablename, indexname FROM pg_indexes WHERE tablename = 'tasks';"
|
|
140
|
+
|
|
141
|
+
# Check table sizes
|
|
142
|
+
psql $DATABASE_URL -c "SELECT pg_size_pretty(pg_total_relation_size('tasks'));"
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Resources
|
|
146
|
+
- `references/naming-conventions.md` - Complete naming conventions for PostgreSQL schemas
|
|
147
|
+
- `references/index-strategies.md` - When and how to create indexes for different query patterns
|
|
148
|
+
|
|
149
|
+
## Examples
|
|
150
|
+
|
|
151
|
+
### Example 1: Create a New Feature Table
|
|
152
|
+
User asks: "Create a tasks table with status tracking and assignment to agents."
|
|
153
|
+
Response approach:
|
|
154
|
+
1. Design columns: id (UUID), title, description, status, demand_id (FK), agent_id (FK), timestamps
|
|
155
|
+
2. Write Alembic migration with proper types and defaults
|
|
156
|
+
3. Add foreign key constraints with ON DELETE behavior
|
|
157
|
+
4. Create indexes on demand_id, agent_id, and status
|
|
158
|
+
5. Run migration: `alembic upgrade head`
|
|
159
|
+
6. Verify: `psql $DATABASE_URL -c "\d tasks"`
|
|
160
|
+
|
|
161
|
+
### Example 2: Optimize a Slow Query
|
|
162
|
+
User asks: "The demands list endpoint is slow when filtering by status."
|
|
163
|
+
Response approach:
|
|
164
|
+
1. Run `EXPLAIN ANALYZE` on the slow query
|
|
165
|
+
2. Check if an index exists on the status column
|
|
166
|
+
3. Create a partial index: `CREATE INDEX idx_demands_status ON demands(status) WHERE deleted_at IS NULL;`
|
|
167
|
+
4. Re-run `EXPLAIN ANALYZE` and compare execution times
|
|
168
|
+
5. Verify the index is being used (look for "Index Scan" in the plan)
|
|
169
|
+
|
|
170
|
+
### Example 3: Add Soft Delete
|
|
171
|
+
User asks: "Implement soft delete for the demands table."
|
|
172
|
+
Response approach:
|
|
173
|
+
1. Write migration to add `deleted_at TIMESTAMP NULL` column
|
|
174
|
+
2. Update partial indexes to exclude soft-deleted rows: `WHERE deleted_at IS NULL`
|
|
175
|
+
3. Update repository queries to filter `WHERE deleted_at IS NULL` by default
|
|
176
|
+
4. Create a `restore` method that sets `deleted_at = NULL`
|
|
177
|
+
5. Run: `alembic upgrade head`
|
|
54
178
|
|
|
55
|
-
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
-
|
|
179
|
+
## Notes
|
|
180
|
+
- Never alter schema without a migration -- even in development
|
|
181
|
+
- Always write both `upgrade()` and `downgrade()` functions
|
|
182
|
+
- Do not create indexes on every column (increases write cost)
|
|
183
|
+
- Do not use `SELECT *` in production code -- select only needed columns
|
|
184
|
+
- Always run `EXPLAIN ANALYZE` before and after adding indexes to verify improvement
|
|
185
|
+
- Use `CASCADE DELETE` with extreme caution -- prefer soft delete or application-level cleanup
|
|
186
|
+
- Use `TIMESTAMP WITH TIME ZONE` for all timestamp columns
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Index Strategies Reference
|
|
2
|
+
|
|
3
|
+
## When to Create Indexes
|
|
4
|
+
|
|
5
|
+
| Query Pattern | Index Type | Example |
|
|
6
|
+
|---|---|---|
|
|
7
|
+
| `WHERE column = value` | B-tree (default) | `CREATE INDEX idx_tasks_status ON tasks(status)` |
|
|
8
|
+
| `WHERE col1 = X AND col2 = Y` | Composite | `CREATE INDEX idx_tasks_demand_status ON tasks(demand_id, status)` |
|
|
9
|
+
| `WHERE status != 'completed'` | Partial | `CREATE INDEX idx_tasks_active ON tasks(status) WHERE status != 'completed'` |
|
|
10
|
+
| `WHERE deleted_at IS NULL` | Partial | `CREATE INDEX idx_demands_live ON demands(id) WHERE deleted_at IS NULL` |
|
|
11
|
+
| Full-text search | GIN on tsvector | `CREATE INDEX idx_search ON docs USING GIN(search_vector)` |
|
|
12
|
+
| Vector similarity | HNSW | `CREATE INDEX idx_vec ON embeddings USING hnsw(embedding vector_cosine_ops)` |
|
|
13
|
+
| JSONB queries | GIN | `CREATE INDEX idx_meta ON docs USING GIN(metadata)` |
|
|
14
|
+
|
|
15
|
+
## When NOT to Create Indexes
|
|
16
|
+
|
|
17
|
+
- Tables with fewer than 1,000 rows (sequential scan is faster)
|
|
18
|
+
- Columns with very low cardinality (e.g., boolean with 50/50 distribution)
|
|
19
|
+
- Columns that are rarely used in WHERE, JOIN, or ORDER BY
|
|
20
|
+
- Write-heavy tables where index maintenance cost exceeds read benefit
|
|
21
|
+
|
|
22
|
+
## Composite Index Column Order
|
|
23
|
+
|
|
24
|
+
Put the most selective column first (the one that filters out the most rows).
|
|
25
|
+
|
|
26
|
+
```sql
|
|
27
|
+
-- Good: demand_id is more selective than status
|
|
28
|
+
CREATE INDEX idx_tasks_demand_status ON tasks(demand_id, status);
|
|
29
|
+
|
|
30
|
+
-- Bad: status has few distinct values, less selective
|
|
31
|
+
CREATE INDEX idx_tasks_status_demand ON tasks(status, demand_id);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Monitoring Index Usage
|
|
35
|
+
|
|
36
|
+
```sql
|
|
37
|
+
-- Find unused indexes
|
|
38
|
+
SELECT indexrelname, idx_scan, idx_tup_read
|
|
39
|
+
FROM pg_stat_user_indexes
|
|
40
|
+
WHERE idx_scan = 0
|
|
41
|
+
ORDER BY pg_relation_size(indexrelid) DESC;
|
|
42
|
+
|
|
43
|
+
-- Find missing indexes (sequential scans on large tables)
|
|
44
|
+
SELECT relname, seq_scan, idx_scan, n_live_tup
|
|
45
|
+
FROM pg_stat_user_tables
|
|
46
|
+
WHERE seq_scan > idx_scan AND n_live_tup > 10000
|
|
47
|
+
ORDER BY seq_scan - idx_scan DESC;
|
|
48
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Naming Conventions Reference
|
|
2
|
+
|
|
3
|
+
## Tables
|
|
4
|
+
- `snake_case`, plural: `demands`, `tasks`, `tracking_events`
|
|
5
|
+
- Junction tables: `<table1>_<table2>` alphabetically: `agents_tasks`
|
|
6
|
+
|
|
7
|
+
## Columns
|
|
8
|
+
- Primary key: `id` (always UUID with `gen_random_uuid()`)
|
|
9
|
+
- Foreign key: `<singular_table>_id`: `demand_id`, `agent_id`
|
|
10
|
+
- Boolean: `is_<adjective>`: `is_active`, `is_verified`
|
|
11
|
+
- Timestamps: `created_at`, `updated_at`, `deleted_at`
|
|
12
|
+
- Status: `status VARCHAR(20)` with constrained values
|
|
13
|
+
|
|
14
|
+
## Indexes
|
|
15
|
+
- Format: `idx_<table>_<columns>`: `idx_tasks_status`, `idx_tasks_demand_id`
|
|
16
|
+
- Unique: `uq_<table>_<columns>`: `uq_users_email`
|
|
17
|
+
- Partial: suffix with purpose: `idx_tasks_status_active`
|
|
18
|
+
|
|
19
|
+
## Constraints
|
|
20
|
+
- Primary key: `pk_<table>`: `pk_demands`
|
|
21
|
+
- Foreign key: `fk_<table>_<referenced>`: `fk_tasks_demands`
|
|
22
|
+
- Unique: `uq_<table>_<columns>`: `uq_users_email`
|
|
23
|
+
- Check: `ck_<table>_<rule>`: `ck_demands_status_valid`
|
|
24
|
+
|
|
25
|
+
## Migrations
|
|
26
|
+
- Format: `NNN_<action>_<table>.py`: `001_create_demands.py`, `002_add_tasks_status_index.py`
|
|
27
|
+
- Actions: `create`, `add`, `alter`, `drop`, `rename`
|
|
@@ -1,11 +1,51 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: docker-containerization
|
|
3
|
-
description:
|
|
3
|
+
description: Create optimized Dockerfiles with multi-stage builds, security hardening, and docker-compose for development. Use when containerizing applications, creating Dockerfiles, or configuring dev environments.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
author: Maestro
|
|
4
6
|
---
|
|
5
7
|
|
|
6
8
|
# Docker Containerization
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
Build production-ready Docker images with multi-stage builds, non-root users, health checks, and docker-compose configurations for local development.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
- Containerizing a Python (FastAPI/Django) or Node.js (React/Next.js) application
|
|
14
|
+
- Creating or optimizing a Dockerfile
|
|
15
|
+
- Setting up docker-compose for local development
|
|
16
|
+
- Adding health checks, security hardening, or image size optimization
|
|
17
|
+
- Configuring multi-service development environments (API + DB + Redis + MinIO)
|
|
18
|
+
|
|
19
|
+
## Available Operations
|
|
20
|
+
1. Create multi-stage Dockerfiles for Python applications
|
|
21
|
+
2. Create multi-stage Dockerfiles for React/Node.js applications
|
|
22
|
+
3. Configure docker-compose for development
|
|
23
|
+
4. Add security hardening (non-root user, minimal base image)
|
|
24
|
+
5. Add health checks for container orchestration
|
|
25
|
+
6. Create .dockerignore for build optimization
|
|
26
|
+
|
|
27
|
+
## Multi-Step Workflow
|
|
28
|
+
|
|
29
|
+
### Step 1: Create .dockerignore
|
|
30
|
+
|
|
31
|
+
Always start with .dockerignore to prevent unnecessary files from entering the build context.
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
.git
|
|
35
|
+
node_modules
|
|
36
|
+
__pycache__
|
|
37
|
+
*.pyc
|
|
38
|
+
.env
|
|
39
|
+
.venv
|
|
40
|
+
dist
|
|
41
|
+
build
|
|
42
|
+
coverage
|
|
43
|
+
.pytest_cache
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Step 2: Create the Dockerfile (Python)
|
|
47
|
+
|
|
48
|
+
Use multi-stage build for minimal image size.
|
|
9
49
|
|
|
10
50
|
```dockerfile
|
|
11
51
|
# === Build stage ===
|
|
@@ -27,7 +67,7 @@ HEALTHCHECK --interval=30s --timeout=5s CMD curl -f http://localhost:8000/health
|
|
|
27
67
|
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
28
68
|
```
|
|
29
69
|
|
|
30
|
-
|
|
70
|
+
### Step 3: Create the Dockerfile (React)
|
|
31
71
|
|
|
32
72
|
```dockerfile
|
|
33
73
|
FROM node:20-slim AS builder
|
|
@@ -43,7 +83,7 @@ COPY nginx.conf /etc/nginx/conf.d/default.conf
|
|
|
43
83
|
EXPOSE 80
|
|
44
84
|
```
|
|
45
85
|
|
|
46
|
-
|
|
86
|
+
### Step 4: Configure Docker Compose for Development
|
|
47
87
|
|
|
48
88
|
```yaml
|
|
49
89
|
# docker-compose.dev.yml
|
|
@@ -98,17 +138,86 @@ volumes:
|
|
|
98
138
|
pgdata:
|
|
99
139
|
```
|
|
100
140
|
|
|
101
|
-
|
|
141
|
+
### Step 5: Build and Test
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
# Build the image
|
|
145
|
+
docker build -t maestro-api -f docker/Dockerfile.api .
|
|
146
|
+
|
|
147
|
+
# Check image size
|
|
148
|
+
docker images maestro-api
|
|
149
|
+
|
|
150
|
+
# Run and test health check
|
|
151
|
+
docker run -d --name test-api -p 8000:8000 maestro-api
|
|
152
|
+
curl -f http://localhost:8000/health
|
|
153
|
+
docker stop test-api && docker rm test-api
|
|
102
154
|
|
|
155
|
+
# Start the full dev environment
|
|
156
|
+
docker compose -f docker-compose.dev.yml up -d
|
|
157
|
+
|
|
158
|
+
# Verify all services are healthy
|
|
159
|
+
docker compose -f docker-compose.dev.yml ps
|
|
160
|
+
|
|
161
|
+
# View logs
|
|
162
|
+
docker compose -f docker-compose.dev.yml logs -f api
|
|
103
163
|
```
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
164
|
+
|
|
165
|
+
### Step 6: Security Audit
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
# Scan for vulnerabilities
|
|
169
|
+
docker scout cves maestro-api
|
|
170
|
+
|
|
171
|
+
# Verify non-root user
|
|
172
|
+
docker run --rm maestro-api whoami # Should output "appuser"
|
|
173
|
+
|
|
174
|
+
# Check no secrets in the image
|
|
175
|
+
docker history maestro-api --no-trunc | grep -i "secret\|password\|key"
|
|
114
176
|
```
|
|
177
|
+
|
|
178
|
+
## Resources
|
|
179
|
+
- `references/dockerfile-checklist.md` - Security and optimization checklist for Dockerfiles
|
|
180
|
+
- `references/compose-patterns.md` - Common docker-compose patterns for dev environments
|
|
181
|
+
|
|
182
|
+
## Examples
|
|
183
|
+
|
|
184
|
+
### Example 1: Containerize a FastAPI Application
|
|
185
|
+
User asks: "Containerize our FastAPI backend for production."
|
|
186
|
+
Response approach:
|
|
187
|
+
1. Create .dockerignore to exclude .venv, __pycache__, .env
|
|
188
|
+
2. Write multi-stage Dockerfile: builder installs deps, runtime copies only what's needed
|
|
189
|
+
3. Add non-root user (appuser)
|
|
190
|
+
4. Add HEALTHCHECK on /health endpoint
|
|
191
|
+
5. Build: `docker build -t api -f Dockerfile .`
|
|
192
|
+
6. Test: `docker run -p 8000:8000 api && curl localhost:8000/health`
|
|
193
|
+
7. Check size: `docker images api` (target: < 200MB)
|
|
194
|
+
|
|
195
|
+
### Example 2: Set Up Local Dev Environment
|
|
196
|
+
User asks: "Set up docker-compose so new developers can run everything locally."
|
|
197
|
+
Response approach:
|
|
198
|
+
1. Create docker-compose.dev.yml with api, postgres (pgvector), redis, minio
|
|
199
|
+
2. Add health checks on postgres so api waits for DB readiness
|
|
200
|
+
3. Mount source code as volume for hot reload
|
|
201
|
+
4. Set environment variables for local database URLs
|
|
202
|
+
5. Start: `docker compose -f docker-compose.dev.yml up -d`
|
|
203
|
+
6. Verify: `docker compose ps` (all services should be "healthy")
|
|
204
|
+
|
|
205
|
+
### Example 3: Optimize Image Size
|
|
206
|
+
User asks: "Our Docker image is 1.2GB. Make it smaller."
|
|
207
|
+
Response approach:
|
|
208
|
+
1. Switch to multi-stage build if not already using one
|
|
209
|
+
2. Use `python:3.11-slim` instead of `python:3.11`
|
|
210
|
+
3. Use `--no-cache-dir` on pip install
|
|
211
|
+
4. Use `--no-install-recommends` on apt-get
|
|
212
|
+
5. Remove apt cache: `rm -rf /var/lib/apt/lists/*`
|
|
213
|
+
6. Check .dockerignore for missing exclusions
|
|
214
|
+
7. Target: under 200MB for Python, under 50MB for React (nginx)
|
|
215
|
+
|
|
216
|
+
## Notes
|
|
217
|
+
- Always use multi-stage builds to keep production images small
|
|
218
|
+
- Never run containers as root -- create a dedicated appuser
|
|
219
|
+
- Never put secrets in Dockerfiles or docker-compose files -- use environment variables
|
|
220
|
+
- Always add HEALTHCHECK for production containers
|
|
221
|
+
- Use `docker compose` (v2) not `docker-compose` (v1)
|
|
222
|
+
- Pin base image versions in production (e.g., `python:3.11.7-slim`, not `python:3.11-slim`)
|
|
223
|
+
- Volume mounts for hot reload should only be used in development
|
package/templates/bundle-ai-agents/skills/docker-containerization/references/compose-patterns.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Docker Compose Patterns Reference
|
|
2
|
+
|
|
3
|
+
## Health Check Pattern
|
|
4
|
+
|
|
5
|
+
Always use health checks so dependent services wait for readiness.
|
|
6
|
+
|
|
7
|
+
```yaml
|
|
8
|
+
postgres:
|
|
9
|
+
image: pgvector/pgvector:pg16
|
|
10
|
+
healthcheck:
|
|
11
|
+
test: ["CMD-SHELL", "pg_isready -U maestro"]
|
|
12
|
+
interval: 5s
|
|
13
|
+
timeout: 5s
|
|
14
|
+
retries: 5
|
|
15
|
+
|
|
16
|
+
api:
|
|
17
|
+
depends_on:
|
|
18
|
+
postgres:
|
|
19
|
+
condition: service_healthy
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Hot Reload Pattern
|
|
23
|
+
|
|
24
|
+
Mount source code for development, but never in production.
|
|
25
|
+
|
|
26
|
+
```yaml
|
|
27
|
+
api:
|
|
28
|
+
volumes:
|
|
29
|
+
- ./src:/app/src # Source code hot reload
|
|
30
|
+
- /app/node_modules # Exclude node_modules from mount
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Environment Variables Pattern
|
|
34
|
+
|
|
35
|
+
```yaml
|
|
36
|
+
# Development: inline values
|
|
37
|
+
api:
|
|
38
|
+
environment:
|
|
39
|
+
- DATABASE_URL=postgresql://maestro:maestro@postgres/maestro
|
|
40
|
+
- DEBUG=true
|
|
41
|
+
|
|
42
|
+
# Production: use .env file or secrets
|
|
43
|
+
api:
|
|
44
|
+
env_file:
|
|
45
|
+
- .env.production
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Named Volumes for Persistence
|
|
49
|
+
|
|
50
|
+
```yaml
|
|
51
|
+
volumes:
|
|
52
|
+
pgdata: # PostgreSQL data
|
|
53
|
+
redis-data: # Redis persistence
|
|
54
|
+
minio-data: # MinIO object storage
|
|
55
|
+
|
|
56
|
+
services:
|
|
57
|
+
postgres:
|
|
58
|
+
volumes:
|
|
59
|
+
- pgdata:/var/lib/postgresql/data
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Multi-Profile Pattern
|
|
63
|
+
|
|
64
|
+
```yaml
|
|
65
|
+
services:
|
|
66
|
+
api:
|
|
67
|
+
profiles: ["dev", "prod"]
|
|
68
|
+
|
|
69
|
+
debug-tools:
|
|
70
|
+
profiles: ["dev"]
|
|
71
|
+
image: busybox
|
|
72
|
+
|
|
73
|
+
# Start only dev profile
|
|
74
|
+
# docker compose --profile dev up
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Networking Pattern
|
|
78
|
+
|
|
79
|
+
```yaml
|
|
80
|
+
services:
|
|
81
|
+
api:
|
|
82
|
+
networks:
|
|
83
|
+
- backend
|
|
84
|
+
|
|
85
|
+
postgres:
|
|
86
|
+
networks:
|
|
87
|
+
- backend
|
|
88
|
+
|
|
89
|
+
frontend:
|
|
90
|
+
networks:
|
|
91
|
+
- frontend
|
|
92
|
+
- backend # Needs to reach API
|
|
93
|
+
|
|
94
|
+
networks:
|
|
95
|
+
frontend:
|
|
96
|
+
backend:
|
|
97
|
+
```
|
package/templates/bundle-ai-agents/skills/docker-containerization/references/dockerfile-checklist.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Dockerfile Checklist Reference
|
|
2
|
+
|
|
3
|
+
## Security
|
|
4
|
+
|
|
5
|
+
- [ ] Non-root user created and used (`USER appuser`)
|
|
6
|
+
- [ ] Base image is minimal (`-slim` or `-alpine`)
|
|
7
|
+
- [ ] No secrets or credentials in the Dockerfile
|
|
8
|
+
- [ ] No `sudo` or `setuid` binaries
|
|
9
|
+
- [ ] `COPY` specific files, not `COPY . .` without .dockerignore
|
|
10
|
+
|
|
11
|
+
## Optimization
|
|
12
|
+
|
|
13
|
+
- [ ] Multi-stage build (separate builder and runtime stages)
|
|
14
|
+
- [ ] `--no-cache-dir` on pip install
|
|
15
|
+
- [ ] `--no-install-recommends` on apt-get
|
|
16
|
+
- [ ] `rm -rf /var/lib/apt/lists/*` after apt-get
|
|
17
|
+
- [ ] `.dockerignore` excludes .git, node_modules, .env, __pycache__
|
|
18
|
+
- [ ] Dependencies installed before source code (layer caching)
|
|
19
|
+
- [ ] Final image size under 200MB (Python) or 50MB (React/nginx)
|
|
20
|
+
|
|
21
|
+
## Production Readiness
|
|
22
|
+
|
|
23
|
+
- [ ] HEALTHCHECK defined
|
|
24
|
+
- [ ] EXPOSE declares the correct port
|
|
25
|
+
- [ ] CMD uses exec form (`["cmd", "arg"]`), not shell form
|
|
26
|
+
- [ ] WORKDIR is set
|
|
27
|
+
- [ ] Labels for metadata (optional): `LABEL maintainer="team"`
|
|
28
|
+
|
|
29
|
+
## Common Mistakes
|
|
30
|
+
|
|
31
|
+
| Mistake | Fix |
|
|
32
|
+
|---|---|
|
|
33
|
+
| `COPY . .` before `pip install` | Copy requirements.txt first, then install, then copy source |
|
|
34
|
+
| Running as root | `RUN useradd appuser` + `USER appuser` |
|
|
35
|
+
| Using `latest` tag | Pin version: `python:3.11.7-slim` |
|
|
36
|
+
| Installing dev dependencies | Use `pip install --no-dev` or separate requirements files |
|
|
37
|
+
| Large final image | Use multi-stage build; check with `docker images` |
|