Investigation brief · Python
Create a local expense application whose calculations are traceable and whose database rejects obvious invalid records.
Start with the business or technical outcome
A fictional freelancer records dated expenses by category, edits mistakes and needs monthly totals without storing payment credentials. Troubleshooting becomes faster when observations are separated from assumptions. A useful database project is more than four CRUD buttons; it preserves valid data through constraints and transactions.
Use synthetic transactions and never store bank credentials. Decide currency and rounding policy. SQLite is appropriate for a small local project, not automatically for a multi-user production service.
Database constraints protect invariants close to the data; application validation gives clearer user feedback. Use both where their responsibilities differ.
What to understand before opening the tool
Understand connection context, parameterized SQL, primary and foreign keys, NOT NULL and CHECK constraints, transactions, rollback, indexes, date storage, aggregate queries and row mapping. Avoid assembling SQL from user text.
Money representation needs care. Store integer minor units or another explicit exact representation for the chosen currency and format only at presentation.
sqlite3 Module
Use it for: connect, execute parameterized statements and control transactions Keep as evidence: database and query tests
Schema Migration Script
Use it for: create tables, constraints and indexes repeatably Keep as evidence: versioned schema
Service Functions
Use it for: implement add, list, update, delete and report behavior Keep as evidence: typed, testable API
CSV Export
Use it for: produce a portable user-owned report without leaking database internals Keep as evidence: validated export
Your investigation should produce a Python CLI or service layer, SQLite schema, parameterized CRUD operations, monthly report, CSV export and automated tests. Preserve observations before changing configuration, and test the smallest plausible correction first. If the evidence does not support the first theory, update the theory instead of forcing the facts to fit it.
Diagnose the scenario without guessing
Design constraints and report questions before writing the command interface.
- Write use casesDefine add, edit, delete, list by period and monthly category report.Checkpoint: Acceptance examples.
- Design the schemaCreate category and expense tables with keys, date, amount and validation constraints.Checkpoint: ER sketch and migration.
- Implement parameterized CRUDKeep SQL placeholders separate from values and return clear not-found results.Checkpoint: Service tests.
- Use transaction boundariesCommit complete operations and roll back an intentionally failed multi-step action.Checkpoint: Atomicity test.
- Build monthly reportsAggregate integer amounts by month and category and reconcile to detail.Checkpoint: Report plus control total.
- Add export and backup noteCreate CSV safely, test reopening a copied database and document limitations.Checkpoint: Export and recovery evidence.
A useful diagnostic note names the symptom, affected scope, time observed, evidence collected, hypotheses rejected and final corrective action. This prevents the next investigation from starting at zero.
Signals that separate symptoms from causes
The schema should prevent invalid states instead of relying only on interface behavior.
| Decision or signal | Action to take | Evidence to retain |
|---|---|---|
| Expense amount | Positive integer minor units | CHECK constraint and boundary test |
| Expense date | ISO date validated by application | Valid and invalid input tests |
| Category | Foreign key to controlled category table | Rejected missing category |
| Description | Optional length and display policy | Unicode and blank tests |
| Monthly total | SUM detail under same filters | Aggregate-to-detail reconciliation |
Common diagnostic traps and safer checks
Small local apps still need injection safety, backups and clear delete behavior.
- Formatting user text into SQL: Use placeholders and parameter binding.
- Storing money as casual float: Choose integer minor units or explicit exact decimal policy.
- Forgetting foreign-key behavior: Enable and test constraints for the connection.
- Committing halfway through one logical action: Use a transaction boundary and rollback on failure.
- Calling a copied live file a tested backup: Restore and query the copy under a controlled procedure.
Turn the exercise into credible portfolio evidence
Publish schema, seed script, service code, CLI help and tests using fictional expenses. Add an ER diagram and sample report with a reconciliation total.
Include one migration note explaining how a future column would be added without deleting user data. Keep claims appropriate for a local learning application.
Explain it clearly in an interview
Explain parameterized queries, transaction atomicity, money storage, foreign keys and how your monthly aggregate is reconciled to underlying rows.
Peer review before calling the work complete
Ask another learner to inspect the result without watching you build it. Give them the original scenario—a fictional freelancer records dated expenses by category, edits mistakes and needs monthly totals without storing payment credentials.—and the evidence pack, but not your intended conclusion. They should be able to trace the input, identify the main decision and locate the proof of the output. If they cannot, improve the labels, timestamps or explanation instead of adding decorative screenshots.
Use this acceptance condition during the review: Constraints reject invalid records, CRUD uses parameters, failed multi-step changes roll back, monthly totals reconcile to detail and a copied database can be reopened in the test. Record one question the reviewer raised and the change you made in response. That small feedback loop makes the Python SQLite expense tracker exercise more credible, easier to maintain and easier to explain under interview questioning.
Questions learners ask
Why is SQLite useful for learning?
It provides a relational database in the standard Python ecosystem without running a separate server.
Do placeholders work for table names?
They bind values, not arbitrary SQL identifiers; keep identifiers controlled by code.
Why store money in minor units?
Integer cents or paise avoid many binary floating-point representation surprises when the currency policy is fixed.
Is copying the database always a safe backup?
Use a procedure appropriate to database state and verify the restored copy; concurrent writes and environment matter.
Use current product guidance
Menus, fields, permissions and service behavior can change between product versions or tenant configurations. Check the official Python documentation before applying version-sensitive steps in a live environment.
Build the complete skill path
Learn Python syntax, data structures, functions, OOP, files, databases, testing, debugging and automation by building small, explainable applications.
Final perspective
The real value of Python SQLite expense tracker is the ability to complete a controlled task and defend the result with evidence. A learner who can show the input, explain the decision, verify the output and describe one realistic exception demonstrates far more than someone who has only memorised a menu path or definition.