A progressive Node.js framework for building efficient and scalable server-side applications.
Mini Blog API with Role-Based Access Control (RBAC)
This API combines NestJS, Passport, and CASL to provide secure and flexible access control.
Create a .env file based on the .env.example:
APP_PORT=3000
JWT_SECRET=your_jwt_secret_key_here
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_USER=your_db_username
DATABASE_PASSWORD=your_db_password
DATABASE_NAME=your_db_name$ pnpm install# Generate a new migration
$ pnpm run migration:generate db/migrations/MigrationName
# Run pending migrations
$ pnpm run migration:run
# Revert the last migration
$ pnpm run migration:revertThe project includes seed data for permissions, roles, and users:
# Seed the database with initial data
$ pnpm run seedAfter running the seed command, the following users will be available:
| Password | Role | Description | |
|---|---|---|---|
| admin@example.com | admin123 | super_admin | Full system access |
| moderator@example.com | moderator123 | moderator | Content management |
| author@example.com | author123 | author | Content creation |
| user@example.com | user123 | user | Basic access |
The application implements a Role-Based Access Control (RBAC) system with the following roles and their permissions:
- Has full access to all system resources (super user)
- Can manage all users, roles, permissions, and blogs
- User Management: Create, read, update, and delete users
- Role Management: Create, read, update, and delete roles
- Permission Management: Read permissions
- Blog Management: Full access to all blogs
- User Management: Read users
- Role Management: Read roles
- Blog Management: Full access to all blogs (create, read, update, delete any blog)
- Blog Management:
- Create new blogs
- Read blogs
- Update own blogs
- Delete own blogs
- Blog Management: Read blogs
Each role is assigned specific permissions that define what actions they can perform on different subjects (users, roles, permissions, blogs). The permissions are based on CRUD operations (Create, Read, Update, Delete) and are enforced through the CASL authorization library.
# development
$ pnpm run start
# watch mode
$ pnpm run start:dev
# production mode
$ pnpm run start:prod# unit tests
$ pnpm run test
# e2e tests
$ pnpm run test:e2e
# test coverage
$ pnpm run test:cov