ServerCRUD
Overview
The CRUD engine provides a standardized pipeline for database operations with hooks, validation, and observability.
The CRUD engine is a high-level orchestration layer over Prisma that provides a standardized way to perform database operations across all Prisma models. It ensures consistent handling of cross-cutting concerns like validation, hooks, and observability.
Core Philosophy
- Standardization: Every CRUD operation follows the same execution pipeline
- Extensibility: Hooks can intercept before and after operations
- Type Safety: Full type inference from Prisma models to Hono RPC clients
- Resilience: Built-in retry logic for transient database failures
Key Components
| Component | File | Purpose |
|---|---|---|
CrudService | features/crud/services/crud.service.ts | Main entry point for executing operations |
CrudRepository | features/crud/services/crud-repository.service.ts | Data access layer wrapping Prisma |
CrudHookService | features/crud/services/crud-hook.service.ts | Manages lifecycle hooks |
createCrudRoutes | features/crud/crud.routes.ts | Hono route factory |
OperationPipeline | features/shared/operation-pipeline.ts | Shared execution pipeline |
File Structure
features/crud/
├── crud.routes.ts # Route factory for Hono
├── factory.ts # Hook registration utilities
├── hooks.ts # Global hook registry
├── layers.ts # Effect-TS layer composition
├── services/
│ ├── crud.service.ts # Main service
│ ├── crud-repository.service.ts # Prisma wrapper
│ ├── crud-hook.service.ts # Hook executor
│ └── operation-handler.service.ts # Operation handler
├── types/
│ └── index.ts # Context tags and interfaces
└── schemas/
├── index.ts # Schema exports
└── *.crud.ts # Per-model CRUD schemasOperation Pipeline
The CRUD engine uses the shared Operation Pipeline which provides:
- Prepare Stage — Before hooks execute, validation
- Execute Stage — Database operation via CrudRepository
- After Stage — After hooks (success/failure)
Quick Navigation
- Architecture — Request flow and layer composition
- API Reference —
createCrudRoutesfactory and endpoints - Services — Effect-TS service implementations
- Observability — Metrics, tracing, and logging
- Runbook — Troubleshooting and maintenance
Supported Operations
Each model exposes these standard operations:
findOne— Get single record by IDfindMany— Query multiple records with filterscreateOne— Create new recordupdateOne— Update existing recorddeleteOne— Soft-delete recordaggregate— Aggregation queriesgroupBy— Grouping queries