npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

archetype-engine

v2.3.4

Published

Type-safe backend generator for Next.js. Define entities once, get Drizzle schemas, tRPC APIs, Zod validation, and React hooks instantly.

Readme

Archetype Engine

npm version License: MIT

The missing backend layer for AI-generated frontends.

Define entities in TypeScript. Get production-ready backends instantly.

const Product = defineEntity('Product', {
  fields: {
    name: text().required().min(1).max(200),
    price: number().required().positive(),
    stock: number().integer().min(0).default(0),
  }
})

Run npx archetype generate → get:

  • Drizzle ORM schemas (type-safe database)
  • tRPC routers (CRUD + pagination + filters)
  • Zod validation (runtime safety)
  • React hooks (useProduct, useCreateProduct, etc.)
  • Vitest tests (comprehensive test suites)
  • OpenAPI docs (Swagger UI + API docs)
  • Seed data (realistic sample data)

Why use this?

| Tool | What it does | What you still write | |------|--------------|---------------------| | Prisma | Database schema → Types | API, validation, hooks | | tRPC | Type-safe API | Schema, validation, CRUD | | Zod | Validation schemas | Database, API, hooks | | Archetype | Schema → Everything | Business logic only |

You're not replacing tools—you're generating the boilerplate.


Quick Start (2 minutes)

# 1. Create a new Next.js project
npx create-next-app@latest my-app && cd my-app

# 2. Install Archetype
npm install archetype-engine

# 3. Initialize with a template
npx archetype init

# Choose from:
# - SaaS Multi-Tenant (Workspace, Team, Member)
# - E-commerce (Product, Order, Customer)
# - Blog/CMS (Post, Author, Comment)
# - Task Management (Project, Task, Label)

# 4. Generate code
npx archetype generate

# 5. Push to database and run
npx drizzle-kit push
npm run dev

🎉 Done! You now have a fully functional backend with type-safe APIs.


What You Get

From a single entity definition, Archetype generates:

generated/
├── db/
│   └── schema.ts              # Drizzle ORM tables (type-safe SQL)
├── schemas/
│   └── product.ts             # Zod validation schemas
├── trpc/routers/
│   ├── product.ts             # Full CRUD API:
│   │                          #   - list (with pagination, filters, search)
│   │                          #   - get (by ID)
│   │                          #   - create, createMany
│   │                          #   - update, updateMany
│   │                          #   - remove, removeMany
│   └── index.ts               # Router aggregation
├── hooks/
│   └── useProduct.ts          # React Query hooks:
│                              #   - useProducts(), useProduct(id)
│                              #   - useCreateProduct(), useUpdateProduct()
│                              #   - useRemoveProduct(), etc.
├── tests/                     # 🆕 Auto-generated tests
│   ├── product.test.ts        #   - CRUD operation tests
│   └── setup.ts               #   - Validation & auth tests
├── docs/                      # 🆕 Auto-generated API docs
│   ├── openapi.json           #   - OpenAPI 3.0 specification
│   ├── swagger.html           #   - Interactive Swagger UI
│   └── API.md                 #   - Markdown documentation
└── seeds/                     # 🆕 Auto-generated seed data
    ├── product.ts             #   - Realistic sample data
    ├── index.ts               #   - Dependency management
    └── run.ts                 #   - CLI seed script

15 lines of entity code → 1,400+ lines of production-ready backend.

Live Example

Define once:

const Order = defineEntity('Order', {
  fields: {
    orderNumber: text().required().unique(),
    status: enumField('pending', 'paid', 'shipped'),
    total: number().required().positive(),
  },
  relations: {
    customer: hasOne('Customer'),
    items: hasMany('OrderItem'),
  },
  behaviors: {
    timestamps: true,
  },
  protected: 'all',  // Requires authentication
})

Use immediately:

// In your React component
const { data: orders } = useOrders({ 
  where: { status: 'pending' },
  orderBy: { field: 'createdAt', direction: 'desc' }
})

const { mutate: createOrder } = useCreateOrder()
createOrder({ 
  orderNumber: 'ORD-001',
  status: 'pending',
  total: 99.99 
})

No API boilerplate. No manual validation. No CRUD repetition. Just works.


