Skip to content

Repository files navigation

Expense Tracker with Approval Workflow

A REST API project for managing employee expenses with authentication, role-based authorization, approval workflows, department budgets, filtering, and finance reporting.

Developed using Node.js, Express.js, TypeScript, MongoDB Atlas, Mongoose, JWT Authentication, and bcrypt.

# Quick Start

git clone https://github.com/ARYAN0-work/Expense-Tracker-with-Approvals.git

cd Expense-Tracker-with-Approvals

pnpm install

pnpm seed

pnpm dev

Live Demo

Base URL

https://expense-tracker-with-approvals.onrender.com/api/v1


Source Code

GitHub Repository

https://github.com/ARYAN0-work/Expense-Tracker-with-Approvals

Features

Authentication

  • User Registration
  • User Login
  • JWT Authentication
  • Password Hashing (bcrypt)
  • Protected Routes
  • Role Based Authorization

User Roles

Employee

  • Create Draft Expense
  • Edit Draft Expense
  • Delete Draft Expense
  • Submit Expense
  • View Own Expenses
  • Reopen Rejected Expense

Manager

  • View Department Expenses
  • Approve Submitted Expenses
  • Reject Submitted Expenses
  • Cannot Approve Own Expenses
  • Cannot Reject Own Expenses

Finance

  • Read-only access to expenses
  • Department Budget Usage
  • Department Filtering
  • Organization-wide visibility

Expense Management

  • Create Expense
  • Update Draft Expense
  • Delete Draft Expense
  • Submit Expense
  • Get Expense by ID
  • Get All Expenses
  • Filtering
  • Pagination
  • Sorting

Expense Lifecycle

Draft
   │
   ▼
Submitted
   │
   ├────────► Approved
   │
   └────────► Rejected
                    │
                    ▼
                 Reopened
                    │
                    ▼
                  Draft

Business Rules

Employee

  • Can edit only Draft expenses
  • Can delete only Draft expenses
  • Can submit only Draft expenses
  • Can reopen only Rejected expenses
  • Can access only their own expenses

Manager

  • Can approve only Submitted expenses
  • Can reject only Submitted expenses
  • Cannot approve/reject own expenses
  • Limited to their department

Finance

  • Read-only access
  • Cross-department visibility
  • Budget tracking

🛠 Tech Stack

  • Node.js
  • Express.js
  • TypeScript
  • MongoDB Atlas
  • Mongoose
  • JWT
  • bcrypt
  • pnpm
  • Husky
  • Prettier
  • Render

Project Structure

src
│
├── common
│   └── errors
│
├── config
├── db
│
├── modules
│   ├── auth
│   ├── department
│   ├── expense
│   └── user
│
├── seed
│
├── app.ts
└── server.ts

Running Locally

1. Clone Repository

git clone https://github.com/ARYAN0-work/Expense-Tracker-with-Approvals.git
cd Expense-Tracker-with-Approvals

2. Install Dependencies

pnpm install

3. Environment Variables

Create a .env

PORT=5000

MONGO_URI=<your_mongodb_connection_string>

JWT_SECRET=<your_secret_key>

JWT_EXPIRES_IN=7d

4. Seed Database

pnpm seed

This creates

  • Departments
  • Employee User
  • Manager User
  • Finance User
  • Draft Expense
  • Submitted Expense
  • Approved Expense
  • Rejected Expense

5. Start Development Server

pnpm dev

Production Build

pnpm build
pnpm start

Seeded Test Accounts

Role Email Password
Employee employee@example.com Password123!
Manager manager@example.com Password123!
Finance finance@example.com Password123!

API Endpoints

Authentication

Method Endpoint
POST /auth/register
POST /auth/login

Employee

Method Endpoint
POST /expenses
GET /expenses
GET /expenses/:id
PATCH /expenses/:id
DELETE /expenses/:id
PATCH /expenses/:id/submit
PATCH /expenses/:id/reopen

Manager

Method Endpoint
GET /manager/expenses
PATCH /manager/expenses/:id/approve
PATCH /manager/expenses/:id/reject

Finance

Method Endpoint
GET /finance/expenses
GET /finance/budget/:departmentId

🔍 Supported Filters

  • Status
  • Category
  • Date Range
  • Amount Range
  • Department (Finance)
  • Pagination
  • Sorting

Expense Model

Each expense contains

  • Title
  • Amount
  • Currency
  • Category
  • Description
  • Employee
  • Department
  • Status
  • Approved By
  • Receipt URL
  • Notes
  • Rejection Reason

Security

Implemented

  • JWT Authentication
  • Password Hashing
  • Protected Routes
  • Role Based Authorization
  • Ownership Validation
  • Department Isolation
  • Business Rule Validation
  • Input Validation

Budget Tracking

Department budget usage is calculated using MongoDB Aggregation.

Returns

  • Budget
  • Approved Spending
  • Remaining Budget

HTTP Status Codes

Code Meaning
200 OK
201 Created
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
409 Conflict
422 Unprocessable Entity
500 Internal Server Error

API Documentation

The repository includes an exported Insomnia Collection.

Import the provided Expense-Tracker-with-Approvals.yaml file into Insomnia. The collection includes all tested endpoints and a pre-configured Base Environment for the deployed API.


Deployment

  • Hosting: Render
  • Database: MongoDB Atlas

Author

Aryan Mishra

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages