# seeden/rbac architecture

> Architecture diagram of the GitHub repository seeden/rbac, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/seeden/rbac
- Repository: https://github.com/seeden/rbac

## Overview

This library provides hierarchical role-based access control for Node.js. An application configures roles, action/resource permissions, and grants, then initializes RBAC; the library creates and stores those entities and links grants into role hierarchies. Authorization checks traverse a role’s grants and match permissions, with role instances offering convenience methods. The default backend is in-memory; custom storage can implement the documented Storage contract. The RBAC excerpt is partial, so only clearly evidenced call relationships are shown.

Main entry points: [`src/RBAC.js`](https://github.com/seeden/rbac/blob/main/src/RBAC.js) (RBAC), [`src/Storage.js`](https://github.com/seeden/rbac/blob/main/src/Storage.js) (Storage Contract), [`src/Role.js`](https://github.com/seeden/rbac/blob/main/src/Role.js) (Role), [`src/Base.js`](https://github.com/seeden/rbac/blob/main/src/Base.js) (Base Entity)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["RBAC API"]
  node_rbac["RBAC<br/>[RBAC.js]"]
end

subgraph group_entities["Roles And Permissions"]
  node_base["Base Entity<br/>[Base.js]"]
  node_role["Role<br/>[Role.js]"]
  node_permission["Permission<br/>[Permission.js]"]
end

subgraph group_authorization["Authorization"]
  node_grant_traversal["Grant Traversal<br/>[RBAC.js]"]
end

subgraph group_storage["Storage"]
  node_storage_contract["Storage Contract<br/>[Storage.js]"]
  node_memory[("Memory Storage<br/>[Memory.js]")]
end

node_application(("Application"))
node_custom_storage["Custom Storage"]

node_application -->|"configures and queries"| node_rbac
node_rbac -->|"creates"| node_role
node_rbac -->|"creates"| node_permission
node_role -->|"extends"| node_base
node_permission -->|"extends"| node_base
node_base -->|"adds or removes"| node_rbac
node_role -->|"delegates checks"| node_rbac
node_rbac -->|"defaults to"| node_memory
node_rbac -->|"uses contract"| node_storage_contract
node_memory -->|"implements"| node_storage_contract
node_custom_storage -.->|"implements"| node_storage_contract
node_rbac -->|"checks hierarchy"| node_grant_traversal
node_grant_traversal -->|"reads grants"| node_storage_contract
node_grant_traversal -->|"matches permission"| node_permission
node_rbac -->|"adds roles and permissions"| node_storage_contract
node_rbac -->|"grants or revokes"| node_storage_contract

click node_rbac "https://github.com/seeden/rbac/blob/main/src/RBAC.js"
click node_base "https://github.com/seeden/rbac/blob/main/src/Base.js"
click node_role "https://github.com/seeden/rbac/blob/main/src/Role.js"
click node_permission "https://github.com/seeden/rbac/blob/main/src/Permission.js"
click node_grant_traversal "https://github.com/seeden/rbac/blob/main/src/RBAC.js"
click node_storage_contract "https://github.com/seeden/rbac/blob/main/src/Storage.js"
click node_memory "https://github.com/seeden/rbac/blob/main/src/Memory.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_rbac toneBlue
class node_base,node_role,node_permission,node_custom_storage toneAmber
class node_grant_traversal toneMint
class node_storage_contract,node_memory toneRose
class node_application toneIndigo
```

## Components

### RBAC API

- [RBAC](https://github.com/seeden/rbac/blob/main/src/RBAC.js): `src/RBAC.js`

### Roles And Permissions

- [Base Entity](https://github.com/seeden/rbac/blob/main/src/Base.js): `src/Base.js`
- [Role](https://github.com/seeden/rbac/blob/main/src/Role.js): `src/Role.js`
- [Permission](https://github.com/seeden/rbac/blob/main/src/Permission.js): `src/Permission.js`

### Authorization

- [Grant Traversal](https://github.com/seeden/rbac/blob/main/src/RBAC.js): `src/RBAC.js`

### Storage

- [Storage Contract](https://github.com/seeden/rbac/blob/main/src/Storage.js): `src/Storage.js`
- [Memory Storage](https://github.com/seeden/rbac/blob/main/src/Memory.js): `src/Memory.js`

### Other components

- **Application**
- **Custom Storage**

## Connections

- Application → RBAC: configures and queries
- RBAC → Role: creates
- RBAC → Permission: creates
- Role → Base Entity: extends
- Permission → Base Entity: extends
- Base Entity → RBAC: adds or removes
- Role → RBAC: delegates checks
- RBAC → Memory Storage: defaults to
- RBAC → Storage Contract: uses contract
- Memory Storage → Storage Contract: implements
- Custom Storage → Storage Contract: implements
- RBAC → Grant Traversal: checks hierarchy
- Grant Traversal → Storage Contract: reads grants
- Grant Traversal → Permission: matches permission
- RBAC → Storage Contract: adds roles and permissions
- RBAC → Storage Contract: grants or revokes
