Skip to content

Introduction ​

RBAC Evolution adds roles and permissions to JavaScript and TypeScript apps. You define permissions, group them into roles, assign roles (or individual permissions) to your users, and then ask a simple question anywhere in your code:

ts
await rbac.for(user).can('edit articles') // true / false

It is a port of spatie/laravel-permission to the JS ecosystem. If you have used that package in Laravel, the concepts and most method names will feel familiar. Huge thanks to Spatie for the original design.

Status

RBAC Evolution is stable (1.x). Breaking changes only happen in a new major version. See Versioning.

Why ​

Laravel developers have a de-facto standard for roles and permissions. In JavaScript, authorization is usually rebuilt per project, or tied to one ORM or one framework.

RBAC Evolution keeps the logic in one framework-agnostic core and moves the rest into small packages:

  • an adapter decides where roles and permissions are stored (Prisma, Drizzle, Kysely, TypeORM, Sequelize, MikroORM, Mongoose, memory, or your own),
  • an integration connects the engine to your framework (Express, Fastify, Hono, Elysia, NestJS, Next.js, React Router, Nuxt, SvelteKit, Astro, TanStack Start, tRPC, React, Vue, Solid).

You install only the pieces you use.

Features ​

  • Roles and permissions, assigned to any kind of subject (users, API clients, service accounts, ...)
  • Permissions granted directly to a subject or inherited through its roles
  • Guards for separate sets of roles and permissions, such as web and api
  • Teams for multi-tenant apps
  • Wildcard permissions like articles.*
  • Super-admin roles and a before hook, like Laravel's Gate::before
  • Typed names: restrict role and permission names with a union type or a TS enum
  • Built-in caching with pluggable stores (Redis, KV, ...)
  • Events when roles or permissions are created, deleted, attached or detached
  • A CLI similar to php artisan permission:*
  • UI helpers for React, Vue, Solid and Svelte, and route protection for Express, Fastify, Hono, Elysia, NestJS, Next.js, React Router, Nuxt, SvelteKit, TanStack Start, Astro and tRPC

Packages ​

PackageWhat it does
@anievo-id/rbac-evolutionThe core engine. Includes the in-memory adapter.
@anievo-id/rbac-evolution-prismaStorage adapter for Prisma
@anievo-id/rbac-evolution-drizzleStorage adapter for Drizzle (PostgreSQL, MySQL and SQLite)
@anievo-id/rbac-evolution-kyselyStorage adapter for Kysely (PostgreSQL, MySQL, SQLite and SQL Server)
@anievo-id/rbac-evolution-typeormStorage adapter for TypeORM 0.3 and 1.x (PostgreSQL, MySQL, SQLite and SQL Server)
@anievo-id/rbac-evolution-sequelizeStorage adapter for Sequelize 6 (PostgreSQL, MySQL, SQLite and SQL Server)
@anievo-id/rbac-evolution-mongooseStorage adapter for Mongoose (MongoDB)
@anievo-id/rbac-evolution-redisCache store shared by every process, in Redis or Valkey
@anievo-id/rbac-evolution-nextNext.js server helpers, server action / route handler guards and middleware
@anievo-id/rbac-evolution-nuxtNuxt module: SSR-hydrated permissions, auto-imported composables, route middleware and Nitro helpers
@anievo-id/rbac-evolution-sveltekitSvelteKit handle hook, guards for load, form actions and +server.ts endpoints, and Svelte 5 <Can> / <HasRole> with a runes-based context
@anievo-id/rbac-evolution-tanstack-startGuards for TanStack Start server functions, middleware and server routes, snapshot for <RbacProvider>
@anievo-id/rbac-evolution-astroAstro guards for pages, endpoints and middleware, and a snapshot for client islands
@anievo-id/rbac-evolution-react<RbacProvider>, <Can>, <Cannot>, <HasRole>, useCan() and other hooks
@anievo-id/rbac-evolution-solidThe same for Solid 1.x and 2.x: <RbacProvider>, <Can>, <HasRole>, useCan() accessors
@anievo-id/rbac-evolution-vuev-can / v-role directives, <Can> / <HasRole> components and composables
@anievo-id/rbac-evolution-expressExpress middleware: requirePermission, requireRole, requireRoleOrPermission
@anievo-id/rbac-evolution-fastifyFastify plugin and preHandler guards
@anievo-id/rbac-evolution-react-routerGuards for React Router 7/8 and Remix loaders and actions, snapshot for <RbacProvider>
@anievo-id/rbac-evolution-honoHono middleware (Node, Bun, Cloudflare Workers and other edge runtimes)
@anievo-id/rbac-evolution-elysiaElysia plugin and beforeHandle guards (Bun first, also Node, Deno, Workers)
@anievo-id/rbac-evolution-nestjsNestJS module, guard and decorators
@anievo-id/rbac-evolution-trpctRPC middleware: requirePermission, requireRole, requireRoleOrPermission for procedures
@anievo-id/rbac-evolution-cliCommand-line tool to create roles, assign them and inspect the setup

TIP

The React, Vue, Solid and Svelte helpers only decide what the UI shows. Always enforce permissions on the server as well.

Next steps ​

Released under the MIT License. Inspired by spatie/laravel-permission.