Skip to content

Enterprise-grade Angular library for scalable, maintainable role-based access control (RBAC) with powerful services and structural directives.

License

Notifications You must be signed in to change notification settings

IroshanRathnayake/ngx-role-accessor

Repository files navigation

NGX Role Accessor - Advanced RBAC Library

Version Angular License TypeScript

🔐 Enterprise-grade Angular Role-Based Access Control (RBAC) Library

DocumentationExamplesAPI Reference


✨ Features

  • 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

📦 Installation

npm install ngx-role-accessor

🚀 Quick Start

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()
    });
  }
}

🏗️ Project Structure

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

� Documentation

For complete documentation, examples, and API reference, see: 📚 Full Documentation


🔧 Development

Build the Library

ng build ngx-role-accessor

Run Tests

ng test ngx-role-accessor

Run Demo

ng serve

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

git clone https://github.com/IroshanRathnayake/ngx-role-accessor.git
cd ngx-role-accessor
npm install
npm run build
npm run test

📄 License

MIT © Iroshan Rathnayake


Made with ❤️ for the Angular community

⭐ Star this project

About

Enterprise-grade Angular library for scalable, maintainable role-based access control (RBAC) with powerful services and structural directives.

Topics

Resources

License

Contributing

Stars

Watchers

Forks