Skip to content

Automatic rules #35

@letehaha

Description

@letehaha

Automatic Transaction Rules Feature

Overview

Auto-categorize transactions based on keywords/regex patterns. Users create rules that automatically assign categories to matching transactions.

Core Features

  1. Rule Management
  • New page. List view showing all rules in table format
  • Edit/delete existing rules
  • Rules processed in creation order, first match wins. This should be specified on the UI to the user
  1. Rule Creation, via dialog on the Rule Management page

Form fields:

  • Name: User-defined rule name
  • Keywords: Text or regex patterns with preview/test functionality
  • Record Type Filter: Apply to income, expense, or both
  • Category: Select which category to auto-assign (optional)
  • Transfer Conversion: Convert to transfer + select source account (optional). See "Extended Features" for more details.
  • Applied to accounts: Select accounts to which the rule should be applied. If none selected, will be applied to all accounts. Specify on the UI that if all accounts specified in this list will be deleted, the rule will be auto-deleted as well.

Processing Logic

  • Match against transaction description/notes/merchant
  • Case-insensitive text matching or regex
  • Apply to new transactions automatically. ONLY to transactions that are not-manually-created, i.e. only to auto-imported via bank connection, or manual import
  • When user deletes account, backend should check if there's any rule that linked to the specific account. If more accounts linked to that rule, do nothing. If account that is being deleted atm is the last one linked to the rule, also delete the rule with it, since it becomes useless.

Extended Features

Regex Support

  • Regex validation with error handling
  • Preview tool: test input field + real-time validation
  • Show example matches

Transfer Conversion

  • Toggle to convert matched transactions to transfers
  • Source account dropdown (only when enabled)
  • Maintains original amount/date – means that opposite transfer transaction should be created for the same date and with correctly converted amount, if currencies don't match between accounts.

Technical Notes

Data Models

Rule {
  id: number;
  name: string;
  matches: string[]; // keywords or regexes
  recordType: null | 'income' | 'expense';
  categoryId: null | number;
  convertToTransfer: boolean;
  sourceAccountId: number;
  isActive: boolean;
}

API Endpoints

  • CRUD operations for rules
  • Batch rule application

Key Requirements

  • Efficient regex processing with timeouts
  • First-match-wins rule precedence
  • Real-time application to new transactions that come from bank connections
  • Graceful handling of deleted categories/accounts

Future Enhancements

  • Rule Templates: Pre-defined common rules
  • Machine Learning: Suggest rules based on user patterns
  • Bulk Rule Application: Apply rules to historical transactions. An endpoint to apply rules to existing transactions (not just new ones). Use cases:
    • User creates a new rule and wants to apply it to past 6 months of transactions
    • User imports 1000 transactions and wants to auto-categorize them all
    • User fixes a rule and wants to re-apply it to previously processed transactions
  • Advanced Conditions: Date ranges, amount thresholds, etc

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions