This is a complete backend system built for a finance dashboard application. It provides user management, record management, dashboard summaries, and role-based access control.
- Node.js & Express: API Framework
- MongoDB & Mongoose: NoSQL database and ODM for robust data modeling.
- JWT (
jsonwebtoken): Authentication and Authorization. - Bcrypt: Password hashing.
- Joi: Input Validation.
-
Install Dependencies ```bash npm install ```
-
Environment Variables ``` PORT = 3000 , JWT_SECRET = ghf6876sdsdas26721fsfas26762sgfas27627 , JWT_EXPIRES_IN = 24h , MONGO_URI = mongodb://127.0.0.1:27017/finance_assessment . ```
-
Start the Server ```bash npm start ```
POST /api/auth/registerRegister a new user. Body:{"name": "...", "email": "...", "password": "..."}Response contains the JWT token. Pass it via headers:Authorization: Bearer <token>GET /api/auth/me- Get current logged in user profile.PUT /api/auth/me- Update name, email, or password.
GET /api/users- List all users.PUT /api/users/:id/role- Update a user's role. Body:{"role": "Analyst"}(Role options: Viewer, Analyst, Admin)PUT /api/users/:id/status- Toggle user active/inactive status.
POST /api/records(Admin Only) Body:{"amount": 100, "type": "income", "category": "Salary", "date": "2024-03-01", "notes": ""}GET /api/records(Admin, Analyzer) Supports Advanced Filtering Query Params:type:income|expensecategory: String (e.g.Salary,Food)startDate/endDate: ISO Date strings (YYYY-MM-DD)limit/offset: For pagination (default: 10/0)
GET /api/records/:id(Admin, Analyst)PUT /api/records/:id(Admin Only)DELETE /api/records/:id(Admin Only)
GET /api/dashboard/summary(All roles) Returns:- Summary: Total Income, Total Expenses, Net Balance.
- Category Spread: Aggregated totals per category.
- Monthly Trends: Income vs Expense breakdown for the last 6 months.
- Recent Activity: The 5 most recent transactions.