Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Finance Dashboard Backend

A RESTful backend API for a finance dashboard system with role-based access control, financial records management, and summary analytics.


Tech Stack

  • Runtime: Node.js
  • Framework: Express.js v4
  • Database: MongoDB Atlas
  • ODM: Mongoose
  • Auth: JWT (JSON Web Tokens)
  • Password Hashing: bcryptjs

Project Structure

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

Setup Instructions

1. Clone the repository

git clone <your-repo-url>
cd finance-dashboard-backend

2. Install dependencies

npm install

3. Create .env file in root

PORT=5000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret

4. Run the server

node server.js

Server runs on http://localhost:5000


Roles

Role Permissions
viewer View records, view summary
analyst View records, view all dashboard analytics
admin Full access — manage users, records, and all analytics

API Reference

Auth

Method Endpoint Access Description
POST /api/auth/register Public Register a new user
POST /api/auth/login Public Login and get token

Records

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

Dashboard

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

Users

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

Authentication

All protected routes require a Bearer token in the Authorization header: Authorization: Bearer <your_jwt_token>


Assumptions Made

  • 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.

Error Handling

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.


Sample Request — Register

POST /api/auth/register
{
  "name": "Prajwal Singh",
  "email": "prajwal@gmail.com",
  "password": "123456",
  "role": "admin"
}

Sample Response

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "id": "69d16104b586dfd5f94975ae",
    "name": "Prajwal Singh",
    "email": "prajwal@gmail.com",
    "role": "admin"
  }
}

About

Backend assignment for finance dashboard using Node.js, Express, MongoDB and JWT

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages