Skip to content

100NikhilBro/ExpenseSync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

326 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💸 ExpenseSync

A production-ready full-stack expense management platform for shared group spending

ExpenseSync simplifies shared group expenses, tracks individual balances, and computes minimal settlements automatically. Unlike typical tutorial clones, it features a **robust backend, normalized relational DB schema, caching, and monitoring** for real-world scalability.


📸 Screenshots

Dashboard View Group Overview

Expense List Settlement View

Expense Details


🛠️ Tech Stack

Layer Technologies
Frontend React, TypeScript, Tailwind CSS, Framer Motion, Lucide Icons, Sonner
State Management TanStack Query, Context API
Backend Node.js, Express, TypeScript
ORM Prisma
Database PostgreSQL (Normalized schema)
Cache Redis (Caching & Rate-limiting)
Authentication Supabase (OAuth / Email, no passwords stored locally)
Email Service Resend (Transactional emails)
Monitoring UptimeRobot (API uptime)
Deployment Vercel (Frontend), Render (Backend)

✨ Core Features

Feature Description Status
User Authentication Secure login via Supabase OAuth & email; fully protected API routes; no passwords stored locally
Group Management Create/manage groups, enforce access control, track membership history
Expense Tracking Add expenses with precise per-user splits, floating-point accuracy, and categories
Settlement Engine Automatic minimal settlement computation; supports partial settlements & history tracking
Security & Validation Input validation, sanitization, rate-limiting; prevents abuse & ensures data consistency
Production Deployment Frontend & backend deployed with environment-based configs; caching & monitoring enabled

🏗️ System Architecture

ExpenseSync System Architecture Diagram

  • Frontend (Client): React + TypeScript application responsible for UI rendering, routing, and server-state management using TanStack Query. The client authenticates users via Supabase Auth and sends authenticated API requests to the backend.
  • Backend (Server): Express + TypeScript server that processes incoming requests through a layered architecture consisting of middleware, controllers, and services.
  • Middleware Layer: Performs request validation, input sanitization, HTTP parameter pollution prevention, and authentication checks before forwarding requests to controllers.
  • Controller Layer: Acts as the routing layer, delegating requests to domain-specific services such as Group, Expense, Settlement, Profile, and Dashboard.
  • Service Layer: Contains core business logic including expense calculations, balance aggregation, settlement generation, and group management. Services interact with Redis for caching and PostgreSQL for persistent storage.
  • Cache & Rate Limiting: Redis is used for caching frequently accessed data and enforcing rate limits. On cache HIT, data is returned directly; on cache MISS, data is fetched from PostgreSQL and cached. Cache invalidation is handled on write operations.
  • Database: PostgreSQL accessed via Prisma ORM, using a normalized relational schema for users, groups, members, expenses, expense splits, and settlements.
  • Authentication Service: Supabase acts as an external identity provider, handling user authentication and token issuance, while the backend verifies tokens and enforces authorization rules.
  • Email Service: Resend is used for sending transactional emails such as group invitation links. Email sending is triggered from the service layer as an external, asynchronous operation.
  • Monitoring: UptimeRobot is used to monitor backend API availability and uptime in production.

🗄️ Database Design

ExpenseSync Database ER Diagram

  • Users: Central entity storing user info.
  • Groups: Represents shared expense groups.
  • MembersOnGroups: Many-to-many relationship preserving membership history.
  • Expenses: Core expense records including payer, amount, category, and time.
  • ExpenseSplit: Stores per-member expense splits.
  • Settlements: Tracks transactions that settle debts between members.

This normalized structure ensures **accuracy, consistency, and scalable settlement computation**.


🧮 Settlement Logic

ExpenseSync converts all group expenses into clear balances and computes **minimal transactions** to settle debts.

Example Workflow

Group: Amit, Rahul, Neha, Priya. Expenses: Amit ₹4000 (hotel), Rahul ₹2000 (food), Neha & Priya ₹0.

Step 1: Compute Total Shares

Total spent: ₹6000 → Each member’s share = ₹1500

Step 2: Net Balances

  • Amit: +₹2500 (creditor)
  • Rahul: +₹500 (creditor)
  • Neha: −₹1500 (debtor)
  • Priya: −₹1500 (debtor)

Step 3: Generate Minimal Settlements

  • Neha pays Amit ₹1500
  • Priya pays Amit ₹1000
  • Priya pays Rahul ₹500

✅ All balances zeroed. Supports **arbitrary splits, floating-point precision, and partial settlements**.

Settlement Logic Example


🚀 Deployment & Monitoring

  • Frontend: Vercel — React + TypeScript application with environment-based configs
  • Backend: Render — Express API with production settings & environment variables
  • Monitoring: UptimeRobot (API availability), Redis caching for fast responses

💡 Why ExpenseSync is Advanced

  • Normalized relational database ensures data consistency and prevents duplication
  • Greedy settlement algorithm minimizes number of transactions
  • Supports partial settlements and maintains historical data
  • Redis caching & rate-limiting enhance performance and security
  • Supabase handles authentication; backend never stores passwords
  • Production-ready deployment & monitoring included out-of-the-box

Made with ❤️ by Nikhil Gupta

About

A full-stack expense management app for shared group spending with automated settlements.

Resources

Stars

Watchers

Forks

Contributors

Languages