🔐 Enterprise-grade Angular Role-Based Access Control (RBAC) Library
- ✅ Angular 16+ Standalone APIs - Modern Angular support
- ✅ Hierarchical Role System - Role inheritance and levels
- ✅ Multi-tenant Architecture - Built-in tenant isolation
- ✅ Fine-grained Permissions - Resource and action-based permissions
- ✅ Performance Optimized - LRU caching with TTL support
- ✅ Professional Logging - Structured logging and audit trail
- ✅ Event-driven Architecture - Real-time RBAC events
- ✅ Rich Directive Set - Multiple directives for all scenarios
- ✅ Route Guards - Ready-to-use guards for route protection
- ✅ Comprehensive Testing - Full test coverage and utilities
npm install ngx-role-accessor
import { Component, inject } from '@angular/core';
import {
HasRoleDirective,
HasAnyRoleDirective,
HasPermissionDirective,
RoleService
} from 'ngx-role-accessor';
@Component({
standalone: true,
selector: 'app-dashboard',
imports: [HasRoleDirective, HasAnyRoleDirective, HasPermissionDirective],
template: `
<!-- Role-based access -->
<div *hasRole="'admin'">Admin only content</div>
<div *hasAnyRole="['admin', 'manager']">Management content</div>
<!-- Permission-based access -->
<div *hasPermission="'CAN_VIEW_REPORTS'">Reports section</div>
<!-- With fallback -->
<div *hasRole="'premium'; else basicUser">Premium features</div>
<ng-template #basicUser>Upgrade to premium</ng-template>
`
})
export class DashboardComponent {
private roleService = inject(RoleService);
ngOnInit() {
// Set user context
this.roleService.setUserContext({
userId: 'user123',
roles: [
{ id: 'admin', name: 'Administrator', active: true, level: 0 }
],
permissions: [
{ id: 'CAN_VIEW_REPORTS', name: 'View Reports', resource: 'reports', action: 'view', active: true }
],
tenantId: 'tenant1',
lastUpdated: new Date()
});
}
}
ngx-role-accessor/
├── projects/
│ └── ngx-role-accessor/ # Main library
│ ├── src/
│ │ ├── lib/
│ │ │ ├── services/ # Core RBAC service
│ │ │ ├── directives/ # Structural directives
│ │ │ ├── guards/ # Route guards
│ │ │ ├── pipes/ # Template pipes
│ │ │ ├── utils/ # Utility classes
│ │ │ ├── types/ # TypeScript definitions
│ │ │ └── config/ # Configuration
│ │ └── public-api.ts # Public API exports
│ └── README.md # Full documentation
├── angular.json # Angular CLI config
├── package.json # Dependencies
└── README.md # This file
For complete documentation, examples, and API reference, see: 📚 Full Documentation
ng build ngx-role-accessor
ng test ngx-role-accessor
ng serve
We welcome contributions! Please see our Contributing Guide for details.
git clone https://github.com/IroshanRathnayake/ngx-role-accessor.git
cd ngx-role-accessor
npm install
npm run build
npm run test
MIT © Iroshan Rathnayake
Made with ❤️ for the Angular community