The CLI Expense Tracker is a command-line-based financial management system that helps users track, categorize, analyze, and visualize their expenses. It supports daily, weekly, monthly, and yearly expense tracking, along with advanced reporting and graphical analysis.
This documentation provides a detailed explanation of the project, including:
- System Flow (Method Call Structure)
- Database Schema
- Feature Breakdown
- Folder Structure
- Setup & Installation
- Usage Guide
- Common SQL Queries
This section provides a step-by-step breakdown of which method calls which method and how they interact.
home_options()
→ Displays Signup, Login, Exit options.- If Signup (
auth.signup()
) → Callsauth.signup()
, thenauth.login()
, thenusers_logged_in()
. - If Login (
auth.login()
) → Callsauth.login()
, thenusers_logged_in()
. - If Exit → Calls
display_goodbye()
and exits.
main.py
├── home_options()
├── auth.signup() → If successful, calls auth.login()
│ ├── If successful, calls users_logged_in()
├── auth.login() → Calls users_logged_in()
├── display_goodbye() → Exits the application
-
Signup (
auth.signup()
)- Checks if username is valid.
- Validates password strength.
- Inserts user into the database.
- Calls
auth.login()
immediately after successful signup.
-
Login (
auth.login()
)- If user is already logged in, it skips re-authentication.
- Verifies credentials, then stores session.
auth.signup()
├── Validates username
├── Validates password strength
├── Stores user in database
├── Calls auth.login() → Directly logs in new user
auth.login()
├── Checks if user is already logged in
├── Verifies credentials
├── Stores session
├── Returns user_id
- Calls expense, category, history, and report functionalities based on user choice.
users_logged_in(user_id)
├── Calls expense_manager.add_expense()
├── Calls expense_manager.delete_expense()
├── Calls expense_manager.update_expense()
├── Calls report_generator.view_reports()
├── Calls report_generator.generate_pdf_report()
├── Calls auth.view_history()
├── Calls category_manager.manage_categories()
├── Calls home_options() on exit
-
Add Expense (
expense_manager.add_expense()
)- Displays categories (6 per line).
- Ensures input validation (date range, amount).
- Logs the action in
user_logs
.
-
Delete Expense (
expense_manager.delete_expense()
)- Allows filtering expenses by category/date.
- Displays filtered expenses in a table.
- Deletes selected expense and logs the action.
-
Update Expense (
expense_manager.update_expense()
)- Allows filtering expenses by category/date.
- Displays filtered expenses in a table.
- Allows selective updates (amount, date, description).
- Logs the action in
user_logs
.
expense_manager.add_expense()
├── Shows categories (6 per line)
├── Takes valid input (date range, amount)
├── Inserts expense into DB
├── Logs action in user_logs
expense_manager.delete_expense()
├── Filters expenses by category/date
├── Displays expenses in a table
├── Deletes selected expense
├── Logs action in user_logs
expense_manager.update_expense()
├── Filters expenses by category/date
├── Displays expenses in a table
├── Allows selective updates
├── Logs action in user_logs
-
View Categories (
category_manager.display_categories()
)- Displays categories 6 per line.
- Ensures deleted categories do not appear.
-
View Last 30 Days' Spending (
category_manager.show_spending_last_30_days()
)- Displays category-wise total spending in a table.
- Includes total spending row.
-
Create New Category (
category_manager.create_category()
)- Prevents duplicate category creation.
- Capitalizes first letter.
- Inserts new category into DB.
-
Delete Category (
category_manager.delete_category()
)- Displays only user-created categories.
- Prevents deletion of predefined categories.
- Deletes associated expenses.
- Logs action in
user_logs
.
-
View Reports (
report_generator.view_reports()
)- Calls:
generate_daily_report()
generate_weekly_report()
generate_monthly_report()
generate_yearly_report()
generate_comparison_report()
- Calls:
-
Generate PDF Reports (
pdf_generator.py
)- Expense Table
- Expense Trend Graph
- Pie Chart
- Bar Chart
- Category-wise summary table
![Flow of Program](https://github.com/AnkushGitRepo/Cashflow-Compass/blob/main/docs/flow.png "Flow of Program")
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
password TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE categories (
id SERIAL PRIMARY KEY,
user_id INT REFERENCES users(id) ON DELETE CASCADE,
category_name VARCHAR(100) NOT NULL,
is_predefined BOOLEAN DEFAULT FALSE
);
CREATE TABLE expenses (
id SERIAL PRIMARY KEY,
user_id INT REFERENCES users(id) ON DELETE CASCADE,
category_id INT REFERENCES categories(id) ON DELETE SET NULL,
amount DECIMAL(10,2) NOT NULL,
description TEXT,
date DATE NOT NULL
);
CREATE TABLE user_logs (
id SERIAL PRIMARY KEY,
user_id INT REFERENCES users(id) ON DELETE CASCADE,
action TEXT NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);