How bottoproject/sr-auction-bot works
Main Components
• Serverless Backend: Represent the three Supabase Edge Functions – “fetch-events”, “process-events”, and “send-discord”. Each function plays a different role:
• fetch-events: Polls the SuperRare GraphQL API for new auction events.
• process-events: Processes and transforms raw events stored in the database.
• send-discord: Dispatches notifications to Discord.
• Database Layer: Include the Supabase PostgreSQL database that stores event data along with tables from the migrations (e.g., auction events, CRON logs).
• Scheduler: Represent the CRON jobs (configured via SQL scripts) that trigger the edge functions on a scheduled interval (every minute).
• External Services:
• SuperRare GraphQL API: External API providing auction event data.
• Discord: Represent both the Discord Bot (using the bot token) and/or Discord Webhooks for sending messages.
Interactions and Flow
• The “fetch-events” function makes an HTTP request to the SuperRare GraphQL API, retrieves auction events, and then writes those events into the PostgreSQL database.
• The “process-events” function is triggered (either via CRON or chained internally) to read from the database, process or format the events, and prepare notifications.
• The “send-discord” function is subsequently triggered; it picks up the processed data and sends notifications to Discord via the Discord Bot or Webhook.
Architectural Patterns & Design Principles
• Serverless Architecture: Emphasize the use of Supabase Edge Functions for scalability.
• Separation of Concerns: Each edge function has a clear, singular responsibility.
• Event-Driven Processing: The scheduler triggers functions based on events (time-based CRON schedule) ensuring reactive behavior.
• Secure Handling of Secrets: Note how sensitive information (like Discord tokens and API keys) is passed as environment variables and through a secured setup process.
Technologies
• Node.js environment for scripts (init, deploy, secret setup).
• Supabase (for both edge functions and PostgreSQL).
• CRON jobs, likely implemented using pg_cron for scheduling in Supabase.
• Discord platform (via Bot tokens or Webhooks).
• GraphQL communication with the SuperRare API.
Additional Details
• That each component is clearly labeled with its purpose (e.g., “Data Fetching”, “Event Processing”, “Notification Dispatch”).
• Use annotations or callouts to explain where configuration files enter the process (e.g., .env files, config.toml).
• For clarity, include notes about the secure handling of secrets, routing of environment variables, and the role of CRON-based scheduling.