Skip to content

pragya238/Finance_Track

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’° Smart Finance Tracker Dashboard

A production-style full-stack finance tracker with role-based access control, JWT authentication, and a clean React frontend.


πŸ—οΈ Project Structure

smart-finance-tracker/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ controllers/        # Route handlers (thin layer, calls services)
β”‚   β”‚   β”œβ”€β”€ authController.js
β”‚   β”‚   β”œβ”€β”€ transactionController.js
β”‚   β”‚   β”œβ”€β”€ dashboardController.js
β”‚   β”‚   └── userController.js
β”‚   β”œβ”€β”€ routes/             # Express route definitions
β”‚   β”‚   β”œβ”€β”€ authRoutes.js
β”‚   β”‚   β”œβ”€β”€ transactionRoutes.js
β”‚   β”‚   β”œβ”€β”€ dashboardRoutes.js
β”‚   β”‚   └── userRoutes.js
β”‚   β”œβ”€β”€ models/             # Mongoose schemas
β”‚   β”‚   β”œβ”€β”€ User.js
β”‚   β”‚   └── Transaction.js
β”‚   β”œβ”€β”€ middleware/         # Express middleware
β”‚   β”‚   β”œβ”€β”€ authMiddleware.js     # JWT protect + authorize(roles)
β”‚   β”‚   β”œβ”€β”€ validationMiddleware.js
β”‚   β”‚   └── errorHandler.js
β”‚   β”œβ”€β”€ services/           # Business logic (keep controllers thin)
β”‚   β”‚   β”œβ”€β”€ authService.js
β”‚   β”‚   β”œβ”€β”€ transactionService.js
β”‚   β”‚   └── dashboardService.js
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”œβ”€β”€ db.js           # MongoDB connection
β”‚   β”‚   β”œβ”€β”€ jwtHelper.js    # Token generation/verification
β”‚   β”‚   └── responseHelper.js   # Consistent API responses
β”‚   β”œβ”€β”€ server.js
β”‚   β”œβ”€β”€ package.json
β”‚   └── .env.example
β”‚
└── frontend/
    β”œβ”€β”€ public/
    β”‚   └── index.html
    └── src/
        β”œβ”€β”€ context/
        β”‚   └── AuthContext.js   # Global auth state (React Context)
        β”œβ”€β”€ services/
        β”‚   └── api.js           # Axios instance + all API calls
        β”œβ”€β”€ components/
        β”‚   β”œβ”€β”€ Sidebar.js
        β”‚   └── AddTransactionModal.js
        β”œβ”€β”€ pages/
        β”‚   β”œβ”€β”€ LoginPage.js
        β”‚   β”œβ”€β”€ RegisterPage.js
        β”‚   β”œβ”€β”€ DashboardPage.js
        β”‚   β”œβ”€β”€ TransactionsPage.js
        β”‚   β”œβ”€β”€ InsightsPage.js
        β”‚   └── UsersPage.js
        β”œβ”€β”€ App.js
        β”œβ”€β”€ index.js
        └── index.css

βš™οΈ Tech Stack

Layer Technology
Backend Node.js, Express.js
Database MongoDB + Mongoose
Auth JWT + bcryptjs
Validation express-validator
Frontend React 18, Axios

πŸš€ Running Locally

Prerequisites

  • Node.js v18+ installed
  • MongoDB running locally on port 27017 (or a MongoDB Atlas URI)

Step 1 β€” Clone / set up the project

# If using this as a folder, navigate into it
cd smart-finance-tracker

Step 2 β€” Set up the Backend

cd backend

# Install dependencies
npm install

# Create your .env file from the example
cp .env.example .env

Edit .env with your values:

PORT=5000
MONGO_URI=mongodb://localhost:27017/smart-finance-tracker
JWT_SECRET=change_this_to_a_long_random_secret
JWT_EXPIRES_IN=7d
# Start the backend (development mode with auto-reload)
npm run dev

# Or in production mode
npm start

The API will be running at: http://localhost:5001


Step 3 β€” Set up the Frontend

cd ../frontend

# Install dependencies
npm install

# Start the React dev server
npm start

The app will open at: http://localhost:3000

The "proxy": "http://localhost:5000" in frontend/package.json routes all /api/... calls to the backend automatically.


πŸ‘₯ Role Permissions

Action Viewer Analyst Admin
View dashboard βœ… βœ… βœ…
View transactions βœ… βœ… βœ…
Create transactions ❌ βœ… βœ…
Update transactions ❌ βœ… βœ…
Delete transactions ❌ ❌ βœ…
View insights ❌ βœ… βœ…
Manage users (CRUD) ❌ ❌ βœ…

πŸ“¦ MongoDB Schema Design

User

{
  name:      String (required, max 50)
  email:     String (required, unique, lowercase)
  password:  String (required, hashed, min 6)
  role:      String (enum: viewer | analyst | admin, default: viewer)
  isActive:  Boolean (default: true)
  createdAt: Date
  updatedAt: Date
}

Transaction

{
  user:        ObjectId β†’ ref: User
  amount:      Number (required, min 0.01)
  type:        String (enum: income | expense)
  category:    String (enum: salary | food | transport | ...)
  description: String (optional, max 200)
  date:        Date (required)
  createdAt:   Date
  updatedAt:   Date
}

πŸ”— API Endpoints

Auth

Method Endpoint Access Description
POST /api/auth/register Public Register new user
POST /api/auth/login Public Login, get JWT
GET /api/auth/me All users Get own profile

Transactions

Method Endpoint Access Description
GET /api/transactions All users List (filter by params)
POST /api/transactions Analyst + Admin Create transaction
GET /api/transactions/:id All users Get single transaction
PUT /api/transactions/:id Analyst + Admin Update transaction
DELETE /api/transactions/:id Admin only Delete transaction

Dashboard

Method Endpoint Access Description
GET /api/dashboard All users Summary stats
GET /api/dashboard/insights Analyst + Admin Deep category insights

Users (Admin only)

Method Endpoint Access Description
GET /api/users Admin only List all users
GET /api/users/:id Admin only Get user by ID
PUT /api/users/:id Admin only Update role/status
DELETE /api/users/:id Admin only Delete user

πŸ” Transaction Filter Query Params

GET /api/transactions?type=expense&category=food&startDate=2024-01-01&endDate=2024-12-31&limit=20
Param Example Description
type income / expense Filter by type
category food Filter by category
startDate 2024-01-01 From date (ISO)
endDate 2024-12-31 To date (ISO)
limit 20 Max results (default 100)

πŸ” Authentication

All protected routes require:

Authorization: Bearer <your_jwt_token>

The JWT is returned from /api/auth/register and /api/auth/login.


βœ… Architecture Decisions

  • MVC Pattern: Routes β†’ Controllers β†’ Services β†’ Models. Controllers are thin β€” all business logic lives in services.
  • Middleware chain: protect verifies JWT β†’ authorize(roles) checks role β†’ validateX validates body β†’ controller runs.
  • Consistent responses: All endpoints return { success, message, data } via responseHelper.js.
  • Password security: bcrypt with salt rounds of 12. Password field excluded from queries by default (select: false).
  • MongoDB indexes: Transactions indexed on (user, date), (user, type), (user, category) for fast dashboard aggregations.

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors