Skip to content

Dewick75/personal-finance-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’° Personal Finance Tracker

A modern, full-stack personal finance management application built with Next.js 15, TypeScript, and Supabase. Track your income, expenses, and financial goals with beautiful analytics and insights tailored for Sri Lankan users.

Finance Tracker TypeScript Supabase TailwindCSS React

🌟 Features

πŸ” Authentication System

  • User Registration & Login - Secure authentication with form validation using Zod schemas
  • Protected Routes - Automatic redirection for unauthorized access with ProtectedRoute component
  • Session Management - Persistent login state with localStorage and React Context
  • Professional UI - Clean, modern authentication forms with error handling
  • Demo Mode - Quick demo access for testing (email: any@email.com, password: 6+ chars)

πŸ“Š Financial Management

  • Transaction Tracking - Add, edit, delete income and expense transactions with full CRUD operations
  • Category Management - 40+ pre-defined Sri Lankan categories with emojis and color coding
  • Real-time Dashboard - Live financial overview with key metrics and recent transactions
  • Advanced Filtering - Filter transactions by type, category, date range, and description
  • Sri Lankan Context - LKR currency, local categories (Rice & Curry, CEB Bills, Dialog/Mobitel, etc.)
  • Data Validation - Form validation with Zod for data integrity and user experience

πŸ“ˆ Analytics & Insights

  • Interactive Charts - Beautiful pie charts and bar graphs using Recharts
  • Expense Breakdown - Visual representation of spending by category
  • Income Analysis - Track income sources and patterns
  • Monthly Trends - Historical data visualization for the last 6 months
  • Financial Summaries - Total income, expenses, and net balance

🎨 User Experience

  • Responsive Design - Optimized for desktop, tablet, and mobile devices
  • Modern UI Components - Custom-built components with TailwindCSS
  • Loading States - Smooth loading indicators and error handling
  • Sri Lankan Context - LKR currency and localized categories

πŸ› οΈ Tech Stack

Frontend

Backend & Database

  • Supabase - PostgreSQL database with real-time features and REST API
  • Supabase Auth - Authentication and user management with JWT
  • Supabase Auth Helpers - Next.js integration for seamless auth
  • Row Level Security (RLS) - Database-level security policies for data isolation
  • PostgreSQL - Robust relational database with ACID compliance

Development Tools

πŸš€ Getting Started

Prerequisites

  • Node.js 18+ and npm/yarn/pnpm
  • Supabase account and project

1. Clone the Repository

git clone https://github.com/yourusername/personal-finance-tracker.git
cd personal-finance-tracker

2. Install Dependencies

npm install
# or
yarn install
# or
pnpm install

3. Environment Setup

Create a .env.local file in the root directory:

NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key

4. Database Setup

Run the SQL scripts in your Supabase Dashboard β†’ SQL Editor in this order:

  1. Initial Setup: Execute database-setup.sql

    • Creates categories and transactions tables
    • Sets up Row Level Security (RLS) policies
    • Creates indexes for optimal performance
    • Inserts 40+ Sri Lankan categories
  2. RLS Policy Fixes (if needed): Execute fix-rls-policies.sql

    • Fixes any RLS policy issues for development
    • Allows demo data access
    • Configures proper user permissions

5. Start Development Server

npm run dev
# or
yarn dev
# or
pnpm dev

Open http://localhost:3000 to view the application.

πŸ“ Project Structure

