motherduckdb/agent-skills / plugins/motherduck-skills-claude/skills/motherduck-build-cfa-app
motherduck-build-cfa-app
VerifiedBuild MotherDuck analytics into customer-facing applications with tenant isolation, backend routing, and serving APIs.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 5.5 KB |
| artifacts/customer_routing_example.py | script | 2.1 KB |
| artifacts/customer_routing_example.ts | script | 1.9 KB |
| references/CFA_ARCHITECTURE.md | markdown | 20.8 KB |
| references/CFA_IMPLEMENTATION_GUIDE.md | markdown | 21.8 KB |
| references/EXECUTION_REFERENCE.md | markdown | 1.6 KB |
artifacts/customer_routing_example.py
View on GitHubimport json
import sys
from pathlib import Path
import duckdb
sys.path.append(str(Path(__file__).resolve().parents[3]))
from scripts._lib.motherduck_artifact_utils import artifact_session
def fetch_rows(conn: duckdb.DuckDBPyConnection, sql: str) -> list[dict]:
cursor = conn.execute(sql)
columns = [col[0] for col in cursor.description]
return [dict(zip(columns, row)) for row in cursor.fetchall()]
def main() -> None:
with artifact_session(
slug="motherduck-build-cfa-app",
database_keys=["customer_acme", "customer_globex"],
) as session:
conn = session.conn
for db_key, values in {
"customer_acme": [(1, "search", 12.5), (2, "checkout", 18.0)],
"customer_globex": [(1, "signup", 4.0), (2, "invoice_paid", 9.5)],
}.items():
conn.execute(
f"""
CREATE TABLE {session.table(db_key, "main", "analytics_events")} (
event_id INTEGER,
event_type VARCHAR,
revenue DOUBLE
)
"""
)
conn.executemany(
f"INSERT INTO {session.table(db_key, 'main', 'analytics_events')} VALUES (?, ?, ?)",
values,
)
def query_customer(database_key: str) -> list[dict]:
return fetch_rows(
conn,
f"""
SELECT event_type, SUM(revenue) AS total_revenue
FROM {session.table(database_key, "main", "analytics_events")}
GROUP BY 1
ORDER BY total_revenue DESC
""",
)
result = {
"backend": session.describe(),
"pattern": "3-tier customer-facing analytics",
"routing_mode": "per-customer database namespace",
"customers": {
"acme": query_customer("customer_acme"),
"globex": query_customer("customer_globex"),
},
}
print(json.dumps(result, indent=2))
if __name__ == "__main__":
main()
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |