Skip to main content

Overview

Genie Helper runs 7 services managed by PM2. This page documents each service, their ports, PM2 configuration, and how they interact.

Service Architecture

Services Table

Service Details

1. AnythingLLM (anything-llm)

Port: 3001
Purpose: Core AI agent, chat API, MCP server orchestration
Features:
  • REST API for chat, workspaces, documents
  • WebSocket support for streaming responses
  • Embed widget hosting (/embed/anythingllm-chat-widget.min.js)
  • MCP server auto-boot (Directus, Ollama, Stagehand)
  • Action Runner plugin for pre-built flows
  • Custom endpoints: registration, RBAC sync, credentials, queue management
Key Files:
  • server/index.js - Express entrypoint
  • server/utils/boot/index.js - MCP server boot logic
  • server/utils/actionRunner/ - Action flow executor
  • storage/ - Persistent data, documents, vector store
Dependencies:
  • Ollama (11434) for LLM inference
  • Directus (8055) for data storage
  • Stagehand (3002) for browser automation

2. Directus CMS (agentx-cms)

Port: 8055
Purpose: Data layer, collections, authentication, REST API
Key Collections:
  • creator_profiles - Platform accounts with encrypted credentials
  • scraped_media - Content with engagement metrics
  • scheduled_posts - Post queue (polled by media worker every 60s)
  • media_jobs - BullMQ job records
  • hitl_sessions - Human-in-the-loop login requests
  • platform_sessions - Encrypted browser cookies
  • taxonomy_dimensions - 6 super-concept classification system
  • taxonomy_mapping - 3208 classified tags
  • fan_profiles - Fan engagement data
  • action_flows - Action Runner flow definitions
  • agent_audits - ACTION execution logs
Authentication:
  • JWT tokens for end-users (React SPA)
  • Static admin token for server-to-server API calls
Security:
  • Platform credentials encrypted with AES-256-GCM
  • encryptJSON() / decryptJSON() in server/utils/credentialsCrypto.js
  • No encryption keys in browser - server-side only

3. Stagehand (stagehand-server)

Port: 3002
Purpose: Browser automation for platform scraping and posting
Capabilities:
  • Headless Chrome sessions with stealth mode
  • Navigate, click, extract, screenshot
  • Cookie management (set/get)
  • Session lifecycle (start/close)
Used By:
  • Media worker jobs (scrape, publish)
  • Stagehand MCP server (9 tools for AI agent)
Resource Usage:
  • ~300MB RAM per active browser session
  • ~33 concurrent sessions max (with 10GB available RAM)

4. Dashboard (genie-dashboard)

Port: 3100 (if using serve, otherwise static files served by Nginx)
Purpose: React SPA - marketing, authentication, creator dashboard
Routes:
  • Public: /, /pricing, /about, /register, /login
  • Authenticated: /app/dashboard, /app/media, /app/calendar, /app/fans, /app/analytics, /app/platforms, /app/settings
  • Admin: /admin (Directus + AnythingLLM iframes), /view-as (impersonation)
Features:
  • AI chat widget (AnythingLLM embed) on all /app/* routes
  • Embed ID: cf54a9c0-224c-469d-b97b-5dc8095eac82
  • Directus JWT auth (auto-refresh, sessionStorage for impersonation)
  • Invite-gated registration
  • Theme switcher (ImpactGenie brand palette)
Build:
Output: dashboard/dist/ served by Nginx at document root.

5. Media Worker (media-worker)

Port: None (BullMQ consumer)
Purpose: Background job processing via Redis/BullMQ
Job Types:
  1. scrape_profile - Stagehand OF login + data extraction
  2. publish_post - Cross-platform posting via Stagehand
  3. apply_watermark - ImageMagick watermarking (~100ms)
  4. create_teaser - FFmpeg video preview (~30s CPU per clip)
  5. post_scheduler - Polls scheduled_posts collection every 60s
Configuration:
  • Concurrency: 3 jobs (configurable via WORKER_CONCURRENCY)
  • Redis connection: 127.0.0.1:6379
  • Scheduler interval: 60000ms (60s)
Resource Bottlenecks:
  • FFmpeg clip generation: ~30s CPU per clip (real bottleneck)
  • Watermark: ~100ms (effectively zero cost)
  • Stagehand sessions: ~300MB RAM each

6. Collector (anything-collector)

Port: None
Purpose: Document ingestion for AnythingLLM vector store
Processes:
  • Monitors storage/documents/ for new files
  • Chunks and embeds documents
  • Updates vector store for RAG retrieval
Embedding Model: bge-m3:latest (via Ollama)

7. Ollama (System Service)

Port: 11434
Purpose: Local LLM inference engine
Installed Models: Managed by: systemd (not PM2)
Performance:
  • CPU-only: ~33s first token for agent mode (qwen-2.5)
  • GPU recommended for production

PM2 Configuration

Starting All Services

Create ecosystem.config.cjs in project root:
Start with ecosystem file:

PM2 Commands

Status and Monitoring

Restart and Reload

Stop and Delete

Flush Logs

Service Interactions

Data Flow

  1. User → Dashboard (React SPA)
    • User interacts with UI at geniehelper.com/app/*
    • Dashboard makes API calls to /api/directus/ and /api/llm/
  2. Dashboard → Directus (via Nginx proxy)
    • CRUD operations on collections
    • JWT authentication
    • File uploads
  3. Dashboard → AnythingLLM (via Nginx proxy)
    • Chat messages via embed widget
    • Streaming responses (SSE)
    • Document management
  4. AnythingLLM → MCP Servers
    • Directus MCP: 17 tools (CRUD, flows, users, files)
    • Ollama MCP: 3 tools (generate, chat, list-models)
    • Stagehand MCP: 9 tools (browser sessions, navigation, extraction)
  5. AnythingLLM → Ollama
    • LLM inference requests
    • Embeddings generation
    • Model selection based on task
  6. Media Worker → Directus
    • Poll scheduled_posts every 60s
    • Read media_jobs for processing
    • Update job status and results
  7. Media Worker → Stagehand
    • Create browser sessions
    • Navigate to platforms
    • Extract data or publish content
  8. Media Worker → ImageMagick/FFmpeg
    • Apply watermarks (ImageMagick)
    • Generate video teasers (FFmpeg)

Authentication Flow

  1. User registers via /register (React route)
  2. Dashboard calls /api/llm/api/register (server-side proxy)
  3. AnythingLLM creates Directus user via DIRECTUS_ADMIN_TOKEN
  4. User logs in via Directus JWT
  5. JWT stored in localStorage, sent with all API requests
  6. RBAC sync webhook keeps AnythingLLM users in sync with Directus roles

Platform Scraping Flow

  1. User connects platform via /app/platforms
  2. Browser extension or manual cookie upload
  3. Encrypted cookies stored in platform_sessions
  4. User clicks “Scrape Profile” button
  5. Dashboard creates media_jobs record
  6. Media worker picks up job from BullMQ
  7. Worker decrypts credentials, starts Stagehand session
  8. Stagehand navigates, extracts data
  9. Worker stores results in scraped_media
  10. Dashboard polls job status, updates UI

Troubleshooting

Service Won’t Start

Memory Issues

MCP Servers Not Loading

BullMQ Jobs Stuck

Quick Reference

Next Steps