[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7F3C14CGAGSB0DVTXPM6DB5":3,"skill-same:01M7F3C14CGAGSB0DVTXPM6DB5":45},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":29,"updatedAt":30,"install":31,"resources":44},"01M7F3C14CGAGSB0DVTXPM6DB5","backend-database-and-orm",null,"Guides backend database design, ORM patterns, zero-downtime migrations, and query performance tailored specifically for Neon (Serverless Postgres) and Firebase (Firestore \u002F Auth \u002F Rules). Use when modeling database schemas, writing ORM code, setting up database migrations, optimizing SQL\u002FFirestore queries, or configuring connection pooling.","26BB\u002Fagent-fleet-os","26BB","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F113676969?v=4","01M7F3AVX9MTTAHCYTANRGEE52","Bhushan Vijay Bhosale","01M7F3AVY15DJBX1CE4H25P52T",0,"MIT","https:\u002F\u002Fgithub.com\u002F26BB\u002Fagent-fleet-os\u002Fblob\u002Fmain\u002FEngg Agent\u002Fplaybooks\u002Fbackend-database-and-orm\u002FSKILL.md",[],[],"2026-11-16 10:05:34",false,"---\nname: backend-database-and-orm\ndescription: Guides backend database design, ORM patterns, zero-downtime migrations, and query performance tailored specifically for Neon (Serverless Postgres) and Firebase (Firestore \u002F Auth \u002F Rules). Use when modeling database schemas, writing ORM code, setting up database migrations, optimizing SQL\u002FFirestore queries, or configuring connection pooling.\n---\n\n# Backend Database & ORM Engineering\n\n## Overview\n\nHigh-performance, scalable backend database design focusing on **Neon (Serverless Postgres)** and **Firebase (Firestore, Security Rules, Admin SDK)**. Enforces clean data modeling, zero-downtime schema evolution, N+1 query prevention, and safe connection pooling across serverless and stateful environments.\n\n---\n\n## When to Use\n\n- Designing or modifying database schemas (SQL table structures, Firestore collections)\n- Writing database queries or using ORMs (Drizzle ORM, Prisma, TypeORM)\n- Configuring Neon database connections, WebSocket pooling, or database branching\n- Implementing Firebase Firestore queries, Security Rules, or Cloud Functions backend logic\n- Executing database migrations in staging or production environments\n- Diagnosing database query performance bottlenecks, slow queries, or missing indexes\n\n---\n\n## Pillar 1: Neon (Serverless PostgreSQL)\n\nNeon is a serverless Postgres platform with decoupled compute and storage, instant database branching, and HTTP\u002FWebSocket proxies for serverless environments.\n\n### 1. Connection Management & Driver Selection\n- **Serverless Environments (Vercel, AWS Lambda, Cloudflare Workers):** Use `@neondatabase\u002Fserverless` over WebSockets \u002F HTTP proxy to avoid connection exhaustion.\n  ```typescript\n  import { Pool, neonConfig } from '@neondatabase\u002Fserverless';\n  import ws from 'ws';\n  neonConfig.webSocketConstructor = ws;\n  \n  const pool = new Pool({ connectionString: process.env.DATABASE_URL });\n  ```\n- **Stateful Long-Running Servers (Node.js \u002F Express):** Use standard PostgreSQL connection poolers (e.g. `pg.Pool`) with Neon's pooled connection string (`-pooler` suffix).\n\n### 2. ORM Patterns (Drizzle ORM & Prisma with Neon)\n- **Drizzle ORM (Recommended for Light Overhead & Explicit SQL):**\n  - Always explicit select fields instead of returning `SELECT *`.\n  - Use relational queries `db.query.users.findMany(...)` for structured tree fetches.\n- **Prisma with Neon:**\n  - Enable `@prisma\u002Fadapter-neon` driver adapter when running in serverless contexts.\n  - Avoid deeply nested `include` statements that cause wide SQL joins; use explicit `select` payloads.\n\n### 3. Neon Branching Workflow for DB Migrations\n- Use Neon's instant copy-on-write branching for dev & staging test environments:\n  1. Branch main database: `neon branches create --name feature-branch`\n  2. Run migrations against `feature-branch`\n  3. Verify application queries against `feature-branch`\n  4. Apply approved migration to `main`\n\n---\n\n## Pillar 2: Firebase (Firestore, Rules & Functions)\n\nFirebase provides document-based Firestore, real-time sync, identity management, and serverless Cloud Functions.\n\n### 1. Data Modeling & Firestore Layout\n- **Normalized vs Denormalized:** Firestore charges per document read\u002Fwrite. Prefer denormalizing frequently accessed sub-fields (e.g. `authorName` stored inside `posts` document) to avoid secondary fetches.\n- **Collection Structures:**\n  - Subcollections for tightly bound sub-resources (`users\u002F{userId}\u002Forders\u002F{orderId}`).\n  - Root collections with indexed reference IDs (`orders` with `userId` field) when cross-user queries are required.\n\n### 2. Firestore Security Rules & Access Control\n- Never rely solely on client-side checks. Every collection must have explicit `firestore.rules`.\n- Enforce strict data validation & auth checking:\n  ```cel\n  match \u002Fusers\u002F{userId} {\n    allow read, write: if request.auth != null && request.auth.uid == userId;\n  }\n  match \u002Fposts\u002F{postId} {\n    allow read: if resource.data.isPublic == true;\n    allow create: if request.auth != null && request.resource.data.authorId == request.auth.uid;\n  }\n  ```\n\n### 3. Query Optimization & Indexing\n- **Composite Indexes:** Any query combining filtering (`where`) with sorting (`orderBy`) across multiple fields requires a composite index in `firestore.indexes.json`.\n- **Pagination:** Always use `limit()` combined with `startAfter(lastDoc)` for collection pagination. Never fetch entire collections into memory.\n\n---\n\n## Pillar 3: Zero-Downtime Migration Pattern (Expand-Contract)\n\nWhen changing database schemas in production (especially on Neon Postgres or Firestore schemas), **NEVER** drop or rename fields in a single breaking deploy. Use the **Expand-Contract (Parallel Write)** pattern:\n\n```\nPhase 1: Expand      ---> Phase 2: Dual Write  ---> Phase 3: Backfill  ---> Phase 4: Contract\n(Add new col\u002Ffield)       (Write to old & new)      (Migrate old rows)      (Remove old col\u002Ffield)\n```\n\n1. **Expand (Deploy 1):** Add the new column\u002Ffield as optional (`NULLable` in SQL, optional in Firestore). Existing code continues using the old field.\n2. **Dual Write (Deploy 2):** Update backend code to write to BOTH old and new fields simultaneously. Read from old field if new field is missing.\n3. **Backfill Script:** Run an async background script to update existing rows\u002Fdocuments to populate the new field.\n4. **Read Switch (Deploy 3):** Switch read logic to strictly read from the new field.\n5. **Contract (Deploy 4):** Remove writes to the old field, drop the old column\u002Ffield.\n\n---\n\n## Pillar 4: Query Performance & Quality Checklist\n\n- [ ] **N+1 Prevention:** Are multi-row queries fetching relations in a single join \u002F single batch query instead of looping async calls?\n- [ ] **Indexing:** Are all `WHERE`, `JOIN`, and `ORDER BY` columns in Postgres covered by B-Tree or GIN indexes? Are Firestore composite queries defined in `firestore.indexes.json`?\n- [ ] **Transaction Boundaries:** Are multi-statement updates wrapped in explicit SQL transactions (`db.transaction(...)`) or Firestore Batched Writes \u002F Transactions?\n- [ ] **Connection Leak Prevention:** Are SQL connection pools cleanly shut down on process termination (`SIGTERM`)?\n","# Backend Database & ORM Engineering\n\n## Overview\n\nHigh-performance, scalable backend database design focusing on **Neon (Serverless Postgres)** and **Firebase (Firestore, Security Rules, Admin SDK)**. Enforces clean data modeling, zero-downtime schema evolution, N+1 query prevention, and safe connection pooling across serverless and stateful environments.\n\n---\n\n## When to Use\n\n- Designing or modifying database schemas (SQL table structures, Firestore collections)\n- Writing database queries or using ORMs (Drizzle ORM, Prisma, TypeORM)\n- Configuring Neon database connections, WebSocket pooling, or database branching\n- Implementing Firebase Firestore queries, Security Rules, or Cloud Functions backend logic\n- Executing database migrations in staging or production environments\n- Diagnosing database query performance bottlenecks, slow queries, or missing indexes\n\n---\n\n## Pillar 1: Neon (Serverless PostgreSQL)\n\nNeon is a serverless Postgres platform with decoupled compute and storage, instant database branching, and HTTP\u002FWebSocket proxies for serverless environments.\n\n### 1. Connection Management & Driver Selection\n- **Serverless Environments (Vercel, AWS Lambda, Cloudflare Workers):** Use `@neondatabase\u002Fserverless` over WebSockets \u002F HTTP proxy to avoid connection exhaustion.\n  ```typescript\n  import { Pool, neonConfig } from '@neondatabase\u002Fserverless';\n  import ws from 'ws';\n  neonConfig.webSocketConstructor = ws;\n  \n  const pool = new Pool({ connectionString: process.env.DATABASE_URL });\n  ```\n- **Stateful Long-Running Servers (Node.js \u002F Express):** Use standard PostgreSQL connection poolers (e.g. `pg.Pool`) with Neon's pooled connection string (`-pooler` suffix).\n\n### 2. ORM Patterns (Drizzle ORM & Prisma with Neon)\n- **Drizzle ORM (Recommended for Light Overhead & Explicit SQL):**\n  - Always explicit select fields instead of returning `SELECT *`.\n  - Use relational queries `db.query.users.findMany(...)` for structured tree fetches.\n- **Prisma with Neon:**\n  - Enable `@prisma\u002Fadapter-neon` driver adapter when running in serverless contexts.\n  - Avoid deeply nested `include` statements that cause wide SQL joins; use explicit `select` payloads.\n\n### 3. Neon Branching Workflow for DB Migrations\n- Use Neon's instant copy-on-write branching for dev & staging test environments:\n  1. Branch main database: `neon branches create --name feature-branch`\n  2. Run migrations against `feature-branch`\n  3. Verify application queries against `feature-branch`\n  4. Apply approved migration to `main`\n\n---\n\n## Pillar 2: Firebase (Firestore, Rules & Functions)\n\nFirebase provides document-based Firestore, real-time sync, identity management, and serverless Cloud Functions.\n\n### 1. Data Modeling & Firestore Layout\n- **Normalized vs Denormalized:** Firestore charges per document read\u002Fwrite. Prefer denormalizing frequently accessed sub-fields (e.g. `authorName` stored inside `posts` document) to avoid secondary fetches.\n- **Collection Structures:**\n  - Subcollections for tightly bound sub-resources (`users\u002F{userId}\u002Forders\u002F{orderId}`).\n  - Root collections with indexed reference IDs (`orders` with `userId` field) when cross-user queries are required.\n\n### 2. Firestore Security Rules & Access Control\n- Never rely solely on client-side checks. Every collection must have explicit `firestore.rules`.\n- Enforce strict data validation & auth checking:\n  ```cel\n  match \u002Fusers\u002F{userId} {\n    allow read, write: if request.auth != null && request.auth.uid == userId;\n  }\n  match \u002Fposts\u002F{postId} {\n    allow read: if resource.data.isPublic == true;\n    allow create: if request.auth != null && request.resource.data.authorId == request.auth.uid;\n  }\n  ```\n\n### 3. Query Optimization & Indexing\n- **Composite Indexes:** Any query combining filtering (`where`) with sorting (`orderBy`) across multiple fields requires a composite index in `firestore.indexes.json`.\n- **Pagination:** Always use `limit()` combined with `startAfter(lastDoc)` for collection pagination. Never fetch entire collections into memory.\n\n---\n\n## Pillar 3: Zero-Downtime Migration Pattern (Expand-Contract)\n\nWhen changing database schemas in production (especially on Neon Postgres or Firestore schemas), **NEVER** drop or rename fields in a single breaking deploy. Use the **Expand-Contract (Parallel Write)** pattern:\n\n```\nPhase 1: Expand      ---> Phase 2: Dual Write  ---> Phase 3: Backfill  ---> Phase 4: Contract\n(Add new col\u002Ffield)       (Write to old & new)      (Migrate old rows)      (Remove old col\u002Ffield)\n```\n\n1. **Expand (Deploy 1):** Add the new column\u002Ffield as optional (`NULLable` in SQL, optional in Firestore). Existing code continues using the old field.\n2. **Dual Write (Deploy 2):** Update backend code to write to BOTH old and new fields simultaneously. Read from old field if new field is missing.\n3. **Backfill Script:** Run an async background script to update existing rows\u002Fdocuments to populate the new field.\n4. **Read Switch (Deploy 3):** Switch read logic to strictly read from the new field.\n5. **Contract (Deploy 4):** Remove writes to the old field, drop the old column\u002Ffield.\n\n---\n\n## Pillar 4: Query Performance & Quality Checklist\n\n- [ ] **N+1 Prevention:** Are multi-row queries fetching relations in a single join \u002F single batch query instead of looping async calls?\n- [ ] **Indexing:** Are all `WHERE`, `JOIN`, and `ORDER BY` columns in Postgres covered by B-Tree or GIN indexes? Are Firestore composite queries defined in `firestore.indexes.json`?\n- [ ] **Transaction Boundaries:** Are multi-statement updates wrapped in explicit SQL transactions (`db.transaction(...)`) or Firestore Batched Writes \u002F Transactions?\n- [ ] **Connection Leak Prevention:** Are SQL connection pools cleanly shut down on process termination (`SIGTERM`)?\n",{"name":5,"description":7},"main","98985c16dc8df1bbd7dcd1bc698cd997a093e751","Engg Agent\u002Fplaybooks\u002Fbackend-database-and-orm","https:\u002F\u002Fgithub.com\u002F26BB\u002Fagent-fleet-os","https:\u002F\u002Fgithub.com\u002F26BB","🚀 Aspiring Product Manager | CS @ GS Moze\r\n\r\n🛠️ Building 0→1 products across SaaS & clean-tech\r\n\r\n📊 Turning user feedback & data into shipped features","2026-11-05 13:34:38",{"source":8,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add 26BB\u002Fagent-fleet-os --skill backend-database-and-orm",{"tool":37,"command":38},"bunx","bunx skills add 26BB\u002Fagent-fleet-os --skill backend-database-and-orm",{"tool":40,"command":41},"pnpm","pnpm dlx skills add 26BB\u002Fagent-fleet-os --skill backend-database-and-orm","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002F26BB\u002Fagent-fleet-os\u002Fblob\u002Fmain\u002FEngg Agent\u002Fplaybooks\u002Fbackend-database-and-orm\u002FSKILL.md",true,[],[46,53,60,67,74,81],{"skillNo":47,"name":48,"nameZh":6,"description":49,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":50,"categories":51,"keywords":52,"publishedAt":19},"01M7F51NQSCRM2PWFMATCV9MEG","taste-design","Semantic Design System Skill for Google Stitch. Generates agent-friendly DESIGN.md files that enforce premium, anti-generic UI standards — strict typography, calibrated color, asymmetric layouts, perpetual micro-motion, and hardware-accelerated performance.","https:\u002F\u002Fgithub.com\u002F26BB\u002Fagent-fleet-os\u002Fblob\u002Fmain\u002Fstitch agent\u002Fplugins\u002Fstitch-utilities\u002Fplaybooks\u002Ftaste-design\u002FSKILL.md",[],[],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":19},"01M7F51JGTS9VJ3S9T6VMQWZ08","stitch-loop","Teaches agents to iteratively build websites using Stitch with an autonomous baton-passing loop pattern","https:\u002F\u002Fgithub.com\u002F26BB\u002Fagent-fleet-os\u002Fblob\u002Fmain\u002Fstitch agent\u002Fplugins\u002Fstitch-utilities\u002Fplaybooks\u002Fstitch-loop\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":19},"01M7F51EZR2XYDWMA3XKWH1HX2","site-md","Analyze a project description or site requirements and synthesize a project constitution into SITE.md for the Stitch Build Loop","https:\u002F\u002Fgithub.com\u002F26BB\u002Fagent-fleet-os\u002Fblob\u002Fmain\u002Fstitch agent\u002Fplugins\u002Fstitch-utilities\u002Fplaybooks\u002Fsite-md\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":19},"01M7F51BNCMP0GQ7SGP39SZYDP","enhance-prompt","Transforms vague UI ideas into polished, Stitch-optimized prompts. Enhances specificity, adds UI\u002FUX keywords, injects design system context, and structures output for better generation results.","https:\u002F\u002Fgithub.com\u002F26BB\u002Fagent-fleet-os\u002Fblob\u002Fmain\u002Fstitch agent\u002Fplugins\u002Fstitch-utilities\u002Fplaybooks\u002Fenhance-prompt\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":19},"01M7F518SX707EB3X42B2V7HRA","design-md","Analyze Stitch projects and synthesize a semantic design system into DESIGN.md files","https:\u002F\u002Fgithub.com\u002F26BB\u002Fagent-fleet-os\u002Fblob\u002Fmain\u002Fstitch agent\u002Fplugins\u002Fstitch-utilities\u002Fplaybooks\u002Fdesign-md\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":19},"01M7F5148PVYTA76NR3X0YK8SK","stitch::upload-to-stitch","Upload local assets (images, mockups, extracted HTML, design markdown) to a Stitch project. ALWAYS use this skill when you need to upload visual assets, HTML pages, or design docs to Stitch, particularly when direct MCP tool calls fail or truncate due to base64 token limits.","https:\u002F\u002Fgithub.com\u002F26BB\u002Fagent-fleet-os\u002Fblob\u002Fmain\u002Fstitch agent\u002Fplugins\u002Fstitch-design\u002Fplaybooks\u002Fupload-to-stitch\u002FSKILL.md",[],[]]