How girik21/twitter-bot works
Project type and purpose
• This is an automated backend “Twitter bot” service written in Node.js.
• Purpose: Every hour (via cron), fetch top Hacker News stories, pass them to Google Gemini to generate click-bait AI/ML tweets, post one tweet via Twitter API, and record the tweet in a Supabase database.
File structure
• index.js: entry point, orchestrates the hourly run
• genAi/: contains geminiIntegration.js (calls Gemini API) and tweetSchema.js (defines prompt/schema for tweets)
• news/: newsFetcher.js (fetches top HN stories)
• utils/: helper modules—demo.js (local testing), saveTweetsToFile.js (persisting to disk), supabaseTracker.js (logging to Supabase)
• output/: .gitignore (likely holds saved tweets when running in demo)
• package.json, .env references for API keys, and deployment config implied (Render.com cron)
README for additional insights
• Runtime: Node ≥18
• External services: Google Gemini API, Twitter API v2, Supabase
• Deployment: Render.com with hourly cron trigger
a. Main components
• Scheduler (Render.com cron)
• Node.js application (index.js)
– newsFetcher module
– Gemini integration module
– Twitter client module
– Supabase tracker module
• External Services: Hacker News API, Google Gemini API, Twitter API, Supabase Database
• Optional local storage (output folder) for demo or logs
b. Relationships & data flow
1. Scheduler invokes the Node.js app every hour
2. App calls newsFetcher → retrieves top stories from Hacker News
3. Pass stories to GeminiIntegration → receives generated tweet text
4. Send one tweet to Twitter API → receives tweet ID/metadata
5. Call SupabaseTracker → insert record of posted tweet
6. (Optional) Save tweet to file via saveTweetsToFile for local audit or demo
c. Architectural patterns & design principles
• Modular pipeline: each step in its own module (single responsibility)
• Event-driven by cron scheduler
• External integrations abstracted behind thin adapters (geminiIntegration, supabaseTracker)
• Idempotency/tracking via Supabase to avoid reposts
d. Key technologies/frameworks
• Node.js (runtime)
• Axios or fetch (HTTP calls in modules)
• Google Gemini API
• Twitter API v2 SDK or REST calls
• Supabase JS client
• Render.com cron jobs