Automated Expense Tracking & Reporting System
Architectural documentation for the automated expense tracking system utilizing n8n, NocoDB, and Google Gemini.
1. Architecture: Transition to NocoDB
Data integrity and scalability requirements necessitated the migration from Google Sheets to NocoDB:
| Requirement | Advantage of NocoDB |
|---|---|
| Data Typing | Enforcement of Currency, Date, and Integer types. |
| Integrity | Foreign Key links between transactions and source emails. |
| Efficiency | Native database filtering for near-zero latency retrieval. |
| Concurrency | Native handling of simultaneous write operations. |
2. Database Schema
State is maintained across three relational tables:
- Emails: Raw metadata and processing states (parse_status: pending, success, failed).
- Transactions: Immutable ledger of parsed financial data mapped to source emails.
- Category Rules: Knowledge base for merchant pattern matching and classification.
3. Pipeline 1: Transaction Ingestion
Workflow execution is triggered by transactional email receipt.
Operation Flow
- Extraction: Raw email content is processed by Google Gemini for entity extraction (merchant, amount, date).
- Categorization: Extracted data is checked against the
category_rulestable.- Match: Deterministic category is applied.
- No Match: New merchant is flagged for classification.
- Commit: Validated data is committed to the
transactionstable. - Closure: Email status is updated to
successto prevent re-processing.
4. Pipeline 2: Daily Financial Summary
Execution is scheduled daily at 22:00 for data aggregation and reporting.
Aggregation Logic
- Timezone Filtering: Retrieval of transactions matching the current calendar date (Asia/Jakarta).
- Summation: Calculation of total expenditure and itemized breakdown via JavaScript.
- Dispatch: Formatted summary delivery to Discord.