C
CanxJS
v1.6.2
  • Learn
  • Blog
  • Showcase
C
CanxJS

Ultra-fast async MVC backend framework for Bun. Build production-ready APIs with elegance and speed.

Resources

  • Documentation
  • Learn
  • Blog
  • Showcase

Documentation

  • Introduction
  • Installation
  • Core Concepts
  • CLI Commands
  • API Reference

Legal

  • Privacy Policy
  • Terms of Service

© 2026 CanxJS. All rights reserved.

Built with ❤️ for Candra Kirana

  • Citadel (Admin)
  • Dominion (RBAC)
  • Blocks (Modules)
  • Echo (Realtime)
  • Telescope (Debug)
  • Payment (Midtrans)
Official Package

Dominion

@canxjs/dominion provides advanced role-based access control (RBAC) for your application. Inspired by Spatie Laravel Permission.

Installation

terminal
1npm install @canxjs/dominion
2
3node canx dominion:install
4node canx migrate

Setup User Model

Add the HasRoles mixin to your User model.

models/User.ts
1import { Model } from "canxjs";
2import { HasRoles } from "@canxjs/dominion";
3
4class User extends HasRoles(Model) {
5 // Your user model...
6}

Creating & Assigning Roles

example.ts
1import { Role, Permission } from "@canxjs/dominion";
2
3// Create roles and permissions
4await Permission.create({ name: "create posts" });
5const role = await Role.create({ name: "writer" });
6
7// Assign role to user
8const user = await User.find(1);
9await user.assignRole("writer");
10
11// Check role
12if (await user.hasRole("writer")) {
13 // User is a writer
14}

Direct Permissions

Give permissions directly to users, or sync all roles at once.

example.ts
1// Direct permissions
2await user.givePermissionTo("delete posts");
3
4// Check permission (both direct and role-based)
5if (await user.hasPermissionTo("delete posts")) {
6 // User can delete posts
7}
8
9// Sync roles (replace all current roles)
10await user.syncRoles("admin", "manager");

Next Steps

Explore related packages and core features.