Skip to content

Commit 465a34a

Browse files
Merge branch 'main' into feat/dockerize-application
2 parents 0fcfe13 + f2477b3 commit 465a34a

38 files changed

Lines changed: 4061 additions & 544 deletions

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ JWT_EXPIRE=7d
1616

1717
# CORS Configuration
1818
CORS_URL=http://localhost:3000
19+
Lines changed: 125 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,142 @@
1-
# Contribute to <Project_Name>
1+
# Contributing to RBAC
22

3-
Thank you for taking the time to contribute to <project_name>! We really appreciate it.
3+
Thank you for taking the time to contribute to **RBAC**! 🎉
4+
We appreciate your interest and contributions — whether it's fixing bugs, improving documentation, or adding new features.
45

5-
Before contributing, please make sure to read the [Code of Conduct](../../CODE_OF_CONDUCT.md). We expect you to follow it in all your interactions with the project.
6+
Before contributing, please make sure to read our [Code of Conduct](../../CODE_OF_CONDUCT.md).
7+
We expect all contributors to uphold it in all interactions related to this project.
68

7-
## New to <Project_Name>?
9+
---
810

9-
If you are new to <Project_Name>, please take a look at the [documentation](./Project_Tour.md). It is a great place to start.
11+
## 🧭 New to RBAC?
1012

11-
## New Contributor Guide
13+
If you’re new here, start by exploring our [Project Tour](./Project_Tour.md) for an overview of the architecture, setup, and modules.
14+
To understand the code structure, check out the [README.md](../src/README.md) file inside the `src` directory.
1215

13-
To get an overview of the codebase, check out the '[README.md](../src/README.md)' file in the `src` directory.
16+
---
1417

15-
that will help you understand the structure of the project.
18+
## 💡 Ways to Contribute
1619

17-
## How to Contribute
20+
There are many ways you can help make RBAC better!
1821

19-
### Reporting Bugs
22+
### 🐞 Reporting Bugs
23+
If you find a bug or an unexpected behavior:
24+
1. Check existing [Issues](../../issues) to see if it’s already reported.
25+
2. If not, [submit a new bug report](../ISSUE_TEMPLATE/bug_report.yaml).
26+
3. Include clear steps to reproduce, expected vs actual behavior, and screenshots if relevant.
2027

21-
If you find a bug in the source code, you can help us by [submitting an issue](../ISSUE_TEMPLATE/bug_report.yaml).
28+
---
2229

23-
### Suggesting Enhancements
30+
### 🚀 Suggesting Enhancements
31+
Have an idea to improve RBAC? We’d love to hear it!
32+
- Submit a [Feature Request](../ISSUE_TEMPLATE/feature_request.yaml).
33+
- Describe the motivation, proposed solution, and any possible alternatives.
2434

25-
If you want to suggest an enhancement to <Project_Name>, please [submit an issue](../ISSUE_TEMPLATE/feature_request.yaml).
35+
---
2636

27-
### Pull Requests
37+
### 🧑‍💻 Submitting a Pull Request (PR)
2838

29-
If you want to contribute to <Project_Name>, submit a pull request.
39+
We welcome pull requests for fixes, features, and docs improvements.
3040

31-
- url: `https://github.com/OPCODE-Open-Spring-Fest/<project_Name>/compare/branch...YOURGITHUBUSERNAME:<project_Name>:BRANCH?quick_pull=1&template=pr.md`
41+
#### 🔄 Fork & Clone
42+
1. Fork the repository:
43+
```bash
44+
git clone https://github.com/YOUR_GITHUB_USERNAME/RBAC.git
45+
cd RBAC
46+
```
47+
2. Create a new branch for your feature or fix:
48+
```bash
49+
git checkout -b feature/your-feature-name
50+
```
3251

33-
### Requirements
52+
#### 🧩 Make Your Changes
53+
- Follow existing code style and conventions.
54+
- Add comments and documentation where needed.
55+
- Test your changes before committing.
3456

