Kartevonmorgen Workflows (kvmflows) is a backend service for managing user subscriptions to OpenFairDB entries. Users can subscribe to updates or new entries in specific geographic areas and receive periodic email notifications. The system includes:
- API Server: Accepts subscription requests, handles activation/unsubscription, and manages user preferences.
- Email Service: Sends activation emails and periodic batch notifications using Mailgun and Liquid templates.
- Sync Flows: Two-tier data synchronization strategy:
- Full Sync: Comprehensive scraping of all OpenFairDB entries for complete data coverage
- Recent Sync: Hourly updates fetching only recently changed entries for real-time responsiveness
- Optimized Email Timing: Subscription emails are scheduled for 8:00 AM UTC to maximize open rates and user engagement, with hourly notifications at minute 5 to ensure recent sync completion.
- Subscription API: Create, activate, and unsubscribe from area-based entry notifications.
- Email Activation: Users must activate subscriptions via a secure email link.
- Batch Notifications: Periodic emails with new/updated entries in the user's area.
- Configurable Intervals: Daily, weekly, and monthly notification options.
- Robust Error Handling: Retries, rate limiting, and logging for email delivery.
- FastAPI: RESTful API for subscription management.
- Mailgun: Email delivery for activation and batch notifications.
- Liquid Templates: Customizable email content.
- PostgreSQL: Persistent storage for subscriptions and entries.
- APScheduler: Cron jobs for scraping and notifications.
- Docker Compose: Containerized deployment for all services.
- Python 3.12+
- Docker & Docker Compose
- Poetry for dependency management
- Mailgun account (for email delivery)
- PostgreSQL database
- Clone the repository:
git clone https://github.com/your-org/kvmflows.git cd kvmflows - Configure environment:
- Edit
config.yamlfor API keys, database, and email settings. - Ensure Mailgun credentials and template paths are set.
- Edit
- Install dependencies:
poetry install
- Run database migrations:
(If needed, apply migrations or run
init_pg_dbs.sql)
- Start API server:
poetry run python src/kvmflows/apis/server.py
- Run sync flows manually:
# Full synchronization of all entries poetry run python src/kvmflows/crons/sync_all_entries.py # Recent entries synchronization (hourly updates) poetry run python src/kvmflows/crons/sync_recent_entries.py # Send subscription emails poetry run python src/kvmflows/crons/send_subscription_emails.py
- Build and start all services:
This will start:
docker-compose up --build
- API server (
server.py) - Full entry synchronizer (
sync_all_entries.py) - Recent entry synchronizer (
sync_recent_entries.py) - runs hourly - Subscription email service (
send_subscription_emails.py)
- API server (
POST /v1/subscriptions— Create a new subscriptionGET /v1/subscriptions/{id}/activate— Activate a subscriptionGET /v1/subscriptions/{id}/unsubscribe— Unsubscribe
See OpenAPI docs for full endpoint details.
- User subscribes via API.
- Activation email sent with secure link.
- User activates subscription.
- Sync flows continuously update entry data:
- Full sync scrapes all OpenFairDB entries for comprehensive coverage
- Recent sync runs hourly to capture newly changed entries
- Batch emails sent to users with relevant entries at 8:00 AM UTC for optimal engagement, with hourly notifications scheduled at minute 5 to ensure recent sync completion.
- User can unsubscribe at any time.
Note: Subscription emails are scheduled for 8:00 AM UTC as this timing significantly increases the likelihood of emails being read and acted upon by users. Hourly notifications are sent at minute 5 of each hour to allow the recent entries sync process to complete. All service times operate in UTC timezone.
- All settings are managed in
config.yaml:- API keys, email templates, database credentials, sync schedules, area definitions, etc.
- Email timing is configured for 8:00 AM UTC delivery to maximize user engagement and read rates.
- Hourly notifications are scheduled at minute 5 of each hour to ensure recent entries sync completion.
- All service operations run in UTC timezone for consistency across deployments.
- Example email templates are in
src/kvmflows/templates/.
- Fork the repository
- Create your feature branch (
git checkout -b feature/foo) - Commit your changes (
git commit -am 'Add feature') - Push to the branch (
git push origin feature/foo) - Create a new Pull Request
This project is licensed under the MIT License.
- Navid Kalaei (navidkalaei@gmail.com)