SpendWise is a modern, mobile-friendly web application designed to help users track their expenses, analyze spending patterns, and receive AI-powered financial advice. Built with Next.js 14 and TypeScript, it provides a comprehensive solution for personal finance management with an intuitive user interface and powerful analytics.
- Core Features
- Technical Architecture
- Key Features
- API Endpoints
- Setup Guide
- Future Enhancements
- AWS Deployment Architecture
- Add Transactions: Simple form to record income and expenses
- Categorization: 12 predefined categories (groceries, rent, utilities, dining, transportation, entertainment, shopping, healthcare, salary, freelance, investments, other)
- Real-time Validation: Zod-based validation for data integrity
- Spending Overview: Real-time financial summary with income, expenses, and savings
- Visual Analytics: Three interactive chart types:
- Pie Chart: Category-based spending breakdown
- Bar Chart: Weekly spending trends
- Area Chart: Monthly financial trends (income vs expenses vs savings)
- Summary Statistics: Total transactions, savings rate, and financial health indicators
- Conversational Interface: Chat-based AI advisor powered by OpenAI GPT-4o-mini
- Context-Aware Advice: Tailored financial guidance based on spending categories
- Professional Guidance: Expert-level financial advice in accessible language
- Advanced Search: Search by description, category, or transaction type
- Filtering Options: Filter by category or type (income/expense)
- Pagination: Efficient handling of large transaction datasets
- Summary Statistics: Filtered results with financial summaries
- Framework: Next.js 14 (App Router)
- Language: TypeScript
- Styling: Tailwind CSS with custom design system
- UI Components: Custom components with Lucide React icons
- Charts: Recharts library for data visualization
- State Management: React hooks (useState, useEffect)
- Runtime: Node.js 18.18.0
- API: Next.js API Routes
- ORM: Sequelize with PostgreSQL
- Validation: Zod schemas for type-safe validation
- AI Integration: OpenAI API (GPT-4o-mini)
- Primary Database: PostgreSQL
- Schema: Single
transactionstable - Connection Pooling: Sequelize built-in connection management
- Seed Data: Pre-populated with realistic 2024 transaction data
The dashboard provides comprehensive financial insights through multiple visualization types:
-
Financial Summary Cards:
- Total Income (current month)
- Total Expenses (current month)
- Net Savings (calculated)
-
Category Spending (Pie Chart):
- Visual breakdown of expenses by category
- Color-coded segments for easy identification
- Percentage and absolute value display
-
Weekly Trends (Bar Chart):
- Day-by-day spending patterns
- Identifies high-spending days
- Helps with weekly budget planning
-
Monthly Trends (Area Chart):
- Income vs expenses over time
- Savings trend visualization
- Long-term financial health tracking
The AI advisor is specifically trained for financial guidance:
- Spending Pattern Analysis: Understands the 12 transaction categories
- Budgeting Advice: Provides actionable saving strategies
- Financial Education: Explains concepts in beginner-friendly terms
- Goal Setting: Helps establish and track financial objectives
- Habit Building: Encourages healthy financial behaviors
POST /api/transactions- Create new transactionGET /api/transactions/search- Search and filter transactions
POST /api/ai-advisor- Get AI financial advice
POST /api/transactions
Content-Type: application/x-www-form-urlencoded
{
amount: "150.00",
category: "groceries",
description: "Weekly grocery shopping",
type: "expense",
date: "2024-01-15"
}GET /api/transactions/search?searchTerm=groceries&category=groceries&type=expensePOST /api/ai-advisor
Content-Type: application/json
{
"message": "How can I reduce my dining expenses?",
"conversation_id": "optional-conversation-id"
}- Node.js 18.18.0+
- PostgreSQL 12+ installed and running locally
- npm 9.0.0+
- Next.js app dependencies installed (
npm install)
Install dependencies from package.json locally.
npm installDatabase setup must be done manually on your local environment.
This guide will help you set up PostgreSQL for your SpendWise application.
Make sure PostgreSQL is running on your local machine.
Connect to PostgreSQL and create the spendwise database:
# Connect to PostgreSQL as superuser
psql -U postgres
# Create the spendwise database
CREATE DATABASE spendwise;
# Connect to the new database
\c spendwise
# Exit psql
\qExecute the provided SQL script to create the transactions table and insert seed data:
# Run the SQL script
psql -U postgres -d spendwise -f app/lib/schema.sqlWhat this script does:
- Creates the
transactionstable with proper schema - Inserts sample transaction data (2024 data from January to October)
- Sets up proper data types and constraints
Create a .env.local file in your project root with the following variables:
# Database Configuration (REQUIRED)
DATABASE_URL="postgresql://username:password@localhost:5432/spendwise"
# Optional: Database connection pool settings
DB_POOL_MIN=2
DB_POOL_MAX=10
# App Configuration
NODE_ENV=development
#OpenAI API Key
OPENAI_API_KEY=your_api_key_here
Replace the values:
username: Your PostgreSQL username (usuallypostgres)password: Your PostgreSQL passwordlocalhost:5432: Your PostgreSQL host and port (default)spendwise: Your database name
Start your application to test the database connection:
npm run devVisit http://localhost:3000 to see your dashboard with seed Data.
With this setup, you now have:
- Sequelize ORM - Type-safe database operations
- Real-time Calculations - Charts update with database data
- Transaction Management - Add, view, and filter transactions
- Performance Optimized - Server-side rendering with fresh data
- Scalable Architecture - Easy to add more features
- User Authentication: Multi-user support with secure authentication
- Data Export: CSV/PDF export functionality
- Budget Goals: Set and track spending goals
- Recurring Transactions: Automatic recurring transaction handling
- Receipt Upload: Image-based transaction creation
- Voice Input: Voice-to-text transaction entry
- Advanced Analytics: More sophisticated financial insights
- Investment Tracking: Portfolio and investment management
- Customize Categories - Modify the seed data in
./schema.sql
The following diagram shows how SpendWise would be deployed on AWS using a containerized, scalable architecture:
graph TB
subgraph "AWS Cloud"
subgraph "Global Infrastructure"
R53[Route 53<br/>DNS & Health Checks]
CF[CloudFront<br/>Global CDN]
end
subgraph "Compute Layer"
AG[API Gateway<br/>Request Management]
ALB[Application Load Balancer<br/>Traffic Distribution]
end
subgraph "Container Services"
ECS[Amazon ECS<br/>Container Orchestration]
Fargate[Amazon Fargate<br/>Serverless Containers]
subgraph "SpendWise Application"
NextJS[Next.js Application]
Frontend[React Frontend<br/>• Dashboard<br/>• Transaction Management<br/>• AI Advisor<br/>• Charts & Analytics]
API[API Routes<br/>• /api/transactions<br/>• /api/ai-advisor<br/>• /api/transactions/search]
Logic[Server Logic<br/>• Sequelize ORM<br/>• Zod Validations<br/>• Business Logic]
end
end
subgraph "Data Layer"
RDS[Amazon RDS PostgreSQL<br/>Multi-AZ Deployment]
Primary[(Primary DB<br/>AZ-1)]
Standby[(Standby DB<br/>AZ-2)]
S3[Amazon S3<br/>Static Assets & Backups]
end
subgraph "Security & Monitoring"
Cognito[Amazon Cognito<br/>User Authentication]
CW[CloudWatch<br/>Monitoring & Logging]
RDSInsights[RDS Performance Insights<br/>Database Monitoring]
end
end
%% User connections
User[Users] --> R53
User --> CF
%% Infrastructure flow
R53 --> CF
CF --> AG
AG --> ALB
ALB --> ECS
ECS --> Fargate
Fargate --> NextJS
%% Application internal flow
NextJS --> Frontend
NextJS --> API
NextJS --> Logic
%% Data connections
API --> RDS
Logic --> RDS
RDS --> Primary
RDS --> Standby
Primary -.-> Standby
%% Storage connections
NextJS --> S3
RDS --> S3
%% Security connections
AG --> Cognito
API --> Cognito
%% Monitoring connections
ECS --> CW
RDS --> RDSInsights
CW --> RDSInsights
%% Styling
classDef aws fill:#ff9900,stroke:#232f3e,stroke-width:2px,color:#fff
classDef app fill:#61dafb,stroke:#20232a,stroke-width:2px,color:#000
classDef data fill:#336791,stroke:#fff,stroke-width:2px,color:#fff
classDef security fill:#ff6b6b,stroke:#fff,stroke-width:2px,color:#fff
class R53,CF,AG,ALB,ECS,Fargate,RDS,S3,Cognito,CW,RDSInsights aws
class NextJS,Frontend,API,Logic app
class Primary,Standby data
class Cognito security
- Scalability: Auto-scaling based on demand with ECS Fargate
- Reliability: Multi-AZ deployment with automatic failover
- Security: Multiple layers including Cognito, IAM, and encryption
- Performance: Global CDN with CloudFront and optimized database access
- Cost Optimization: Pay-per-use model with no over-provisioning
- Monitoring: Comprehensive observability with CloudWatch and RDS Insights