35-
### Setup
57+
#### 🧾 Commit Your Changes
58+
Use **conventional commit messages** (for example):
59+
```
60+
fix: resolve login redirect bug
61+
docs: update API setup instructions
62+
feat: add JWT-based role validation middleware
63+
```
64+
65+
#### 📬 Push and Create a PR
66+
Push your branch and open a pull request using the following URL:
67+
```
68+
https://github.com/OPCODE-Open-Spring-Fest/RBAC/compare/main...YOUR_GITHUB_USERNAME:RBAC:BRANCH?quick_pull=1&template=pr.md
69+
```
70+
71+
Your PR should:
72+
- Clearly describe the changes.
73+
- Reference related issues (e.g., “Closes #23”).
74+
- Include screenshots or logs if relevant.
75+
76+
---
77+
78+
## ⚙️ Local Setup
79+
80+
To set up the project locally:
81+
82+
```bash
83+
git clone https://github.com/OPCODE-Open-Spring-Fest/RBAC.git
84+
cd RBAC
85+
npm install
86+
npm run dev
87+
```
88+
89+
> 💡 Ensure Node.js and npm are installed before running the project.
90+
91+
---
92+
93+
## ✅ Code Guidelines
94+
95+
- Follow **ESLint** rules configured in the project.
96+
- Write meaningful commit messages and pull request titles.
97+
- Keep PRs focused — one purpose per PR.
98+
- Update or add relevant documentation when changing code.
99+
100+
---
101+
102+
## 🧪 Testing
103+
104+
Run the test suite before submitting your PR:
105+
106+
```bash
107+
npm test
108+
```
109+
110+
If you add new functionality, include corresponding unit tests.
111+
112+
---
113+
114+
## 🧱 Branch Naming Convention
115+
116+
Please follow this format for branch names:
117+
- `feat/<feature-name>` – for new features
118+
- `fix/<bug-name>` – for bug fixes
119+
- `docs/<file-update>` – for documentation
120+
- `refactor/<component>` – for refactoring
121+
122+
Example:
123+
```
124+
feat/add-role-based-access
125+
fix/login-redirect-error
126+
docs/update-readme
127+
```
128+
129+
---
130+
131+
## 🙌 Need Help?
132+
133+
If you’re stuck or need clarification:
134+
- Open a **discussion** in the [GitHub Discussions](../../discussions) tab.
135+
- Or ask in the issue thread related to your contribution.
136+
137+
---
138+
139+
## 💬 Attribution
140+
141+
This project follows open-source best practices.
142+
Inspired by contributing guides from [Contributor Covenant](https://www.contributor-covenant.org/) and [GitHub Docs](https://docs.github.com/en/get-started/quickstart/contributing-to-projects).

API_DOCUMENTATION.md

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
# 🔐 RBAC API Documentation
2+
3+
## Authentication Endpoints
4+
5+
### POST /api/auth/register
6+
Register a new user in the system.
7+
8+
**Request Body:**
9+
```json
10+
{
11+
"username": "string",
12+
"email": "string",
13+
"fullname": "string",
14+
"password": "string"
15+
}
16+
```
17+
18+
**Response:**
19+
```json
20+
{
21+
"success": true,
22+
"message": "User registered successfully",
23+
"user": {
24+
"id": "user_id",
25+
"username": "username",
26+
"email": "email",
27+
"role": "User"
28+
}
29+
}
30+
```
31+
32+
### POST /api/auth/login
33+
Authenticate user and return access and refresh tokens.
34+
35+
**Request Body:**
36+
```json
37+
{
38+
"email": "string",
39+
"password": "string"
40+
}
41+
```
42+
43+
**Response:**
44+
```json
45+
{
46+
"success": true,
47+
"message": "Login successful",
48+
"accessToken": "jwt_access_token",
49+
"refreshToken": "jwt_refresh_token",
50+
"user": {
51+
"id": "user_id",
52+
"username": "username",
53+
"email": "email",
54+
"fullname": "fullname",
55+
"role": "User"
56+
}
57+
}
58+
```
59+
60+
### POST /api/auth/refresh
61+
Refresh access token using refresh token.
62+
63+
**Request Body:**
64+
```json
65+
{
66+
"refreshToken": "jwt_refresh_token"
67+
}
68+
```
69+
70+
**Response:**
71+
```json
72+
{
73+
"success": true,
74+
"message": "Token refreshed successfully",
75+
"accessToken": "new_jwt_access_token",
76+
"user": {
77+
"id": "user_id",
78+
"username": "username",
79+
"email": "email",
80+
"fullname": "fullname",
81+
"role": "User"
82+
}
83+
}
84+
```
85+
86+
### POST /api/auth/logout
87+
Logout user and invalidate refresh token.
88+
89+
**Request Body:**
90+
```json
91+
{
92+
"refreshToken": "jwt_refresh_token"
93+
}
94+
```
95+
96+
**Response:**
97+
```json
98+
{
99+
"success": true,
100+
"message": "Logged out successfully"
101+
}
102+
```
103+
104+
## Role Management Endpoints
105+
106+
### GET /api/roles
107+
Get all roles (requires authentication).
108+
109+
**Headers:**
110+
```
111+
Authorization: Bearer <access_token>
112+
```
113+
114+
**Response:**
115+
```json
116+
[
117+
{
118+
"_id": "role_id",
119+
"name": "Admin",
120+
"permissions": [
121+
{
122+
"_id": "permission_id",
123+
"name": "Manage Users",
124+
"description": "Admin can manage users"
125+
}
126+
]
127+
}
128+
]
129+
```
130+
131+
### POST /api/roles
132+
Create a new role (requires authentication).
133+
134+
**Headers:**
135+
```
136+
Authorization: Bearer <access_token>
137+
```
138+
139+
**Request Body:**
140+
```json
141+
{
142+
"name": "string",
143+
"permissions": ["permission_id_1", "permission_id_2"]
144+
}
145+
```
146+
147+
## Permission Management Endpoints
148+
149+
### GET /api/permissions
150+
Get all permissions (requires authentication).
151+
152+
**Headers:**
153+
```
154+
Authorization: Bearer <access_token>
155+
```
156+
157+
### POST /api/permissions
158+
Create a new permission (requires authentication).
159+
160+
**Headers:**
161+
```
162+
Authorization: Bearer <access_token>
163+
```
164+
165+
**Request Body:**
166+
```json
167+
{
168+
"name": "string",
169+
"description": "string"
170+
}
171+
```
172+
173+
## RBAC Test Endpoints
174+
175+
### GET /api/rbac-test/admin-only
176+
Test endpoint for Admin role only.
177+
178+
**Headers:**
179+
```
180+
Authorization: Bearer <access_token>
181+
```
182+
183+
**Response:**
184+
```json
185+
{
186+
"message": "Welcome, Admin"
187+
}
188+
```
189+
190+
### GET /api/rbac-test/user-only
191+
Test endpoint for User role only.
192+
193+
**Headers:**
194+
```
195+
Authorization: Bearer <access_token>
196+
```
197+
198+
**Response:**
199+
```json
200+
{
201+
"message": "Welcome, User"
202+
}
203+
```
204+
205+
## Error Responses
206+
207+
All endpoints return consistent error responses:
208+
209+
```json
210+
{
211+
"success": false,
212+
"message": "Error description"
213+
}
214+
```
215+
216+
Common HTTP status codes:
217+
- `400` - Bad Request
218+
- `401` - Unauthorized
219+
- `403` - Forbidden
220+
- `404` - Not Found
221+
- `500` - Internal Server Error
222+
223+
## Security Features
224+
225+
- **JWT Access Tokens**: Short-lived (1 day) for API access
226+
- **Refresh Tokens**: Long-lived (7 days) for token renewal
227+
- **Password Hashing**: bcrypt with salt rounds
228+
- **Role-Based Access Control**: Granular permissions
229+
- **Token Invalidation**: Secure logout mechanism

0 commit comments

Comments
 (0)