Refactor: make a factory for trigger-action app and move rule persistence to a RuleDb class