How wangwangit/substracker works
Project Type and Purpose
• This is a serverless full-stack subscription management and reminder system (“SubsTracker”) built entirely on Cloudflare Workers.
• It exposes both a web UI (single‐page app served from the Worker) and a REST-style API for managing subscriptions, and runs a scheduled job (Cron Trigger) to send notifications via Telegram, Webhook, email, etc.
File Structure Analysis
• index.js – the sole Worker entry point. Contains routing logic (UI vs API vs Cron) and service layer.
• package.json – dependencies (e.g. Router, Resend SDK).
• wrangler.toml – Cloudflare Workers config (KV binding, Cron schedule).
• README.md – detailed feature list, deployment instructions, and notification channel configs.
Key Architecture Insights from the README
• Uses a single Cloudflare Worker for all functionality (UI + API + scheduler).
• Persists subscription data in a Workers KV namespace (SUBSCRIPTIONS_KV).
• Cron trigger fires daily (or hourly) to run the “check-expiry-and-notify” job.
• Integrates with multiple external notification services (Telegram Bot API, NotifyX, WeChat, Webhook templates, Bark, Resend email).
Main Components & Their Interactions
a. Client (Browser)
– Requests the UI (static HTML/CSS/JS) and calls the JS app’s REST APIs under /api/*.
b. Cloudflare Worker
– Route Handler: Serves static assets and routes API calls.
– API Layer: CRUD operations on subscriptions, auth (admin user), config endpoints.
– Scheduler (Cron Trigger): Periodically invokes notification job.
– Notification Service Layer: Picks configured channels, formats payloads, calls external endpoints.
c. Workers KV (SUBSCRIPTIONS_KV)
– Key-value store for subscription records, user settings, and notification history.
d. External Services
– Telegram Bot API, NotifyX API, WeChat robot webhook, generic Webhook endpoint, Bark push API, Resend email API.
Architectural Patterns & Principles
• Serverless / Functions-as-a-Service: single deployable unit for routing, data, and scheduled jobs.
• Layered design within the Worker:
1. HTTP Routing → 2. Business Logic / Subscription Service → 3. Persistence (KV) & Notification Adapters.
• Event-driven Cron scheduling for asynchronous notification tasks.
• Modular adapters for each notification channel (plug-and-play).
Detailed Capture of Essential Elements
• Technology stacks: JavaScript/TypeScript runtime, Cloudflare Workers, Workers KV, Wrangler CLI.
• Cron schedule (defined in wrangler.toml) as part of the deployment config.
• Modular adapters for each channel so it’s clear where new channels would plug in.