personal-finance-tracker/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                    # Next.js 15 App Router pages
β”‚   β”‚   β”œβ”€β”€ analytics/         # Analytics dashboard with charts
β”‚   β”‚   β”‚   └── page.tsx       # Analytics page component
β”‚   β”‚   β”œβ”€β”€ dashboard/         # Main financial dashboard
β”‚   β”‚   β”‚   └── page.tsx       # Dashboard overview
β”‚   β”‚   β”œβ”€β”€ login/            # Authentication pages
β”‚   β”‚   β”‚   └── page.tsx      # Login form
β”‚   β”‚   β”œβ”€β”€ register/         # User registration
β”‚   β”‚   β”‚   └── page.tsx      # Registration form
β”‚   β”‚   β”œβ”€β”€ transactions/     # Transaction management
β”‚   β”‚   β”‚   β”œβ”€β”€ add/          # Add new transaction
β”‚   β”‚   β”‚   β”‚   └── page.tsx  # Transaction form
β”‚   β”‚   β”‚   β”œβ”€β”€ [id]/         # Dynamic transaction routes
β”‚   β”‚   β”‚   β”‚   └── edit/     # Edit transaction
β”‚   β”‚   β”‚   β”‚       └── page.tsx
β”‚   β”‚   β”‚   └── page.tsx      # Transaction list
β”‚   β”‚   β”œβ”€β”€ globals.css       # Global styles with Tailwind
β”‚   β”‚   β”œβ”€β”€ layout.tsx        # Root layout with providers
β”‚   β”‚   └── page.tsx          # Landing page
β”‚   β”œβ”€β”€ components/            # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ ui/               # Base UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ Button.tsx    # Custom button variants
β”‚   β”‚   β”‚   β”œβ”€β”€ Card.tsx      # Container component
β”‚   β”‚   β”‚   └── Input.tsx     # Form input with validation
β”‚   β”‚   β”œβ”€β”€ Header.tsx        # Navigation header
β”‚   β”‚   └── ProtectedRoute.tsx # Route protection HOC
β”‚   β”œβ”€β”€ contexts/             # React Context providers
β”‚   β”‚   └── AuthContext.tsx   # Authentication state management
β”‚   β”œβ”€β”€ lib/                  # Utility libraries
β”‚   β”‚   β”œβ”€β”€ supabase.ts      # Supabase client & database types
β”‚   β”‚   β”œβ”€β”€ utils.ts         # Helper functions
β”‚   β”‚   β”œβ”€β”€ validations.ts   # Zod validation schemas
β”‚   β”‚   └── sri-lankan-data.ts # Local data and constants
β”‚   └── types/               # TypeScript type definitions
β”‚       └── transaction.ts   # Transaction-related interfaces
β”œβ”€β”€ public/                   # Static assets
β”‚   β”œβ”€β”€ favicon.ico          # App favicon
β”‚   └── *.svg               # Icon assets
β”œβ”€β”€ database-setup.sql       # Initial database schema
β”œβ”€β”€ fix-rls-policies.sql    # RLS policy configurations
β”œβ”€β”€ package.json            # Dependencies and scripts
β”œβ”€β”€ tsconfig.json           # TypeScript configuration
β”œβ”€β”€ next.config.ts          # Next.js configuration
β”œβ”€β”€ postcss.config.mjs      # PostCSS configuration
β”œβ”€β”€ eslint.config.mjs       # ESLint configuration
└── README.md              # Project documentation

πŸ—„οΈ Database Schema

Categories Table

