This is the backend implementation for the Finance Dashboard system designed for the Zorvyn internship screening assignment.
- Engine: Node.js
- Framework: Express.js
- Database: MongoDB
- ODM: Mongoose
- Authentication: JSON Web Tokens (JWT)
- Validation: express-validator
- Security: bcryptjs (for password hashing)
- Feature: Role-based access control with
Viewer,Analyst, andAdminroles. - Architecture: Uses JWT for stateless authentication. Passwords are encrypted using bcrypt. User status (Active/Inactive) is supported to revoke access globally.
- Endpoints:
POST /api/v1/auth/register- Create a new user account (Can specify a role, default is Viewer)POST /api/v1/auth/login- Exchange email & password for a JWT token.
- Feature: Complete CRUD operations for financial records. Models include essential fields:
amount,type(income/expense),category,date,notes, andcreatedBy. - Architecture: Implements advanced query features natively (e.g.
?limit=10&page=2&sort=-date&type=income). - Endpoints:
GET /api/v1/records- List records (with filters & pagination)GET /api/v1/records/:id- Get single recordPOST /api/v1/records- Create a new recordPATCH /api/v1/records/:id- Update an existing recordDELETE /api/v1/records/:id- Remove a record
- Feature: High-level aggregated data for frontend dashboards.
- Architecture: Uses MongoDB Aggregation Framework for rapid, database-level aggregation of net balance, totals, and category breakdowns.
- Endpoints:
GET /api/v1/summary- Retrieves total income, total expense, net balance, categorized limits, and the most recent 5 activities.
- Implementation: Express middlewares handle JWT validation (
protect) and role-based restrictions (restrictTo).- Admin: Can create, read, update, and delete records. Appointed full access.
- Analyst: Can view all records and financial summaries. Cannot modify or delete records.
- Viewer: Can only view the highest-level dashboard summary data. Cannot access granular record endpoints.
- Validation: Uses
express-validatorto protect the/api/v1/recordsPOST endpoint preventing malformed inserts. - Error Handling: Implemented a global Express error handler
errorHandler.jshandling async errors gracefully, abstracting complex MongoDB error states (like CastError, DuplicateKey) into readable 400 requests.
- Dependencies:
npm install
- Environment Variables:
Copy the
.env.exampleto.envand assign your MongoDB connection string toMONGODB_URI.cp .env.example .env
- Run Application:
npm start # Or node server.js
By default, the server runs on Port 5000.
- Authentication is strictly JWT based.
- Registration currently allows assigning your own level for ease of demonstration, whereas for production this would strictly be an Admin-only path.
- Summary data does not enforce strict multi-tenancy limits for demonstration purposes (you might want Admins to only see organizational data, whilst basic users only see their own - here, all validated users share a pool of organizational documents).