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

Overview

Primebrick Backend

The Primebrick Backend (primebrick-api) is the central API server for Primebrick v3. It exposes the REST API consumed by the frontend, manages the PostgreSQL database, integrates with Casdoor for identity and authentication, and acts as the service registry for microservices connected via NATS.

Responsibilities

AreaWhat it does
REST APIExpress-based HTTP server on port 3001 serving all Primebrick endpoints
DatabasePostgreSQL with a patch-based migration system (db:migrate)
AuthenticationCasdoor IDP integration, JWT/OIDC verification, API keys, passkeys
RBACWildcard-based permission system with role mappings and admin bypass
Service registrySubscribes to microservice lifecycle events over NATS
MCP ServerModel Context Protocol server for AI agent integration
OrganizationsMulti-tenant organization management with user invitations

Architecture

Modules

ModuleDescription
authCasdoor integration, JWT/OIDC verification, user profiles, passkeys, organizations, role mappings, password policy
customersCustomer entity CRUD, audit trail, bulk operations, duplicate/restore
mcpModel Context Protocol server exposing Primebrick tools to AI agents
proxyReverse proxy to registered microservices via NATS
systemSystem configuration, module registry, health checks, version info

Authentication flow

The backend integrates with Casdoor as the identity provider (IDP). The authentication flow is:

  1. The frontend redirects to Casdoor for login (OIDC authorization code flow)
  2. Casdoor returns a JWT access token
  3. The frontend sends the JWT in the Authorization: Bearer header
  4. The backend's auth middleware verifies the JWT against Casdoor's JWKS
  5. The RBAC middleware checks the user's permissions against the required route permission using wildcard pattern matching

RBAC permission system

Permissions follow the pattern module.action.granularity:

  • customers.read.all — list all customers
  • customers.read.single — read a single customer
  • customers.create.bulk — bulk create customers
  • customers.* — wildcard matching all customer permissions
  • * — admin bypass (matches everything)

Role mappings are stored in the role_mappings table and linked to Casdoor roles. Users with is_admin = true bypass all permission checks.

Database

The backend uses PostgreSQL with a patch-based migration system:

  • pnpm run db:meta:compare — generates snapshots and patch files when entity models drift from the database schema
  • pnpm run db:migrate — applies pending .sql patch files in order, using SHA-256 checksums to skip already-applied patches

Commands

ActionCommand
Installpnpm install
Dev APIpnpm run dev (port 3001)
Buildpnpm run build
DB schema comparepnpm run db:meta:compare
Apply DB patchespnpm run db:migrate
Seed demo customerspnpm run db:seed:customers
Postgres updocker compose -f infra/docker-compose.postgres.yml up -d
Postgres downdocker compose -f infra/docker-compose.postgres.yml down
Last modified on July 26, 2026
Architecture
On this page
  • Responsibilities
  • Architecture
  • Modules
  • Authentication flow
  • RBAC permission system
  • Database
  • Commands