https://github.com/ctrly4sh/auth-rbac-rest-api
Role Base Access Control Rest API implementation in Express , Typescript, Prisma and Neon DB ( serverless postgres) with Bun.
https://github.com/ctrly4sh/auth-rbac-rest-api
authentication backend nodejs security
Last synced: 9 months ago
JSON representation
Role Base Access Control Rest API implementation in Express , Typescript, Prisma and Neon DB ( serverless postgres) with Bun.
- Host: GitHub
- URL: https://github.com/ctrly4sh/auth-rbac-rest-api
- Owner: ctrly4sh
- Created: 2024-05-05T16:24:53.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-08-18T16:08:48.000Z (10 months ago)
- Last Synced: 2025-08-18T18:11:33.225Z (10 months ago)
- Topics: authentication, backend, nodejs, security
- Language: TypeScript
- Homepage:
- Size: 150 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Auth RBAC REST API
A secure and scalable Role-Based Access Control (RBAC) REST API built with Express.js, TypeScript, and Prisma. This API provides authentication and authorization services with JWT tokens and refresh tokens.
Design

## ๐ Features
- **User Authentication**
- Secure registration and login with email/password
- JWT-based authentication
- Refresh token mechanism
- Rate limiting for security
- **Role-Based Access Control (RBAC)**
- Predefined user roles (ADMIN, USER)
- Middleware for role-based route protection
- Extensible permission system
- **Security**
- Password hashing with bcrypt
- Helmet for security headers
- CORS protection
- Environment-based configuration
- **Database**
- PostgreSQL with Prisma ORM
- Database migrations
- Type-safe database queries
## ๐ ๏ธ Tech Stack
- **Runtime**: Node.js with Bun
- **Language**: TypeScript
- **Framework**: Express.js
- **Database**: PostgreSQL
- **ORM**: Prisma
- **Authentication**: JWT
- **Security**: Helmet, bcrypt, express-rate-limit
- **Validation**: Express Validator
## ๐ฆ Prerequisites
- Node.js (v18+)
- Bun (v1.0.0+)
- PostgreSQL (v14+)
- Git
## ๐ Getting Started
1. **Clone the repository**
```bash
git clone https://github.com/ctrly4sh/Auth-RBAC-Rest-API.git
cd Auth-RBAC-Rest-API
```
2. **Install dependencies**
```bash
bun install
```
3. **Set up environment variables**
Create a `.env` file in the root directory and add the following variables:
```env
DATABASE_URL="postgresql://user:password@localhost:5432/auth_rbac?schema=public"
JWT_SECRET=your_jwt_secret_key
JWT_REFRESH_SECRET=your_refresh_token_secret
PORT=3000
NODE_ENV=development
```
4. **Run database migrations**
```bash
npx prisma migrate dev --name init
```
5. **Start the development server**
```bash
bun run dev
```
Or with hot-reload:
```bash
bun run watch
```
## ๐ API Documentation
API documentation is available in the Postman collection file: `postman-collection.json`
### Available Endpoints
- `POST /api/auth/register` - Register a new user
- `POST /api/auth/login` - User login
- `POST /api/auth/refresh-token` - Refresh access token
- `GET /api/users/me` - Get current user profile (protected)
- `GET /api/users` - Get all users (admin only)
## ๐งช Testing
To run tests:
```bash
bun test
```
## ๐๏ธ Project Structure
```
src/
โโโ config/ # Configuration files
โโโ controllers/ # Route controllers
โโโ middlewares/ # Custom middlewares
โโโ routes/ # Route definitions
โโโ services/ # Business logic
โโโ types/ # TypeScript type definitions
โโโ app.ts # Express application setup
โโโ server.ts # Server entry point
```
## ๐ Security
- All passwords are hashed using bcrypt
- JWT tokens for stateless authentication
- Rate limiting to prevent brute force attacks
- Security headers with Helmet
- Environment variables for sensitive data
## ๐ค Contributing
1. Fork the project
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Official Documentation and Resources
- [Express.js](https://expressjs.com/)
- [Prisma](https://www.prisma.io/)
- [JWT](https://jwt.io/)
- [Bun](https://bun.sh/)
- [Excalidraw](https://excalidraw.com/)