How slynderly/wibc works
1. System shape
- This is a single Node.js/Express SaaS backend that serves both the web dashboard and the API.
- It is not split into separate services; most behavior lives in server.js plus modules under src/.
- Persistence is file-based in data/ rather than a database.
2. Main runtime boundary
- server.js is the bootstrapping entry point.
- On startup it configures Express, applies security middleware, migrates base64 avatars to files, and restores persisted WhatsApp sessions from data/auth_*/.
- The server listens on PORT and exposes both user-facing routes and admin routes.
3. Frontend boundary
- public/ contains static HTML/CSS/Vanilla JS pages: login/register, dashboard, and admin panel.
- The frontend is thin and talks to the backend through REST endpoints.
- There is no SPA framework; the UI is mostly server-served static assets plus API-driven interactions.
4. Core API boundary
- src/routes.js is the main application API surface.
- It covers authentication, user profile and bot configuration, WhatsApp device/session control, chat history, manual message sending, order management, Shopify/Hotmart integrations, and prompt generation.
- The route design is user-scoped: most resources are addressed by :userId.
5. WhatsApp session subsystem
- src/whatsapp.js manages Baileys connections and persists device sessions per user/device in data/auth_*/.
- It supports QR-based linking and pairing-code-based linking.
- Incoming WhatsApp messages are the primary event stream for the application and feed both chat history storage and bot automation.
6. AI and sales automation subsystem
- src/ai.js is the bot brain: it builds prompts, calls Groq API models, and handles AI-driven replies.
- The bot has a silent order-detection path that scans conversation history and creates orders without interrupting the chat.
- The AI context is intentionally selective: product catalog data is only injected when purchase-related intent is detected.
7. Business data model and persistence
- User accounts live in data/users.json.
- Per-user configuration, products, and integration settings live under data/user_data/<userId>.json.
- Chat logs are stored under data/chats/, and detected orders under data/orders/.
- This makes the architecture strongly file-backed, with each user’s operational state separated by directory structure.
8. Commerce integrations boundary
- src/shopify.js handles store connection, product sync, and CSV import from Shopify.
- src/hotmart.js handles Hotmart account connection and product sync.
- These integrations feed the same internal product/catalog model used by the WhatsApp bot and dashboard.
9. Security and abuse protection
- src/security.js centralizes defensive middleware.
- It includes Helmet, global and endpoint-specific rate limiting, payload inspection, anti-flood checks, user-agent blocking, request timeouts, and IP handling behind proxies.
- The admin panel uses a random session token generated on each server start, so admin access is transient across restarts.
10. Admin subsystem
- src/admin-routes.js exposes /admin functionality for privileged operations.
- Admin capabilities include user management, per-user product limits, live file editing, backup download, and restore.
- This is a separate trust boundary from the normal SaaS dashboard, protected by password plus session token.
11. Operational flow
- Typical flow: user logs in via the web UI, saves bot and catalog settings, connects WhatsApp, and the backend stores everything in data/.
- Incoming WhatsApp messages trigger the bot pipeline: anti-spam/security checks, conversation persistence, optional AI response generation, and order detection.
- Manual dashboard actions can also modify chats, orders, bot mode, and integrations, all through the same file-backed state.
12. Important architectural consequence
- Because the system relies on local JSON files and session folders, the deployment model is stateful on disk.
- Architecture diagrams should show a single Express application with three major external dependencies: WhatsApp via Baileys, Groq for AI, and Shopify/Hotmart for catalog imports, all mediated by local file storage.
Main entry points: README.md README
Components 17
Backend
Express app, core API, automation, and admin boundary
- Server · Express startup, middleware wiring, session restore, and route mounting
- API · Main SaaS API for auth, profile, bot config, chats, orders, and integrations
- WhatsApp · Baileys connections, QR/pairing linking, and incoming message stream
- Bot AI · Prompt building, Groq calls, replies, and silent order detection
- Security · Helmet, rate limits, flood checks, blocking, timeouts, and proxy-aware IP handling
- Admin · Admin operations for user management, limits, file editing, backup, and restore
Frontend
Static dashboard and admin UI
- Web UI · Login, registration, dashboard, and admin pages served as static assets
Data
Local file-backed persistence and session state
- Users · User account records in the file-backed data layer
- User state · Per-user bot settings, products, and integration configuration
- Chats · Persisted WhatsApp conversation history
- Orders · Detected and manually managed order records
- WA sessions · Per-user/device WhatsApp session state restored on startup
Integrations
External services for messaging, AI, and commerce
- Shopify · Store connection, product sync, and CSV import
- Hotmart · Hotmart account connection and product synchronization
- Groq · External model provider used for bot reasoning and replies
- WhatsApp net · WhatsApp platform accessed through Baileys connections
Other components
- README · Repository overview and operational notes
README.md
Connections 24
- README → Server: describes · Documents the server-driven architecture and startup flow
- Server → Security: applies · Installs protective middleware before handling requests
- Server → API: mounts · Exposes the main SaaS API surface
- Server → Admin: mounts · Exposes privileged admin functionality
- Server → Web UI: serves · Hosts the static dashboard and admin pages
- Server → WhatsApp: initializes · Restores sessions and starts device connections
- Server → WA sessions: restores · Loads persisted WhatsApp sessions from disk
- API → Users: reads/writes · Manages accounts and user-scoped state
- API → User state: reads/writes · Stores bot settings, products, and integrations
- API → Chats: reads/writes · Persists conversation history
- API → Orders: reads/writes · Manages detected and manual orders
- API → WhatsApp: controls · Links devices, sends messages, and manages sessions
- API → Bot AI: invokes · Generates prompts and bot responses
- API → Shopify: uses · Connects stores and imports products
- API → Hotmart: uses · Connects accounts and syncs catalog data
- Admin → Users: administers · Manages users and per-user limits
- Admin → User state: edits · Allows live file editing of persisted settings
- WhatsApp → WhatsApp net: connects · Maintains Baileys connections to WhatsApp
- WhatsApp → Chats: emits · Stores incoming conversation events
- WhatsApp → Bot AI: feeds · Supplies message context for automation
- Bot AI → Groq: calls · Uses Groq models for reasoning and replies
- Bot AI → Orders: detects · Creates silent orders from conversation history
- Shopify → User state: updates · Writes imported catalog data into user state
- Hotmart → User state: updates · Writes synced catalog data into user state