everything-gemini 1.1.1 → 1.8.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/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +27 -0
- package/.github/ISSUE_TEMPLATE/subagent_proposal.md +29 -0
- package/.github/workflows/ci.yml +72 -1
- package/.github/workflows/release.yml +17 -2
- package/.vscode/extensions.json +8 -0
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +167 -0
- package/CONTRIBUTING.md +85 -4
- package/README.md +139 -18
- package/SECURITY.md +38 -0
- package/action.yml +35 -0
- package/agents/browser-qa.md +1 -1
- package/agents/database-migrator.md +26 -0
- package/agents/documentation-writer.md +27 -0
- package/agents/incident-responder.md +34 -0
- package/agents/performance-tuner.md +27 -0
- package/agents/release-engineer.md +34 -0
- package/bin/everything-gemini +1550 -86
- package/docs/COMMUNITY_SUBMISSIONS.md +88 -0
- package/docs/LAUNCH_KIT.md +148 -22
- package/docs/architecture/progressive-disclosure.md +3 -3
- package/docs/index.html +401 -37
- package/docs/launch-kit.md +163 -0
- package/examples/cli-workflows/README.md +45 -0
- package/examples/cli-workflows/demo_workflow.sh +39 -0
- package/examples/python-sdk/README.md +28 -5
- package/examples/python-sdk/documentation_audit_pipeline.py +83 -0
- package/examples/python-sdk/incident_triage_pipeline.py +170 -0
- package/examples/python-sdk/multi_agent_pipeline.py +95 -0
- package/examples/python-sdk/release_readiness_audit.py +144 -0
- package/hooks/secret-scrubber/hooks.json +16 -0
- package/hooks/secret-scrubber/scripts/scrub-secrets.sh +62 -0
- package/mcp/README.md +20 -0
- package/mcp/mcp_config.example.json +35 -0
- package/package.json +3 -1
- package/plugins/core/rules/core-practices.md +63 -4
- package/plugins/python-ai/rules/ai-agent-patterns.md +67 -4
- package/plugins/security-shield/rules/zero-trust.md +60 -4
- package/plugins/web-fullstack/rules/frontend-standards.md +74 -4
- package/rules/paradigms/security-hardened.md +53 -10
- package/rules/paradigms/tdd.md +65 -8
- package/scripts/install.ps1 +14 -0
- package/scripts/install.sh +15 -1
- package/scripts/validate.sh +103 -12
- package/skills/agent-evals/SKILL.md +61 -0
- package/skills/apache-kafka-streams/SKILL.md +152 -0
- package/skills/argo-workflows/SKILL.md +151 -0
- package/skills/axum-web-service/SKILL.md +159 -0
- package/skills/cilium-ebpf-networking/SKILL.md +145 -0
- package/skills/clickhouse-analytics/SKILL.md +128 -0
- package/skills/dbt-transformation/SKILL.md +179 -0
- package/skills/debezium-cdc/SKILL.md +166 -0
- package/skills/docker-compose-orchestrator/SKILL.md +85 -0
- package/skills/duckdb-local-olap/SKILL.md +134 -0
- package/skills/fastapi-production/SKILL.md +157 -0
- package/skills/graphql-architect/SKILL.md +78 -0
- package/skills/grpc-connect-rpc/SKILL.md +176 -0
- package/skills/langgraph-orchestrator/SKILL.md +144 -0
- package/skills/litellm-proxy-gateway/SKILL.md +154 -0
- package/skills/nats-jetstream/SKILL.md +122 -0
- package/skills/open-telemetry-tracing/SKILL.md +151 -0
- package/skills/playwright-visual-regression/SKILL.md +124 -0
- package/skills/redis-cache-patterns/SKILL.md +159 -0
- package/skills/svelte-kit-architect/SKILL.md +190 -0
- package/skills/temporal-workflows/SKILL.md +158 -0
- package/skills/trpc-react-query/SKILL.md +169 -0
- package/skills/turborepo-monorepo/SKILL.md +199 -0
- package/skills/vllm-inference/SKILL.md +144 -0
- package/skills/wasm-rust-optimizer/SKILL.md +130 -0
- package/templates/full-power/hooks.json +14 -0
- package/templates/full-power/mcp_config.json +43 -0
- package/templates/recommended/hooks.json +14 -0
- package/tests/cli.test.js +383 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dbt-transformation
|
|
3
|
+
description: >-
|
|
4
|
+
Designs, develops, and tests modular SQL data transformations using dbt (data build tool), Jinja macros, semantic layer metrics, automated schema tests, and documentation generation.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# dbt Modular Transformation & Data Modeling
|
|
8
|
+
|
|
9
|
+
This skill guides structuring production-grade ELT pipelines using dbt (Core & Cloud), enforcing modular layer architecture (staging, intermediate, marts), DRY Jinja macros, automated data testing, and incremental table materialization.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## ⚡ Core Patterns
|
|
14
|
+
|
|
15
|
+
### 1. Multi-Layer Dimensional Modeling Architecture
|
|
16
|
+
|
|
17
|
+
Organize transformations into clean, progressive DAG layers:
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
models/
|
|
21
|
+
├── staging/ # 1:1 view on raw sources (renaming, casting)
|
|
22
|
+
│ ├── stripe/
|
|
23
|
+
│ │ ├── _stripe__sources.yml
|
|
24
|
+
│ │ ├── _stripe__models.yml
|
|
25
|
+
│ │ └── stg_stripe__payments.sql
|
|
26
|
+
├── intermediate/ # Business logic joins & window aggregations
|
|
27
|
+
│ └── finance/
|
|
28
|
+
│ ├── _int_finance__models.yml
|
|
29
|
+
│ └── int_payments_pivoted_to_orders.sql
|
|
30
|
+
└── marts/ # Dimensional star schema (facts & dimensions)
|
|
31
|
+
├── core/
|
|
32
|
+
│ ├── fct_orders.sql
|
|
33
|
+
│ └── dim_customers.sql
|
|
34
|
+
└── marketing/
|
|
35
|
+
└── fct_campaign_conversions.sql
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
### 2. Staging Layer Model with CTE Standards
|
|
41
|
+
|
|
42
|
+
Clean raw source tables into normalized relational types:
|
|
43
|
+
|
|
44
|
+
```sql
|
|
45
|
+
-- models/staging/stripe/stg_stripe__payments.sql
|
|
46
|
+
with source as (
|
|
47
|
+
select * from {{ source('stripe', 'payment') }}
|
|
48
|
+
),
|
|
49
|
+
|
|
50
|
+
renamed as (
|
|
51
|
+
select
|
|
52
|
+
id as payment_id,
|
|
53
|
+
orderid as order_id,
|
|
54
|
+
paymentmethod as payment_method,
|
|
55
|
+
status as payment_status,
|
|
56
|
+
-- Amount stored in cents; convert to dollars
|
|
57
|
+
round(amount / 100.0, 2) as amount_usd,
|
|
58
|
+
created as created_at
|
|
59
|
+
from source
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
select * from renamed
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Declare tests and column descriptions in accompanying YAML:
|
|
66
|
+
|
|
67
|
+
```yaml
|
|
68
|
+
# models/staging/stripe/_stripe__models.yml
|
|
69
|
+
version: 2
|
|
70
|
+
|
|
71
|
+
models:
|
|
72
|
+
- name: stg_stripe__payments
|
|
73
|
+
description: "Normalized payments table from Stripe webhook ingest."
|
|
74
|
+
columns:
|
|
75
|
+
- name: payment_id
|
|
76
|
+
description: "Primary key for payment events."
|
|
77
|
+
tests:
|
|
78
|
+
- unique
|
|
79
|
+
- not_null
|
|
80
|
+
- name: payment_status
|
|
81
|
+
tests:
|
|
82
|
+
- accepted_values:
|
|
83
|
+
values: ['success', 'fail', 'pending']
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
### 3. High-Performance Incremental Fact Table
|
|
89
|
+
|
|
90
|
+
Process only newly ingested or updated records using `is_incremental()`:
|
|
91
|
+
|
|
92
|
+
```sql
|
|
93
|
+
-- models/marts/core/fct_orders.sql
|
|
94
|
+
{{
|
|
95
|
+
config(
|
|
96
|
+
materialized='incremental',
|
|
97
|
+
unique_key='order_id',
|
|
98
|
+
incremental_strategy='merge',
|
|
99
|
+
on_schema_change='fail'
|
|
100
|
+
)
|
|
101
|
+
}}
|
|
102
|
+
|
|
103
|
+
with orders as (
|
|
104
|
+
select * from {{ ref('stg_jaffle_shop__orders') }}
|
|
105
|
+
{% if is_incremental() %}
|
|
106
|
+
-- Only query rows created or modified in the last 3 days for backfill resilience
|
|
107
|
+
where order_date >= (select dateadd('day', -3, max(order_date)) from {{ this }})
|
|
108
|
+
{% endif %}
|
|
109
|
+
),
|
|
110
|
+
|
|
111
|
+
payments as (
|
|
112
|
+
select * from {{ ref('stg_stripe__payments') }}
|
|
113
|
+
),
|
|
114
|
+
|
|
115
|
+
order_payments as (
|
|
116
|
+
select
|
|
117
|
+
order_id,
|
|
118
|
+
sum(case when payment_status = 'success' then amount_usd else 0 end) as amount_usd
|
|
119
|
+
from payments
|
|
120
|
+
group by 1
|
|
121
|
+
),
|
|
122
|
+
|
|
123
|
+
final as (
|
|
124
|
+
select
|
|
125
|
+
orders.order_id,
|
|
126
|
+
orders.customer_id,
|
|
127
|
+
orders.order_date,
|
|
128
|
+
orders.status as order_status,
|
|
129
|
+
coalesce(order_payments.amount_usd, 0) as total_amount_usd
|
|
130
|
+
from orders
|
|
131
|
+
left join order_payments on orders.order_id = order_payments.order_id
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
select * from final
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
### 4. Custom Jinja Macro for Dynamic Pivoting
|
|
140
|
+
|
|
141
|
+
Avoid repetitive boilerplate using parameterized Jinja macros:
|
|
142
|
+
|
|
143
|
+
```sql
|
|
144
|
+
-- macros/pivot_sum.sql
|
|
145
|
+
{% macro pivot_sum(column_name, values_list, aggregate_col='amount_usd') %}
|
|
146
|
+
{% for val in values_list %}
|
|
147
|
+
sum(case when {{ column_name }} = '{{ val }}' then {{ aggregate_col }} else 0 end) as {{ val }}_amount
|
|
148
|
+
{% if not loop.last %},{% endif %}
|
|
149
|
+
{% endfor %}
|
|
150
|
+
{% endmacro %}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Usage in intermediate model:
|
|
154
|
+
|
|
155
|
+
```sql
|
|
156
|
+
select
|
|
157
|
+
order_id,
|
|
158
|
+
{{ pivot_sum('payment_method', ['credit_card', 'coupon', 'bank_transfer', 'gift_card']) }}
|
|
159
|
+
from {{ ref('stg_stripe__payments') }}
|
|
160
|
+
group by 1
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## 🎯 Verification & Diagnostics
|
|
166
|
+
|
|
167
|
+
1. **Compile SQL with Resolved Jinja**:
|
|
168
|
+
```bash
|
|
169
|
+
dbt compile --select fct_orders
|
|
170
|
+
```
|
|
171
|
+
2. **Execute Targeted Subgraph**:
|
|
172
|
+
```bash
|
|
173
|
+
dbt run --select +fct_orders # Run fct_orders and all upstream dependencies
|
|
174
|
+
dbt test --select stg_stripe+ # Test staging models and downstream marts
|
|
175
|
+
```
|
|
176
|
+
3. **Build Documentation & DAG Visualizer**:
|
|
177
|
+
```bash
|
|
178
|
+
dbt docs generate && dbt docs serve
|
|
179
|
+
```
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: debezium-cdc
|
|
3
|
+
description: >-
|
|
4
|
+
Change Data Capture (CDC) streaming architectures using Debezium, PostgreSQL logical decoding (pgoutput), MySQL binlog replication, Kafka Connect, and transactional outbox patterns. Use when capturing real-time database mutations, synchronizing search indices, or avoiding dual-write race conditions.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Debezium Change Data Capture (CDC) Architecture
|
|
8
|
+
|
|
9
|
+
A production runbook for implementing distributed **Change Data Capture (CDC)** pipelines using Debezium, PostgreSQL/MySQL WAL replication, Kafka Connect, and event-driven data streaming.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 🎯 Core Architectural Principles
|
|
14
|
+
|
|
15
|
+
1. **Log-Based CDC Over Polling**: Reads write-ahead logs (WAL / binlog) directly at the storage engine level, incurring minimal CPU overhead and zero query locks on primary tables.
|
|
16
|
+
2. **Transactional Outbox Pattern**: Guarantees atomic database operations and event emission within a single ACID transaction without two-phase commit (2PC) or dual-write inconsistencies.
|
|
17
|
+
3. **Strict Ordering Guarantees**: Partitioning by primary key ensures sequential ordering per record entity across consumer groups.
|
|
18
|
+
4. **Idempotent Consumers**: Design downstream event processors with upsert semantics and revision monotonic version checks.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 🏗️ Debezium PostgreSQL Connector Configuration
|
|
23
|
+
|
|
24
|
+
### 1. Database Prerequisite (`postgresql.conf`)
|
|
25
|
+
|
|
26
|
+
```ini
|
|
27
|
+
# Enable logical replication
|
|
28
|
+
wal_level = logical
|
|
29
|
+
max_wal_senders = 10
|
|
30
|
+
max_replication_slots = 10
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Kafka Connect Connector Payload (`debezium-postgres.json`)
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"name": "postgres-order-cdc",
|
|
38
|
+
"config": {
|
|
39
|
+
"connector.class": "io.debezium.connector.postgresql.PostgresConnector",
|
|
40
|
+
"tasks.max": "1",
|
|
41
|
+
"plugin.name": "pgoutput",
|
|
42
|
+
"database.hostname": "postgres.internal",
|
|
43
|
+
"database.port": "5432",
|
|
44
|
+
"database.user": "debezium_cdc",
|
|
45
|
+
"database.password": "${file:/secrets/db-credentials.properties:password}",
|
|
46
|
+
"database.dbname": "production_app",
|
|
47
|
+
"database.server.name": "prod_cdc",
|
|
48
|
+
"table.include.list": "public.orders,public.outbox_events",
|
|
49
|
+
"slot.name": "debezium_orders_slot",
|
|
50
|
+
"publication.name": "dbz_orders_pub",
|
|
51
|
+
"publication.autocreate.mode": "filtered",
|
|
52
|
+
"decimal.handling.mode": "double",
|
|
53
|
+
"tombstones.on.delete": "true",
|
|
54
|
+
"heartbeat.interval.ms": "5000"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Deploy to Kafka Connect cluster via REST API:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" \
|
|
63
|
+
http://kafka-connect.internal:8083/connectors/ \
|
|
64
|
+
-d @debezium-postgres.json
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## 📦 Transactional Outbox Pattern Implementation
|
|
70
|
+
|
|
71
|
+
### Step 1: Outbox Event Table Schema
|
|
72
|
+
|
|
73
|
+
```sql
|
|
74
|
+
CREATE TABLE outbox_events (
|
|
75
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
76
|
+
aggregate_type VARCHAR(64) NOT NULL,
|
|
77
|
+
aggregate_id VARCHAR(64) NOT NULL,
|
|
78
|
+
event_type VARCHAR(64) NOT NULL,
|
|
79
|
+
payload JSONB NOT NULL,
|
|
80
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
-- Index for optional periodic cleanup
|
|
84
|
+
CREATE INDEX idx_outbox_created_at ON outbox_events (created_at);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Step 2: Atomic Business Transaction (TypeScript / Node.js)
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { PoolClient } from 'pg';
|
|
91
|
+
|
|
92
|
+
interface OrderEvent {
|
|
93
|
+
orderId: string;
|
|
94
|
+
userId: string;
|
|
95
|
+
totalCents: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function createOrderWithOutbox(client: PoolClient, event: OrderEvent): Promise<void> {
|
|
99
|
+
try {
|
|
100
|
+
await client.query('BEGIN');
|
|
101
|
+
|
|
102
|
+
// 1. Mutate primary business state
|
|
103
|
+
const orderSql = `
|
|
104
|
+
INSERT INTO orders (id, user_id, total_cents, status)
|
|
105
|
+
VALUES ($1, $2, $3, 'CREATED')
|
|
106
|
+
`;
|
|
107
|
+
await client.query(orderSql, [event.orderId, event.userId, event.totalCents]);
|
|
108
|
+
|
|
109
|
+
// 2. Append event to outbox within same transaction
|
|
110
|
+
const outboxSql = `
|
|
111
|
+
INSERT INTO outbox_events (aggregate_type, aggregate_id, event_type, payload)
|
|
112
|
+
VALUES ('Order', $1, 'OrderCreated', $2)
|
|
113
|
+
`;
|
|
114
|
+
await client.query(outboxSql, [event.orderId, JSON.stringify(event)]);
|
|
115
|
+
|
|
116
|
+
await client.query('COMMIT');
|
|
117
|
+
} catch (error) {
|
|
118
|
+
await client.query('ROLLBACK');
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 🔄 Debezium Event Payload Structure
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"before": null,
|
|
131
|
+
"after": {
|
|
132
|
+
"id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
|
|
133
|
+
"user_id": "usr_98231",
|
|
134
|
+
"total_cents": 12500,
|
|
135
|
+
"status": "CREATED"
|
|
136
|
+
},
|
|
137
|
+
"source": {
|
|
138
|
+
"version": "2.5.0.Final",
|
|
139
|
+
"connector": "postgresql",
|
|
140
|
+
"name": "prod_cdc",
|
|
141
|
+
"ts_ms": 1718000000000,
|
|
142
|
+
"snapshot": "false",
|
|
143
|
+
"db": "production_app",
|
|
144
|
+
"schema": "public",
|
|
145
|
+
"table": "orders",
|
|
146
|
+
"txId": 984120,
|
|
147
|
+
"lsn": 104857600
|
|
148
|
+
},
|
|
149
|
+
"op": "c",
|
|
150
|
+
"ts_ms": 1718000000100
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
* `op`: `"c"` (create), `"u"` (update), `"d"` (delete), `"r"` (snapshot read).
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## 🛡️ Production Failure Modes & Operational Checklist
|
|
159
|
+
|
|
160
|
+
1. **Replication Slot Disk Exhaustion**:
|
|
161
|
+
- *Risk*: If Kafka Connect crashes, Postgres retains WAL logs indefinitely, filling disk.
|
|
162
|
+
- *Mitigation*: Set `max_slot_wal_keep_size = 50GB` in `postgresql.conf` to protect database uptime.
|
|
163
|
+
2. **Heartbeat Tuning**:
|
|
164
|
+
- Always configure `heartbeat.interval.ms` (e.g. 5000ms) to ensure LSN progression even during low-traffic periods.
|
|
165
|
+
3. **Schema Evolution Handling**:
|
|
166
|
+
- Use Schema Registry (Avro or Protobuf) with `BACKWARD` or `FULL` compatibility to avoid downstream deserialization failures.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: docker-compose-orchestrator
|
|
3
|
+
description: Architects, configures, and troubleshoots multi-container Docker Compose environments, database services (Postgres, pgvector, Redis), healthchecks, and local dev networking.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Docker Compose Multi-Service Orchestrator
|
|
7
|
+
|
|
8
|
+
This skill guides the design, hardening, and troubleshooting of multi-container local and staging environments using Docker Compose v2.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 1. Core Principles
|
|
13
|
+
|
|
14
|
+
1. **Deterministic Healthchecks**:
|
|
15
|
+
- Always define explicit `healthcheck` blocks for stateful services (databases, caches, message brokers).
|
|
16
|
+
- Use `depends_on: { condition: service_healthy }` to prevent app containers from starting before databases are ready.
|
|
17
|
+
2. **Persistent Named Volumes**:
|
|
18
|
+
- Store persistent data (e.g., PostgreSQL data, Redis dumps, uploaded media) in named volumes, never in ephemeral container layers.
|
|
19
|
+
3. **Environment Isolation**:
|
|
20
|
+
- Use `.env.example` templates with sensible local defaults; never hardcode production secrets in compose files.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 2. Production-Grade Compose Blueprint
|
|
25
|
+
|
|
26
|
+
Example architecture pairing an application server with PostgreSQL (pgvector enabled) and Redis caching:
|
|
27
|
+
|
|
28
|
+
```yaml
|
|
29
|
+
version: '3.8'
|
|
30
|
+
|
|
31
|
+
services:
|
|
32
|
+
db:
|
|
33
|
+
image: pgvector/pgvector:pg16
|
|
34
|
+
container_name: app_db
|
|
35
|
+
environment:
|
|
36
|
+
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
|
37
|
+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
|
|
38
|
+
POSTGRES_DB: ${POSTGRES_DB:-app_dev}
|
|
39
|
+
ports:
|
|
40
|
+
- "5432:5432"
|
|
41
|
+
volumes:
|
|
42
|
+
- pgdata:/var/lib/postgresql/data
|
|
43
|
+
healthcheck:
|
|
44
|
+
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
45
|
+
interval: 5s
|
|
46
|
+
timeout: 5s
|
|
47
|
+
retries: 5
|
|
48
|
+
networks:
|
|
49
|
+
- app-net
|
|
50
|
+
|
|
51
|
+
redis:
|
|
52
|
+
image: redis:7-alpine
|
|
53
|
+
container_name: app_redis
|
|
54
|
+
ports:
|
|
55
|
+
- "6379:6379"
|
|
56
|
+
volumes:
|
|
57
|
+
- redisdata:/data
|
|
58
|
+
healthcheck:
|
|
59
|
+
test: ["CMD", "redis-cli", "ping"]
|
|
60
|
+
interval: 5s
|
|
61
|
+
timeout: 3s
|
|
62
|
+
retries: 5
|
|
63
|
+
networks:
|
|
64
|
+
- app-net
|
|
65
|
+
|
|
66
|
+
volumes:
|
|
67
|
+
pgdata:
|
|
68
|
+
redisdata:
|
|
69
|
+
|
|
70
|
+
networks:
|
|
71
|
+
app-net:
|
|
72
|
+
driver: bridge
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 3. Common Operations & Diagnostics
|
|
78
|
+
|
|
79
|
+
| Command | Action |
|
|
80
|
+
| :--- | :--- |
|
|
81
|
+
| `docker compose up -d` | Start all services in the background |
|
|
82
|
+
| `docker compose ps` | Inspect service health and exposed ports |
|
|
83
|
+
| `docker compose logs -f <service>` | Stream logs for a specific container |
|
|
84
|
+
| `docker compose down -v` | Tear down containers and wipe persistent volumes |
|
|
85
|
+
| `docker compose exec <service> sh` | Open an interactive shell inside a container |
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: duckdb-local-olap
|
|
3
|
+
description: >-
|
|
4
|
+
Architects, queries, and optimizes embedded in-process DuckDB analytical workflows, direct Parquet/S3 querying, zero-copy Apache Arrow dataframes, and MotherDuck hybrid cloud execution.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# DuckDB Local OLAP & Serverless Analytics
|
|
8
|
+
|
|
9
|
+
This skill guides building high-speed analytical engines using DuckDB—the "SQLite for analytics"—enabling columnar vectorized execution, direct querying of compressed Parquet files on cloud storage, and zero-copy transfers with Apache Arrow.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## ⚡ Core Patterns
|
|
14
|
+
|
|
15
|
+
### 1. Direct Parquet Querying Over S3 Without Ingestion
|
|
16
|
+
|
|
17
|
+
Query gigabytes of remote compressed files with projection and predicate pushdowns (only requested byte ranges are transferred over the network):
|
|
18
|
+
|
|
19
|
+
```sql
|
|
20
|
+
-- 1. Install and load HTTP and S3 extensions
|
|
21
|
+
INSTALL httpfs;
|
|
22
|
+
LOAD httpfs;
|
|
23
|
+
|
|
24
|
+
-- 2. Configure S3 authentication
|
|
25
|
+
SET s3_region = 'us-east-1';
|
|
26
|
+
SET s3_access_key_id = 'YOUR_ACCESS_KEY';
|
|
27
|
+
SET s3_secret_access_key = 'YOUR_SECRET_KEY';
|
|
28
|
+
|
|
29
|
+
-- 3. Query remote Parquet directory with globs
|
|
30
|
+
SELECT
|
|
31
|
+
country,
|
|
32
|
+
count(*) AS total_transactions,
|
|
33
|
+
round(avg(amount_usd), 2) AS avg_amount,
|
|
34
|
+
quantile_cont(amount_usd, 0.95) AS p95_amount
|
|
35
|
+
FROM read_parquet('s3://my-data-lake/transactions/year=2026/month=*/*.parquet')
|
|
36
|
+
WHERE status = 'settled'
|
|
37
|
+
GROUP BY country
|
|
38
|
+
ORDER BY total_transactions DESC
|
|
39
|
+
LIMIT 20;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
### 2. Zero-Copy Python & Polars / Arrow Integration
|
|
45
|
+
|
|
46
|
+
Pass memory buffers directly between DuckDB's vectorized engine and Polars or PyArrow without JSON or IPC serialization:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import duckdb
|
|
50
|
+
import polars as pl
|
|
51
|
+
|
|
52
|
+
# Connect to in-memory instance
|
|
53
|
+
con = duckdb.connect()
|
|
54
|
+
|
|
55
|
+
# Set aggressive memory limits and worker threads
|
|
56
|
+
con.execute("SET memory_limit = '8GB';")
|
|
57
|
+
con.execute("SET threads = 8;")
|
|
58
|
+
|
|
59
|
+
# Create a sample Polars DataFrame
|
|
60
|
+
df = pl.DataFrame({
|
|
61
|
+
"user_id": [101, 102, 103],
|
|
62
|
+
"scores": [98.5, 76.2, 89.0]
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
# Query Polars DataFrame directly as a virtual table (zero-copy)
|
|
66
|
+
arrow_table = con.execute("""
|
|
67
|
+
SELECT
|
|
68
|
+
user_id,
|
|
69
|
+
scores,
|
|
70
|
+
CASE WHEN scores >= 90 THEN 'A' ELSE 'B' END AS grade
|
|
71
|
+
FROM df
|
|
72
|
+
WHERE scores > 80
|
|
73
|
+
""").arrow()
|
|
74
|
+
|
|
75
|
+
# Convert back to Polars instantaneously
|
|
76
|
+
result_df = pl.from_arrow(arrow_table)
|
|
77
|
+
print(result_df)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
### 3. Node.js Embedded Analytics Engine
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { Database } from 'duckdb-async';
|
|
86
|
+
|
|
87
|
+
export async function aggregateLocalParquet(parquetPath: string) {
|
|
88
|
+
const db = await Database.create(':memory:');
|
|
89
|
+
|
|
90
|
+
const rows = await db.all(`
|
|
91
|
+
SELECT
|
|
92
|
+
category,
|
|
93
|
+
count(*) AS item_count,
|
|
94
|
+
sum(price) AS gross_revenue
|
|
95
|
+
FROM read_parquet(?)
|
|
96
|
+
GROUP BY category
|
|
97
|
+
ORDER BY gross_revenue DESC
|
|
98
|
+
`, [parquetPath]);
|
|
99
|
+
|
|
100
|
+
await db.close();
|
|
101
|
+
return rows;
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
### 4. MotherDuck Cloud Hybrid Execution
|
|
108
|
+
|
|
109
|
+
Scale seamlessly from a single laptop to collaborative cloud storage without modifying SQL queries:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
import duckdb
|
|
113
|
+
|
|
114
|
+
# Connect to MotherDuck (cloud database)
|
|
115
|
+
con = duckdb.connect("md:production_analytics")
|
|
116
|
+
|
|
117
|
+
# Join local disk Parquet files directly with MotherDuck cloud tables
|
|
118
|
+
con.execute("""
|
|
119
|
+
SELECT
|
|
120
|
+
cloud_users.organization_id,
|
|
121
|
+
count(local_events.event_id) AS event_volume
|
|
122
|
+
FROM read_parquet('./local_cache/*.parquet') AS local_events
|
|
123
|
+
JOIN cloud_users ON local_events.user_id = cloud_users.id
|
|
124
|
+
GROUP BY cloud_users.organization_id
|
|
125
|
+
""")
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## 🛠️ Performance Checklist
|
|
131
|
+
|
|
132
|
+
- **Use Parquet Over CSV**: Parquet is 10x-50x faster due to columnar compression, statistics dictionaries, and column skipping.
|
|
133
|
+
- **Configure Memory Limit**: Always set `SET memory_limit = 'XGB';` to ensure DuckDB uses external sorting/joining when data exceeds RAM instead of crashing the process.
|
|
134
|
+
- **Avoid Row-by-Row Inserts**: Use `Appender` or `COPY ... FROM ...` in bulk batches of 50,000+ rows.
|