PrimeBrickPrimeBrick
  • Docs
  • Contact
  • MIT License
  • Documentation
  • MCP Server
  • API Catalog
  • Services
  • Libraries
PrimeBrickPrimeBrick

© 2026 PrimeBrick. MIT License. v3.8.0

github
Backend
    OverviewArchitectureAuthenticationRBAC
Frontend
Microservices
powered by Zudoku
Backend

RBAC

RBAC Permission System

The backend uses a wildcard-based RBAC (Role-Based Access Control) system with pattern matching. Permissions are defined in code and mapped to Casdoor roles via the role_mappings table.

Permission format

Permissions follow the pattern: module.action.granularity

PermissionDescription
customers.read.allList all customers
customers.read.singleRead a single customer
customers.read.auditRead customer audit trail
customers.create.singleCreate a single customer
customers.create.bulkBulk create customers
customers.update.singleUpdate a single customer
customers.update.bulkBulk update customers
customers.delete.singleDelete a single customer
customers.delete.bulkBulk delete customers
customers.restore.singleRestore a soft-deleted customer
customers.restore.bulkBulk restore customers
customers.duplicate.bulkBulk duplicate customers
customers.exportExport customers
modules.read.allList all registered modules

Wildcard support

Wildcards use * to match any segment:

PatternMatches
customers.*All customer permissions
customers.read.*All customer read permissions
*Everything (equivalent to admin)

The wildcard matching converts the pattern to a regex at runtime (matchesWildcard(pattern, permission) in permissions.ts).

Role mappings

Role mappings link Casdoor roles to Primebrick permissions. They are stored in the role_mappings table:

ColumnTypeDescription
idp_roletextCasdoor role name (snake_case)
permissionstext[]Array of permission patterns
is_adminbooleanIf true, bypasses all permission checks

Default roles

RolePermissionsAdmin
administrators(bypass)true
collaborator["customers.*"]false
guest["customers.read.*"]false

Implementation

Key files:

FilePurpose
src/modules/auth/permissions.tsPermission enum and wildcard matching
src/modules/auth/rbac.middleware.tsRBAC middleware with admin bypass
src/modules/auth/auth.middleware.tsAuth middleware with permission expansion
src/modules/auth/role-mapping-repo.tsRole mapping repository
src/modules/auth/types.tsAuthUser type with isAdmin field

Key functions:

  • expandPermissions(roles, getRoleMappingFn) — returns { patterns, isAdmin }
  • isPermissionGranted(userPermissions, requiredPermission) — pattern matching
  • matchesWildcard(pattern, permission) — converts wildcard to regex

Adding a new permission

  1. Add the permission constant to the Permission enum in permissions.ts
  2. Use it in route handlers: rbacHandler([Permission.NEW_PERMISSION])
  3. Update role mappings in the database to grant the permission (or use a wildcard)
  4. The Permission enum is the source of truth — no need to update getAllPermissions

Testing RBAC changes

After updating role mappings in the database, restart the backend server to reload the role mapping cache.

Last modified on July 26, 2026
AuthenticationOverview
On this page
  • Permission format
  • Wildcard support
  • Role mappings
    • Default roles
  • Implementation
  • Adding a new permission
  • Testing RBAC changes