Drizzle ORM

Standardize schema-first Drizzle ORM structure for TypeScript database projects.

1|Updated May 2, 2026
One-click install
npx skills add https://github.com/Levironexe/architect --skill drizzle-orm-levironexe
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Drizzle ORM
Source: https://github.com/Levironexe/architect/tree/main/skills/patterns/drizzle
Command: npx skills add https://github.com/Levironexe/architect --skill drizzle-orm-levironexe

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill solves the problem of fragile, inconsistent database code in TypeScript projects by standardizing how Drizzle schemas, migrations, connections, and queries are organized so refactors stay safe and predictable.

Core Features & Use Cases

  • Schema-first structure: Centralizes all table definitions in src/db/schema.ts as the single source of truth, with inferred types via $inferSelect and $inferInsert.
  • Migration discipline: Uses drizzle-kit (drizzle.config.ts + npx drizzle-kit generate/migrate) to create versioned migration SQL rather than editing migration files manually.
  • Typed query layer & singleton connection: Enforces a single Drizzle instance in src/lib/db.ts and routes all SQL-building through functions in src/db/queries to keep APIs consistent and maintainable.
  • Validation and safety guardrails: Validates inputs at the service boundary (e.g., with Zod) and defines common anti-patterns like multiple DB connections and raw SQL string concatenation.

Quick Start

Ask your AI coding agent to implement Drizzle ORM using a schema-first layout: put all tables and inferred types in src/db/schema.ts, create the singleton connection in src/lib/db.ts, move all queries into src/db/queries/*, and manage schema changes with drizzle-kit migrations.

Frequently Asked Questions about Drizzle ORM

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure a Drizzle ORM codebase to make refactoring safer?

To structure Drizzle ORM for safe refactoring, centralize table definitions in a single schema file, use a singleton database instance, and route all typed queries through dedicated functions to prevent inconsistent runtime behavior.

What is the best way to manage SQL migrations with Drizzle ORM in TypeScript?

The best way to manage SQL migrations with Drizzle ORM is to configure drizzle-kit to generate versioned migration SQL files automatically, avoiding manual edits to migration files to maintain schema discipline.

How do I infer TypeScript types from Drizzle ORM table schemas?

To infer TypeScript types from Drizzle ORM schemas, use the built-in $inferSelect and $inferInsert utilities on your centralized table definitions to generate accurate select and insert types.

Where should I instantiate the database connection when using Drizzle ORM?

When using Drizzle ORM, you should instantiate a single database connection in a dedicated server-safe singleton file like src/lib/db.ts to prevent multiple connections and maintain consistent query execution.

Why should I validate inputs at the service layer with Drizzle ORM queries?

Validating inputs at the service boundary with tools like Zod prevents invalid data from reaching your Drizzle ORM typed queries, defining common guardrails against risky runtime behavior and raw SQL string concatenation.

Can I refactor existing CRUD services to use a schema-first Drizzle ORM architecture?

Yes, you can refactor existing CRUD services to use a schema-first Drizzle ORM architecture by relocating schemas, enforcing a singleton connection, and centralizing query functions to make API routes safe and predictable.