Skip to content

mowems/rbac-system

Repository files navigation

RBAC Access Manager

This project is a scalable Role-Based Access Control (RBAC) API built with Node.js, Express, Prisma, PostgreSQL, Redis, and AWS ECS Fargate. It provides secure access control by dynamically assigning users to roles and permissions. It is deployed on AWS ECS Fargate with a Load Balancer, Redis ElastiCache, and PostgreSQL for optimized performance.


** Features**

  • Secure Authentication: JWT-based authentication for secure session handling
  • Role & Permission Management: Assign multiple roles to users and define custom permissions
  • Caching Layer: Redis ElastiCache for fast lookup of user roles & permissions
  • Scalability: Auto-scaling ECS tasks based on CPU load, handling up to 5000 concurrent requests
  • Fault Tolerance: Load Balancer for distributing traffic across multiple containers
  • Optimized Queries: Prisma ORM with PostgreSQL for efficient database queries

Tech Stack

  • Backend: Node.js, Express.js, TypeScript
  • Database: PostgreSQL (via Prisma ORM)
  • Caching: Redis (AWS ElastiCache)
  • Containerization: Docker
  • Authentication: JWT (JSON Web Token)
  • Orchestration: AWS ECS (Fargate)
  • Load Balancing: AWS Application Load Balancer (ALB)
  • Auto-Scaling: ECS Service Auto-Scaling based on CPU utilization
  • Monitoring & Logging: AWS CloudWatch Logs
  • Testing: Jest, Supertest, ApacheBench (ab) for load testing
  • Version Control: Git, GitHub

Getting Started

Install Dependencies

  • npm install

Set up environment variables

Server Config

PORT=3000 HOST=0.0.0.0

JWT Authentication

JWT_SECRET=your_super_secret_key JWT_EXPIRES_IN=1h

Database Connection (Local)

DATABASE_URL=postgresql://postgres:123@localhost:5434/rbac_db?schema=public

Redis Configuration

REDIS_URL=redis://localhost:6379 REDIS_HOST=127.0.0.1 REDIS_PORT=6379 REDIS_TLS_ENABLED=false

Start the API Locally

  • npm run dev

Run with Docker - Ensure you have Docker installed

  • docker build -t rbac-api .
  • docker run -p 3000:3000 --env-file .env rbac-api

Apply database migrations

  • npx prisma migrate dev --name init

Seed the database

  • npm run seed

Start the API

  • npm run dev

Authentication Method Endpoint Description POST /api/auth/register Register a new user POST /api/auth/login Login and get JWT token POST /api/auth/logout Logout user

Users Method Endpoint Description GET /api/users Get all users GET /api/users/:id Get user by ID POST /api/users Create a new user (Admin only) PATCH /api/users/:id Update user details (Admin only) DELETE /api/users/:id Delete a user (Admin only)

Roles & Permissions Method Endpoint Description GET /api/roles Get all roles POST /api/roles Create a new role (Admin only) POST /api/assignments/users/:userId/assign-role Assign a role to a user

Testing

  • npm test

Benchmark Results

  • ab -n 5000 -c 100 /api/auth/login

Results:

  • 5000 concurrent requests
  • Average response time: ~1200ms
  • Zero failed requests
  • Auto-scaled to 3 ECS tasks under load

Deployment to AWS

This API is deployed using AWS ECS Fargate with AWS Application Load Balancer (ALB) and Redis ElastiCache. Here’s a summary of the AWS deployment strategy:

Containerization:

  • Dockerized and stored in AWS Elastic Container Registry (ECR)
  • Task definitions managed via AWS ECS

Database & Caching:

  • PostgreSQL RDS as the primary database
  • Redis ElastiCache for session storage & caching

Scaling & Load Balancing:

  • AWS Application Load Balancer (ALB) for traffic distribution
  • ECS Auto-Scaling adjusts instances based on CPU & memory utilization

Clone the repository

git clone https://github.com/mowems/rbac-system.git
cd rbac-system

NOTES **

Ensure Docker is installed and running before setting up the database. Modify the .env file with your own database credentials before running migrations. Only admins can create users and assign roles. The API is fully tested with Jest & Supertest.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors