A robust, enterprise-grade RESTful API developed for the GDG Backend Task. This system provides a secure environment for managing personal notes with multi-user support, strict data ownership, and Role-Based Access Control (RBAC).
- User Registration & Login: Integrated authentication flow using JWT (JSON Web Tokens).
- Password Security: State-of-the-art hashing using
bcryptjsto ensure data protection. - Secure Token Issuance: Stateless session management with expiring access tokens.
- Full CRUD Support: Create, Read, Update, and Delete operations for personal notes.
- Data Integrity: Each note automatically tracks
id,title,content,created_at, andupdated_at. - Ownership Enforcement: Users are restricted to accessing and managing only their own data.
- Granular Roles: Support for
userandadminroles. - Admin Privileges: Administrative users can monitor all system activity, view every note, and perform system-wide deletions.
- Standardized Responses: Consistent use of HTTP status codes (200, 201, 204, 400, 401, 403, 404, 500).
- Input Validation: Robust request validation powered by Zod.
- Centralized Error Handling: Sophisticated error management for handling invalid tokens, missing fields, and resource conflicts.
| Category | Technology |
|---|---|
| Framework | Express.js |
| Language | TypeScript |
| ORM | Prisma |
| Database | SQLite |
| Validation | Zod |
| Auth | JWT & Bcrypt |
| Documentation | Swagger UI |
- Node.js: v18.0.0 or higher
- npm: v9.0.0 or higher
Create a .env file in the root directory and configure the following variables:
PORT=5000
JWT_SECRET=your_secure_random_secret_key
DATABASE_URL="file:./prisma/dev.db"# Install dependencies
npm install
# Initialize the database and generate Prisma Client
npx prisma db pushRuns the server with hot-reload enabled via ts-node-dev.
npm run devThe server will be accessible at http://localhost:5000
Interactive documentation with "Try it out" capabilities is built-in:
- Swagger UI: http://localhost:5000/api-docs
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /api/auth/register |
Register a new user (user or admin) |
No |
| POST | /api/auth/login |
Authenticate and retrieve JWT | No |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /api/notes |
List notes (supports search, page, limit) |
Yes |
| POST | /api/notes |
Create a new note | Yes |
| GET | /api/notes/:id |
Retrieve a specific note | Yes |
| PATCH | /api/notes/:id |
Update an existing note | Yes |
| DELETE | /api/notes/:id |
Delete a specific note | Yes |
curl -X POST http://localhost:5000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com", "password": "password123", "role": "user"}'curl -X POST http://localhost:5000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"email": "admin@example.com", "password": "adminpassword", "role": "admin"}'curl -G http://localhost:5000/api/notes \
-H "Authorization: Bearer <YOUR_JWT_TOKEN>" \
-d "search=project" \
-d "page=1" \
-d "limit=5"curl -X PATCH http://localhost:5000/api/notes/1 \
-H "Authorization: Bearer <YOUR_JWT_TOKEN>" \
-H "Content-Type: application/json" \
-d '{"title": "Updated Title", "content": "Updated content body"}'Verified for GDG Backend Task Requirements.