How guru322/guru-ai works
Project Type and Purpose
• This is a monolithic Node.js WhatsApp bot (“GURU Ai”) with a plugin-based command system plus a small frontend pairing interface.
• It connects to WhatsApp Web via a library (e.g. Baileys), provides an HTTP UI for scanning/linking, and processes incoming messages through dozens of plugin scripts.
• Persisted state (sessions, user data, logs, queues) is stored in MongoDB.
High-Level Components
A. Frontend Pairing Interface
• Files: index.html, index.js, Assets/…
• Served by an Express HTTP server (server.js or via index.js).
• Displays pairing QR code, connection status, and basic controls.
B. HTTP Server Layer
• server.js (or index.js) sets up the Express app, static asset routes, and WebSocket/SSE for live updates.
• handler.js orchestrates incoming HTTP requests and forwards events to the bot engine.
C. Bot Engine Core
• index.js initializes the WhatsApp Web connection, loads config.js, and starts the event loop.
• Uses lib/ modules (database.js, mongo-auth.js, queue.js, converter.js, logs.js, etc.) to handle low-level services.
• Central event dispatcher routes incoming WhatsApp messages to handler.js → Plugin Manager.
D. Plugin Manager
• Directory: plugins/
• Each file exports a command or group of commands (e.g. .ping, .alive, dl-tiktok, gp-kick).
• On message events, the manager selects the matching plugin, invokes its handler, and returns a response.
E. Persistence Layer
• MongoDB (lib/mongo-connection.js, mongo-store.js, auth modules).
• Stores user sessions, chat metadata, queues, command logs, rate-limits, etc.
F. Utility Services
• Conversion (lib/converter.js, webp.js, gifbuffer.js)
• File upload/download (lib/uploadFile.js, lib/import.js)
• Sticker, image upscaling (lib/sticker.js, lib/upscale.js)
• Temporary file cleanup (lib/tempclear.js)
• Logging (lib/logs.js)
G. External Services
• WhatsApp Web API (over websockets/HTTP)
• Optional third-party APIs invoked by plugins (e.g. TikTok, YouTube download endpoints).
Inter-Component Relationships & Data Flow
1. User opens browser → HTTP Server → retrieves index.html & assets → shows QR pairing.
2. HTTP Server pushes QR code events (via SSE/WebSocket) generated by Bot Engine core.
3. index.js (Bot Engine) connects to WhatsApp Web, emits events (QR code, connection, messages).
4. handler.js receives WhatsApp events, invokes Plugin Manager.
5. Plugin Manager loads appropriate plugin, may:
a. Query/modify MongoDB via lib/database.js
b. Call utility services (converter, sticker, upload)
c. Call external APIs (dl-tiktok, ai-chat, etc.)
6. Plugin returns a payload (text, media buffer) to Bot Engine → sends back to WhatsApp Web.
7. All significant actions logged (lib/logs.js) and queued (lib/queue.js) if needed.
Architectural Patterns & Principles
• Event-driven, plugin-based modularity: easy to add/remove commands.
• Single process, layered services: HTTP layer, core engine, plugin layer, persistence, utilities.
• Clear separation of concerns:
• server.js & handler.js for transport
• lib/ for low-level services
• plugins/ for business logic
Final Checklist
• Components: Browser UI, HTTP Server, Bot Engine, Plugin Manager, Utility Services, MongoDB, External APIs & WhatsApp Web
• Container boundaries for “lib/” vs. “plugins/”