Features

  • 🎯 Type-Safe Everything - Database ↔ API ↔ Frontend sync guaranteed
  • 🚀 Production-Ready Templates - SaaS, E-commerce, Blog, Task Management
  • 🔐 Built-in Auth - NextAuth v5 integration with multiple providers
  • 🔍 Smart Filtering - Pagination, search, sorting out of the box
  • 🪝 Lifecycle Hooks - Add business logic before/after CRUD operations
  • 📊 Auto ERD - Visual database diagrams with npx archetype view
  • 🌍 i18n Ready - Multi-language support for generated code
  • Fast - Generate 1000+ lines of code in seconds
  • 🧪 Auto-Generated Tests - Comprehensive Vitest test suites with validation, auth, and CRUD tests
  • 📖 Auto-Generated Docs - OpenAPI 3.0 specs + interactive Swagger UI
  • 🌱 Auto-Generated Seeds - Realistic sample data with smart field mapping

Use Cases

| Template | Perfect For | Entities Included | |----------|-------------|-------------------| | SaaS Multi-Tenant | Team collaboration apps | Workspace, Team, Member + roles | | E-commerce | Online stores, marketplaces | Product, Customer, Order, OrderItem | | Blog/CMS | Content platforms, news sites | Post, Author, Comment | | Task Management | Todo apps, kanban boards | Project, Task, Label |

Documentation

📚 Full docs: archetype-engine.vercel.app

Popular guides:


Why Archetype?

The Problem: AI Tools Generate Incomplete Backends

Tools like v0.dev, Bolt.new, and Cursor generate beautiful UIs but:

  • ❌ Hardcoded mock data
  • ❌ No database integration
  • ❌ No type safety
  • ❌ No production-ready APIs

You get a gorgeous frontend that doesn't connect to anything real.

The Solution: Archetype Completes the Stack

Archetype generates the missing backend layer:

  • ✅ Real database schemas (Drizzle ORM)
  • ✅ Type-safe APIs (tRPC)
  • ✅ Runtime validation (Zod)
  • ✅ React hooks for data fetching

Use case: Generate UI with v0 → Add backend with Archetype → Deploy to production.


CLI Commands

Archetype provides a suite of commands organized by namespace to avoid conflicts with your Next.js project:

Archetype Commands (Code Generation & Documentation)

npx archetype init                 # Interactive setup with entity templates
npx archetype generate             # Generate all code from entities
npx archetype view                 # View ERD diagram in browser (port 3333)
npx archetype docs                 # View OpenAPI/Swagger UI (port 3334)
npx archetype validate             # Validate manifest without generating

Project Scripts (Added by npx archetype init)

New projects automatically get these npm scripts:

{
  "scripts": {
    // Archetype - Generation & Docs
    "archetype:generate": "archetype generate",
    "archetype:view": "archetype view",
    "archetype:docs": "archetype docs",
    "archetype:check": "archetype validate",
    
    // Database - Schema & Data
    "db:push": "drizzle-kit push",
    "db:studio": "drizzle-kit studio",
    "db:seed": "tsx generated/seeds/run.ts",
    "db:seed:reset": "tsx generated/seeds/run.ts --reset",
    
    // Testing
    "test:api": "vitest run generated/tests"
  }
}

Common Workflows

Initial setup:

npm run archetype:generate   # Generate code
npm run db:push              # Create database schema
npm run db:seed              # Add sample data
npm run dev                  # Start dev server

Development loop:

# Edit archetype/entities/product.ts
npm run archetype:generate   # Regenerate code
npm run db:push              # Update schema
npm run dev                  # Test changes

Documentation & validation:

npm run archetype:view       # View entity relationships
npm run archetype:docs       # Browse API endpoints
npm run archetype:check      # Validate entity definitions

Roadmap

  • [x] Core entity system with relations
  • [x] Pagination, filtering, search
  • [x] Authentication integration (NextAuth v5)
  • [x] CRUD lifecycle hooks
  • [x] Batch operations (createMany, updateMany, removeMany)
  • [x] Computed fields
  • [x] Enum support
  • [x] Test generator (Vitest)
  • [x] API documentation generator (OpenAPI + Swagger)
  • [x] Seed data generator
  • [ ] E2E test generator (Playwright) (Q1 2026)
  • [ ] Admin UI generator (Q1 2026)
  • [ ] Multi-tenancy utilities (Q1 2026)
  • [ ] RBAC/permissions framework (Q2 2026)
  • [ ] GraphQL template (Q2 2026)

Contributing

We welcome contributions! See CONTRIBUTING.md for:

  • Architecture overview
  • Development setup
  • How to add features
  • Testing guidelines

License

MIT - Use freely in commercial and open-source projects.


Support


Built with ❤️ for developers tired of writing boilerplate.