CREATE TABLE categories (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  name VARCHAR(100) NOT NULL,
  icon VARCHAR(10) NOT NULL,
  color VARCHAR(7) NOT NULL,
  type VARCHAR(10) CHECK (type IN ('income', 'expense')),
  created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

Transactions Table

CREATE TABLE transactions (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  user_id UUID REFERENCES auth.users(id) ON DELETE CASCADE,
  amount DECIMAL(12,2) NOT NULL CHECK (amount > 0),
  type VARCHAR(10) NOT NULL CHECK (type IN ('income', 'expense')),
  category_id UUID REFERENCES categories(id),
  description TEXT NOT NULL,
  date DATE NOT NULL,
  created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
  updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

πŸ”§ Key Components

Authentication Context

Manages user authentication state across the application:

  • Login/logout functionality
  • User session persistence
  • Protected route access control

Database Layer

Abstracted database operations with TypeScript:

  • CRUD operations for transactions
  • Category management
  • Analytics data aggregation
  • Type-safe database queries

UI Components

Reusable, accessible components:

  • Button: Multiple variants and sizes
  • Card: Consistent container styling
  • Input: Form inputs with validation
  • Header: Navigation with user context

πŸ“Š Analytics Features

Dashboard Metrics

  • Total income and expenses
  • Current balance calculation
  • Transaction count
  • Recent transactions list

Visual Analytics

  • Pie Charts: Expense and income breakdown by category
  • Bar Charts: Monthly trends over time
  • Category Lists: Detailed breakdown with percentages
  • Time Filtering: View data for different time periods

πŸ”’ Security Features

Authentication & Authorization

  • Form Validation - Client-side validation with Zod schemas and server-side verification
  • Password Security - Minimum 6 characters requirement with secure hashing
  • Session Management - JWT-based authentication with automatic token refresh
  • Protected Routes - Route-level protection with automatic redirects
  • User Context - Secure user state management with React Context API

Database Security

  • Row Level Security (RLS) - PostgreSQL RLS policies ensuring users only access their own data
  • User Isolation - UUID-based user identification with foreign key constraints
  • SQL Injection Prevention - Parameterized queries and Supabase client protection
  • Secure API Endpoints - Server-side validation and authentication checks
  • Data Encryption - Encrypted data transmission with HTTPS and secure storage

Privacy & Compliance

  • Data Minimization - Only collect necessary financial data
  • User Control - Users can delete their own transactions and data
  • Secure Storage - Encrypted database storage with Supabase infrastructure
  • No Third-party Tracking - Privacy-focused design without external analytics

🎨 Design System

Color Palette

  • Primary: Blue (#3B82F6)
  • Success: Green (#10B981)
  • Danger: Red (#EF4444)
  • Warning: Yellow (#F59E0B)
  • Neutral: Gray scale

Typography

  • Font: Geist Sans (Vercel's font family)
  • Headings: Bold, hierarchical sizing
  • Body: Regular weight, readable line height

Components

  • Consistent spacing using Tailwind's scale
  • Rounded corners and subtle shadows
  • Hover and focus states for interactivity
  • Mobile-first responsive design

πŸš€ Deployment

Vercel (Recommended)

  1. Connect Repository: Link your GitHub repository to Vercel
  2. Environment Variables: Add the following in Vercel dashboard:
    NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
    NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
    
  3. Auto Deploy: Automatic deployment on push to main branch
  4. Custom Domain: Configure custom domain in Vercel settings

Manual Deployment

# Build the application
npm run build

# Start production server
npm run start

# Or using PM2 for production
npm install -g pm2
pm2 start npm --name "finance-tracker" -- start

Docker Deployment

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]

πŸ§ͺ Testing

Running Tests

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

Test Structure

  • Unit Tests - Component and utility function testing
  • Integration Tests - API endpoint and database operation testing
  • E2E Tests - Full user workflow testing with Playwright

πŸ“Š Performance

Optimization Features

  • Next.js 15 - Latest performance optimizations and Turbopack
  • Image Optimization - Automatic image optimization with Next.js Image component
  • Code Splitting - Automatic code splitting for optimal loading
  • Static Generation - Pre-rendered pages for better performance
  • Database Indexing - Optimized database queries with proper indexing

Monitoring

  • Core Web Vitals - Optimized for Google's Core Web Vitals
  • Bundle Analysis - Regular bundle size monitoring
  • Database Performance - Query optimization and connection pooling

🀝 Contributing

We welcome contributions! Please follow these steps:

Development Setup

  1. Fork the repository and clone your fork
  2. Install dependencies: npm install
  3. Set up environment: Copy .env.example to .env.local
  4. Database setup: Run the SQL scripts in Supabase
  5. Start development: npm run dev

Contribution Guidelines

  1. Create a feature branch: git checkout -b feature/amazing-feature
  2. Follow code style: Use ESLint and Prettier configurations
  3. Write tests: Add tests for new features
  4. Update documentation: Update README if needed
  5. Commit changes: Use conventional commit messages
  6. Push to branch: git push origin feature/amazing-feature
  7. Open Pull Request: Provide clear description of changes

Code Style

  • Use TypeScript for all new code
  • Follow ESLint and Prettier configurations
  • Use meaningful variable and function names
  • Add JSDoc comments for complex functions
  • Maintain consistent file structure

πŸ› Troubleshooting

Common Issues

Database Connection Issues

# Check environment variables
echo $NEXT_PUBLIC_SUPABASE_URL
echo $NEXT_PUBLIC_SUPABASE_ANON_KEY

# Verify Supabase connection
npm run test:db

Build Errors

# Clear Next.js cache
rm -rf .next

# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install

# Check TypeScript errors
npm run type-check

Authentication Issues

  • Verify Supabase Auth is enabled
  • Check RLS policies are correctly configured
  • Ensure environment variables are set correctly

Version History

  • v0.1.0 - Initial release with basic transaction tracking
  • v0.2.0 - Added analytics and charts
  • v0.3.0 - Enhanced security and authentication
  • v1.0.0 - Production-ready release (planned)

οΏ½ Acknowledgments

  • Next.js - For the amazing React framework with App Router
  • Supabase - For the powerful backend infrastructure and PostgreSQL
  • TailwindCSS - For the utility-first CSS framework
  • Recharts - For the beautiful and responsive charting library
  • Lucide - For the comprehensive icon library
  • Vercel - For the seamless deployment platform
  • TypeScript - For type safety and developer experience
  • Sri Lankan Developer Community - For inspiration and local context

Demo a7 a1 a2 a3 a4 a5 a6

Supabase db1 db2 db3 db4

⭐ Star this repository if you found it helpful!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published