A RESTful backend API for a finance dashboard system with role-based access control, financial records management, and summary analytics.
- Runtime: Node.js
- Framework: Express.js v4
- Database: MongoDB Atlas
- ODM: Mongoose
- Auth: JWT (JSON Web Tokens)
- Password Hashing: bcryptjs
finance-dashboard-backend/
├── src/
│ ├── config/
│ │ └── db.js
│ ├── controllers/
│ │ ├── authController.js
│ │ ├── dashboardController.js
│ │ ├── recordController.js
│ │ └── userController.js
│ ├── middleware/
│ │ ├── authMiddleware.js
│ │ └── roleMiddleware.js
│ ├── models/
│ │ ├── Record.js
│ │ └── User.js
│ └── routes/
│ ├── authRoutes.js
│ ├── dashboardRoutes.js
│ ├── recordRoutes.js
│ └── userRoutes.js
├── app.js
├── server.js
├── package.json
└── README.md
git clone <your-repo-url>
cd finance-dashboard-backendnpm installPORT=5000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secretnode server.jsServer runs on http://localhost:5000
| Role | Permissions |
|---|---|
| viewer | View records, view summary |
| analyst | View records, view all dashboard analytics |
| admin | Full access — manage users, records, and all analytics |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /api/auth/register |
Public | Register a new user |
| POST | /api/auth/login |
Public | Login and get token |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| GET | /api/records |
All roles | Get all records |
| GET | /api/records/:id |
All roles | Get single record |
| GET | /api/records?type=income |
All roles | Filter by type |
| GET | /api/records?category=salary |
All roles | Filter by category |
| GET | /api/records?startDate=&endDate= |
All roles | Filter by date range |
| POST | /api/records |
Analyst, Admin | Create a record |
| PUT | /api/records/:id |
Admin | Update a record |
| DELETE | /api/records/:id |
Admin | Delete a record |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| GET | /api/dashboard/summary |
All roles | Total income, expenses, net balance |
| GET | /api/dashboard/categories |
Analyst, Admin | Category-wise totals |
| GET | /api/dashboard/trends |
Analyst, Admin | Monthly trends |
| GET | /api/dashboard/recent |
Analyst, Admin | Recent 10 transactions |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| GET | /api/users |
Admin | Get all users |
| GET | /api/users/:id |
Admin | Get single user |
| PATCH | /api/users/:id/role |
Admin | Update user role |
| PATCH | /api/users/:id/status |
Admin | Update user status |
| DELETE | /api/users/:id |
Admin | Delete user |
All protected routes require a Bearer token in the Authorization header: Authorization: Bearer <your_jwt_token>
- Any user can self-register with a role. In production this would be restricted — only admins would assign roles.
- Soft delete is not implemented; records and users are hard deleted.
- Financial records are not scoped per user — all authenticated users can view all records, simulating a shared finance dashboard.
- The analyst role can create records but not update or delete them.
All endpoints return consistent JSON error responses:
{
"message": "Description of the error"
}Standard HTTP status codes are used throughout — 200, 201, 400, 401, 403, 404, 500.
POST /api/auth/register
{
"name": "Prajwal Singh",
"email": "prajwal@gmail.com",
"password": "123456",
"role": "admin"
}{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "69d16104b586dfd5f94975ae",
"name": "Prajwal Singh",
"email": "prajwal@gmail.com",
"role": "admin"
}
}