Entity Relationship Diagram
Tables Overview
Core Tables
users- User accounts and authenticationaccounts- Financial accounts (bank, cash, etc.)categories- Transaction categoriestransactions- Income/expense records
Supporting Tables
net_worths- Historical net worth snapshotssessions- User session managementpassword_reset_tokens- Password resetsjobs- Queue management
Users Table
Stores user authentication and profile information.database/migrations/0001_01_01_000000_create_users_table.php
Fields
| Column | Type | Description |
|---|---|---|
id | bigint unsigned | Primary key |
name | varchar(255) | User’s full name |
email | varchar(255) | Email address (unique) |
email_verified_at | timestamp | Email verification timestamp |
password | varchar(255) | Hashed password (nullable for OAuth users) |
remember_token | varchar(100) | Remember me token |
provider | varchar(255) | OAuth provider name (e.g., ‘google’, ‘github’) |
provider_id | varchar(255) | OAuth provider user ID (unique) |
created_at | timestamp | Account creation timestamp |
updated_at | timestamp | Last update timestamp |
The
password field is nullable to support OAuth authentication via Laravel Socialite. Users who sign in with Google or other providers don’t need a password.Relationships
app/Models/User.php
Accounts Table
Represents financial accounts like bank accounts, wallets, or credit cards.database/migrations/2024_05_22_071335_create_accounts_table.php
Fields
| Column | Type | Description |
|---|---|---|
id | bigint unsigned | Primary key |
user_id | bigint unsigned | Foreign key to users table |
name | varchar(255) | Account name (e.g., “Main Bank”, “Cash Wallet”) |
balance | decimal(15,2) | Current account balance |
color | varchar(255) | Tailwind color name for UI display |
created_at | timestamp | Creation timestamp |
updated_at | timestamp | Last update timestamp |
Indexes
name- For searching accounts by name(user_id, balance)- Composite index for net worth calculations
Relationships
app/Models/Account.php
Categories Table
Defines categories for classifying transactions.database/migrations/2024_05_26_074754_create_categories_table.php
Fields
| Column | Type | Description |
|---|---|---|
id | bigint unsigned | Primary key |
user_id | bigint unsigned | Foreign key to users table |
name | varchar(255) | Category name (e.g., “Groceries”, “Salary”) |
type | enum | One of: income, expense, correction, transfer |
color | varchar(255) | Tailwind color name for UI display |
icon | varchar(255) | Icon filename for visual representation |
created_at | timestamp | Creation timestamp |
updated_at | timestamp | Last update timestamp |
Category Types
- Income
- Expense
- Correction
- Transfer
Categories for money coming in (salary, gifts, freelance work, etc.)
Default Categories
New users automatically receive default categories via theCreateDefaultCategories listener:
config/default-categories.php
Indexes
name- For category search and autocompletetype- For filtering by category typeuser_id- For user-specific queries(user_id, type)- Composite index for filtered category lists
Transactions Table
Records all financial transactions.database/migrations/2024_06_03_143109_create_transactions_table.php
Fields
| Column | Type | Description |
|---|---|---|
id | bigint unsigned | Primary key |
user_id | bigint unsigned | Foreign key to users table |
category_id | bigint unsigned | Foreign key to categories table |
account_id | bigint unsigned | Foreign key to accounts table |
title | varchar(255) | Transaction description |
amount | decimal(15,2) | Transaction amount (negative for expenses) |
details | text | Optional transaction notes |
created_at | timestamp | Transaction date/time |
updated_at | timestamp | Last update timestamp |
Indexes
title- For transaction searchuser_id,category_id,account_id- Individual foreign key indexes(user_id, category_id)- For category-specific transaction queries(user_id, account_id)- For account-specific transaction queries
Cascade Deletion
All foreign keys usecascadeOnDelete(), meaning:
- Deleting a user deletes all their transactions
- Deleting an account deletes all its transactions (with balance correction)
- Deleting a category deletes all transactions in that category
In practice, the
TransactionController::destroy() method creates a correction transaction before deletion to maintain accurate balance history.Net Worths Table
Stores historical snapshots of user net worth for tracking over time.database/migrations/2024_06_14_110400_create_net_worths_table.php
Fields
| Column | Type | Description |
|---|---|---|
id | bigint unsigned | Primary key |
user_id | bigint unsigned | Foreign key to users table |
net_worth | decimal(15,2) | Total net worth snapshot |
created_at | timestamp | Snapshot timestamp |
updated_at | timestamp | Last update timestamp |
Usage
Net worth snapshots are created automatically whenever transactions are created, updated, or deleted:app/helpers.php
Supporting Tables
Sessions Table
Password Reset Tokens
Data Integrity
Foreign Key Constraints
All relationships use foreign key constraints with cascade delete to maintain referential integrity.
Decimal Precision
All monetary values use
decimal(15,2) for accurate financial calculations without floating-point errors.