How jayleecn/btc_alerts works
Project’s Purpose and Type
• This project is a scheduled data‐collection and notification service for BTC market metrics. It gathers BTC metrics (MVRV Z-score and Pi Multiple) every morning, then posts alerts to Twitter and, if thresholds are met, to a Google email group.
• It integrates with third-party services (Twitter API 2.0 and Google Groups) and uses GitHub Actions for scheduling and Vercel for serverless deployment. Essentially, it’s a small full-stack (or serverless backend) application focused on scheduled integrations rather than serving a client-facing UI.
Analyzing the File Structure
• Top-Level Files/Directories:
• .github/workflows: Contains GitHub Actions YAML files (schedule.yml and keep-alive.yml) responsible for triggering the daily job.
• api/index.js: The main code for collecting data and posting alerts. (Note that the README explains that index.js was relocated here to work as a Vercel Serverless Function.)
• server.js and index.html: Possibly used for local testing or additional web serving aspects.
• vercel.json: Configures Vercel’s behavior – particularly that files under /api are automatically interpreted as serverless functions.
• package.json and package-lock.json: Define dependencies and scripts.
• These indicate a design that uses serverless functions (via Vercel) combined with scheduled triggering via GitHub Actions.
Insights from the README
• Describes the schedule (daily at 8 AM) and the external services (Twitter and Google Groups).
• Explains the adjustments made: loading environment variables with dotenv, switching Twitter API versions, and required permission settings.
• Highlights deployment nuances like moving index.js to the /api folder to accommodate Vercel’s serverless functions.
• Notes configuration changes needed in GitHub Actions (public repository requirement) for the scheduler.
a. Main Components:
• GitHub Actions Scheduler: Represents the automated triggers (using schedule.yml and keep-alive.yml) that start the daily execution.
• Vercel Deployment Layer: Illustrates that the project is deployed on Vercel which hosts the serverless function.
• Serverless Function (/api/index.js): The execution core that collects BTC metrics and interfaces with external APIs.
• External Services:
• BTC Data Provider: (Implicit) the source of BTC metrics.
• Twitter API (v2.0): For posting tweets.
• Google Groups (Email Alerts): For sending extra notifications if conditions are met.
• Supporting Components:
• Dotenv Initialization: Depicted as part of the startup process in the serverless function.
• Environment Variables: Critical for API keys and configuration.
• Optional Local Testing Component: server.js and index.html might be used for local validations.
b. Relationships and Interactions:
• GitHub Actions → Vercel (triggering the serverless function).
• Vercel (serverless function) → BTC Data Provider for fetching metrics.
• Vercel (serverless function) → Twitter API for posting tweets.
• Vercel (serverless function) → Google Groups for sending email alerts when criteria are met.
• Additionally, indicate feedback loops (e.g., responses from the APIs, error logging, etc.) if applicable.
c. Architectural Patterns & Design Principles:
• Serverless Architecture: Emphasize that the core processing logic is hosted as a serverless function on Vercel.
• Scheduled/Triggered Processing: Use GitHub Actions as an external scheduler.
• Separation of Concerns: The code clearly separates tasks (data collection vs. notification) and isolates configuration (via dotenv and vercel.json).
• Use of Environment Variables for secure configuration.
d. Relevant Technologies and Libraries:
• Node.js: The runtime environment.
• dotenv: For loading environment variables.
• Twitter API v2.0 Client Library: For posting tweets.
• Vercel Serverless Functions: For hosting the API.
• GitHub Actions: For orchestrating scheduled tasks.