zerx.js
v0.1.0-beta.1
Published
Zerx — The Universal Application Contract Engine
Readme
Zerx Engine
The Universal Application Contract Engine
🚀 What makes Zerx special?
Modern app development is fragmented: you write Prisma schemas for your DB, Express/Fastify routes for your API, Casbin/CASL rules for authorization, and React Query hooks for the frontend.
Zerx solves this by moving everything into the Contract.
With Zerx, you define your models once. The Zerx AOT Compiler statically parses your TypeScript definitions and generates:
- High-Performance SQL Migrations & DB Schema.
- Zero-Config REST API Routes with automatic caching & rate limiting.
- Robust AuthZ Policies evaluated before any data is touched.
- End-to-End Type-Safe Frontend Hooks (React + SDK).
✨ Killer Features
🛡️ Unified Engine Architecture
Define Models, Validation, Relations, and Permissions in one elegant chainable API.
export const Post = z.model('Post', {
id: z.id(),
title: z.string().min(1).max(200),
author: z.belongsTo('User'),
tags: z.manyToMany('Tag'),
})
.access({
read: () => true, // Publicly readable
create: (_, ctx) => ctx.auth !== null, // Must be logged in
update: (post, ctx) => ctx.auth?.id === post.authorId, // Owner only
delete: (post, ctx) => ctx.auth?.role === 'admin', // Admin only
})
.api({
list: { paginate: true, cache: '1m' },
});⚡ AOT Compiler (No Runtime Overhead)
Unlike other frameworks that generate routes heavily at runtime, zerx generate executes an Ahead-of-Time (AOT) compilation step. It parses the AST of your contract and generates raw, lightning-fast Fastify controllers and optimized SQL statements.
🗄️ Automated Migrations Engine
Stop writing DDL by hand. Run zerx migrate create and Zerx diffs your current Contract against its snapshot history to emit precise SQLite/PostgreSQL ALTER TABLE statements, including foreign key constraints and synthetic join-tables for manyToMany relations.
🎨 Zerx Studio (Premium Admin Dashboard)
Run zerx studio to instantly get a Vercel/Tailwind-inspired premium management dashboard:
- Data Explorer: Visualize, Filter, Sort, and mutate your data.
- Rules Visualizer: Debug your
access()rules visually with exact reason matching (e.g. "Denied by rule: delete requires admin"). - Migration Manager: See real-time database schema states.
- SQL Editor: Run raw SQL queries directly from your browser.
- Relation Badges & Smart Empty States: A UI that feels like magic.
🔌 Fully Ejectable & Modular
You're never locked in. The generated artifacts(.zerx/server, .zerx/client) are formatted, highly-readable TypeScript files. At any point, you can take the generated Fastify app and Prisma-like generic DB client and build upon them yourself.
🛠️ Quick Start
# 1. Initialize a new Zerx Project
npx zerx init my-app
cd my-app
# 2. Generate the Artifacts (Server, Client, Migrations)
npx zerx generate all
# 3. Apply the Database Migrations
npx zerx migrate run
# 4. Start the Development Server
npx zerx dev
# 5. Open the Admin Studio
npx zerx studio📦 Packages
Zerx is managed as a Monorepo using pnpm and turborepo.
| Package | Description |
| :--- | :--- |
| zerx/core | The core z DSL builder, Models, and Engine APIs. |
| zerx/compiler | AOT AST Parser, Code Generators, and Migration Diff Engine. |
| zerx/cli | The zerx command line interface for developers. |
| zerx/server | Fastify-based backend runtime and route adapters. |
| zerx/client | The Frontend SDK & React hooks. |
| zerx/authz | The standalone dynamic Policy Enforcement Engine. |
| zerx/db | High-performance query builder and SQLite driver. |
| zerx/studio | The React-based Premium Admin Dashboard. |
🏗️ Architecture
- Phase 1 (Design): You write
z.model()contracts. - Phase 2 (Compile):
zerx/compilerreads the TS AST, produces aContractIR(Intermediate Representation). - Phase 3 (Generate): Generators spin out SQL Migrations, OpenAPI specs, Fastify routes, and React clients.
- Phase 4 (Runtime):
zerx/servermounts the artifacts dynamically alongside thezerx/authzengine check logic.
🤝 Contributing
Contributions are welcome! Please read our Contributing Guidelines and check out the open issues.
📝 License
Zerx is open-sourced software licensed under the MIT license.
