Architecture¶
High-level system design for Meerkit.
System Topology¶
Vue 3 frontend (Vite)
-> HTTP /api/*
Flask app (meerkit/app.py)
-> routes + service layer
-> SQLite persistence (per-user DB files)
-> background workers (scan/prediction/automation/download)
-> filesystem caches (data/cache, data/image_cache, data/diffs)
-> Instagram API via insta_interface wrappers
Backend Layers¶
- Routes (
meerkit/routes) - HTTP contracts and validation.
-
Scope resolution via session and active Instagram account.
-
Services (
meerkit/services) -
Business logic for auth, scan, prediction, automation, cache, persistence.
-
DB Layer (
meerkit/db,meerkit/services/db_service.py) - Schema creation/migrations for new columns.
-
Thread-local connection handling.
-
Workers (
meerkit/workers) - Queue consumers for image, prediction, automation workloads.
Route Domains¶
- Auth + account management (
/api/auth/*) - Scan lifecycle + history + diffs (
/api/scan*,/api/history,/api/diff/*,/api/summary) - Predictions (
/api/predictions/*,/api/prediction-tasks/*, target relationship-cache endpoints) - Automation (
/api/automation/*) - Unified task board (
/api/tasks) - Image serving (
/api/image/<pk_id>)
Core Data Flows¶
1) Scan Flow¶
- Frontend calls
POST /api/scan. scan_runner.start_scan()acquires per-scope lock and starts thread.meerkit/scan_worker.pyruns follower scan with explicit credentials.- Scan records + diff metadata are stored.
- Frontend polls
GET /api/scan/statusand refreshes summary/diff/history when done.
2) Prediction Flow¶
- Frontend calls
POST /api/predictions/follow-back. - Immediate result may be returned, or background task is queued.
- Worker refreshes prediction and marks task progress/status.
- Frontend polls prediction task endpoints and can submit feedback.
3) Automation Flow¶
- Frontend stages action via prepare endpoint.
- User confirms action (
/actions/<id>/confirm). - Worker executes item-by-item with heartbeat + rate-aware delay.
- Status transitions persist in
automation_actions+automation_action_items.
Scope + Session Design¶
- Flask session stores app user and active Instagram account.
- Every scoped request resolves context with
get_active_context(). - Query override allows selecting explicit profile scope when needed.
Cache Strategy¶
- Instagram gateway read-cache envelopes in
data/cache. - Optional legacy user detail cache writes controlled by feature flag.
- Relationship cache snapshots for followers/following lists.
- Image cache metadata in DB + files in
data/image_cache.
Reliability Patterns¶
- Stale scan/prediction/automation task detection and error marking.
- Worker thread startup guarded against duplicate startup under Flask reload.
- Background cancellation support for scan, prediction tasks, automation actions.
Frontend Architecture Notes¶
- Router-based views in
frontend/src/router/index.ts. - TanStack Query for API state, polling, and cache invalidation.
- Dedicated workflows for dashboard, history, discovery, prediction history, tasks, and automation suites.
See Backend API, Frontend, Database, and API Reference.