Article
Introducing Crudora - A CRUD Framework for Express.js Developers
Crudora is a TypeScript CRUD framework built on Express.js and Prisma, with automatic API generation, lifecycle hooks, and field-level security.
Overview
Building REST APIs involves a lot of repetitive work: CRUD operations, validation, pagination, wiring up the database. Crudora exists to cut that down for TypeScript and Express.js developers.
Crudora is an automatic CRUD API generator built on top of Prisma ORM. Define a model, register it, and you have working REST endpoints in minutes instead of hours, without giving up flexibility once you need to customize something.
Why Crudora
1. Zero configuration
Install the package, define your models, and Crudora handles the rest: CRUD endpoints, Prisma schemas, even environment configuration, without hours of boilerplate first.
2. Type-safe by default
Crudora leans on TypeScript and Prisma for full type safety across the project, which means fewer runtime surprises and better autocomplete in your editor.
3. Built-in features
Request validation via Zod, pagination, filtering, and field security all ship with Crudora, so you’re not pulling in three extra libraries to cover the basics.
4. Lifecycle hooks
Need to hash a password before it hits the database, or send a welcome email after a user is created? Crudora’s lifecycle hooks (beforeCreate, afterUpdate, and others) give you a place to hook in custom logic at each step.
5. Room to extend
Crudora automates the repetitive parts without locking you into a rigid structure. Custom routes, middleware, and overriding default behavior are all straightforward.
Key features
Automatic CRUD generation
Define a model, register it with Crudora, and it generates working REST endpoints for listing, creating, updating, and deleting records.
class User extends Model {
static tableName = "users";
static fillable = ["name", "email", "password"];
static hidden = ["password"];
}
const server = new CrudoraServer({ port: 3000, prisma });
server.registerModel(User).generateRoutes().listen(); Flexible model definitions
Models support attributes like fillable (for mass assignment), hidden (to keep sensitive fields out of API responses), and timestamps (to manage createdAt and updatedAt automatically).
Pagination and filtering
Built-in support for pagination (skip, take) and filtering (where, orderBy) keeps your APIs scalable without extra setup.
Automatic validation
Crudora uses Zod under the hood to validate incoming requests, generating both strict (create) and partial (update) validation schemas from your model definitions.
Field security
Mark sensitive fields like passwords or API keys as hidden and they’re excluded from every API response automatically.
CLI tool
# Initialize a new project
npx crudora init
# Generate Prisma Client
npx crudora generate
# Push schema changes to the database
npx crudora push Getting started with Crudora
Step 1: Install dependencies
npm install crudora prisma @prisma/client
# or
yarn add crudora prisma @prisma/client Step 2: Define your models
Create model classes that extend Crudora’s Model base class:
import { Model } from "crudora";
class User extends Model {
static tableName = "users";
static primaryKey = "id";
static timestamps = true;
static fillable = ["name", "email", "password"];
static hidden = ["password"];
static async beforeCreate(data: any): Promise<any> {
data.password = await hashPassword(data.password);
return data;
}
} Step 3: Register models and start the server
import { CrudoraServer } from "crudora";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
const server = new CrudoraServer({
port: 3000,
prisma,
});
server
.registerModel(User)
.generateRoutes()
.listen(() => {
console.log("Server running on port 3000");
}); That’s it, Crudora generates REST endpoints for the User model automatically.
Advanced usage
Custom routes
Crudora doesn’t stop you from adding routes outside the generated CRUD set:
server.get("/health", (req, res) => {
res.json({ status: "ok", timestamp: new Date() });
}); Lifecycle hooks
static async beforeCreate(data: any): Promise<any> {
data.password = await hashPassword(data.password);
return data;
}
static async afterCreate(data: any, result: any): Promise<any> {
await sendWelcomeEmail(result.email);
return result;
} Schema generation
Generate Prisma schemas programmatically from your models:
const schema = server.getCrudora().generatePrismaSchema("postgresql");
console.log(schema); Conclusion
Crudora combines TypeScript, Express.js, and Prisma into a CRUD framework that stays type-safe and customizable while cutting out most of the repetitive setup. It’s not trying to replace your architecture, just the boilerplate around it.
Source and docs are on GitHub.
Note: Crudora is currently in alpha and not yet recommended for production use. Issues and pull requests are welcome.