akopulko / ffiiitc

FireFly III Transactions Classifier
MIT License
37 stars 9 forks source link

FireFly III Transaction Classification

This little web service performs transaction classification and integrates with FireFly III (A free and open source personal finance manager) via web hooks.

What is does?

Every time you add new transaction to FireFly III, either manually or via import tool, web hook will trigger and provide transaction description to ffiiitc. It will then be classified using Naive Bayesian Classification and transaction will be updated with matching category.

Naive Bayesian classifier go package used by ffiiitc is available here. Please read the license.

How to run?

Pre-requisites

Docker Compose

Run

Docker Compose
  fftc:
    image: akopulko/ffiiitc:latest
    hostname: fftc
    networks:
      - firefly_iii
    restart: always
    container_name: ffiiitc
    environment:
      - FF_API_KEY=<YOUR_PAT_GOES_HERE>
      - FF_APP_URL=<FIREFLY_ADDRESS:PORT>
    volumes:
      - ffiiitc-data:/app/data
    ports:
     - '<EXPOSED_PORT>:8080'
    depends_on:
     - app
volumes:
    ...
   ffiiitc-data:

You can also append your environment variable names with _FILE instead, having their value point to the file where tha actual sensitive value is stored. This works with any environment variable.

secrets:
  ffiiitc-personal-access-token:
    file: "<path/to/secrets/location>/ffiiitc-personal-access-token"

services:
  ...
  fftc:
    image: akopulko/ffiiitc:latest
    hostname: fftc
    networks:
      - firefly_iii
    restart: always
    container_name: ffiiitc
    secrets:
      - "ffiiitc-personal-access-token"
    environment:
      - FF_API_KEY_FILE="/run/secrets/ffiiitc-personal-access-token"
      - FF_APP_URL=<FIREFLY_ADDRESS:PORT>
    volumes:
      - ffiiitc-data:/app/data
    ports:
      - '<EXPOSED_PORT>:8080'
    depends_on:
      - app

volumes:
  ...
  ffiiitc-data:

Docker

docker run
  -d
  --name='ffiiitc'
  -e 'FF_API_KEY'='<YOUR_PAT_GOES_HERE>'
  -e 'FF_APP_URL'='<FIREFLY_ADDRESS:PORT>'
  -p '<EXPOSED_PORT>:8080'
  -v '<TRAINED_MODEL_FOLDER>':'/app/data':'rw' 'ffiiitc'

Configure Web Hooks in FireFly

In FireFly go to Automation -> Webhooks and click Create new webhook

title: classify
trigger: after transaction creation
response: transaction details
delivery: json
url: http://fftc:<EXPOSED_PORT>/classify
active: checked

Troubleshooting

Logs

You can check ffiiitc logs to see if there are any errors:
docker compose logs fftc -f

Forced training of your model

There is also option available to force train the model from your transactions if required. To trigger force train run the following command and restart fftc container: curl -i http://localhost:<EXPOSED_PORT>/train where EXPOSED_PORT is the port you provided in your docker compose for fftc. As always, you can check logs to see if model was successfully regenerated.