Skip to main content
Architecture overview for the Weam AI platform across Node.js backend and Next.js frontend.

Architecture Evolution

Weam AI uses a streamlined architecture with Node.js handling all backend operations through LangGraph for intelligent AI orchestration.

Node.js Backend Architecture

Core Application Stack

ComponentTechnology
Backend FrameworkExpress.js
AI OrchestrationLangGraph
Task QueueBull (Redis-based)
Job SchedulerAgenda
DatabaseMongoDB
AuthenticationJWT + Middleware
StreamingSocket.IO

AI & Vector Layer

ComponentTechnology
LLMsOpenAI, Gemini, Anthropic, HuggingFace
AI OrchestrationLangGraph (intelligent routing)
EmbeddingsGemini, OpenAI
Vector DatabasePinecone (Primary), Qdrant (Optional)
Web SearchSearxNG (self-hosted metasearch)
Image GenerationOpenAI DALL·E
Direct API integration for OpenAI, Anthropic, Gemini, and HuggingFace. OpenRouter used for LLaMA, DeepSeek, Grok, and Qwen models.

Security & Configuration

  • API key encryption with internal crypto module
  • JWT tokens for access and refresh authentication
  • Environment-based configuration (.env files)
  • Role-based access control

Real-time & Storage

  • Socket.IO for live updates and streaming responses
  • Redis Pub/Sub for socket scaling
  • SMTP email integration
  • MinIO / AWS S3 file storage with parallel processing
  • Event streaming for optimized file uploads
Socket scaling across multiple servers uses Redis Pub/Sub. See socket scaling guide for implementation details.

Next.js Frontend Architecture

Framework & UI

ComponentTechnology
Frontend FrameworkNext.js (App Router)
Type SystemTypeScript
StylingTailwind CSS
State ManagementRedux Toolkit
FormsFormik + Custom Inputs
RoutingNext.js File System
AuthenticationFirebase + IronSession

Module Structure

ModulePath
Authenticationsrc/app/(auth) + src/actions/auth.ts
Chat & Threadssrc/components/Chat + src/hooks/chat
Custom GPTsrc/components/CustomGpt
Workspacesrc/components/Workspace + src/hooks/workspace
File Uploadssrc/components/FileUpload* + src/hooks/storage
Reportssrc/app/(page)/settings/reports

AI Integration

  • Socket.IO client for real-time AI responses
  • Single event emission for all AI operations
  • Backend-driven operation routing
  • Asset serving through S3/MinIO

Request Processing Architecture

Client Request (Socket Event)

[Node.js Backend] → Single entry point

[LangGraph Router] → Intelligent operation detection

[Operation Handler] → Execute appropriate flow:
    • Normal Chat → LLM call
    • Web Search → SearxNG + LLM
    • Image Generation → DALL·E
    • Document Chat → Pinecone + LLM
    • Agent Chat → Agent prompt + LLM
    • Agent + Document → Combined context + LLM

[Response Stream] → Socket.IO streaming to frontend

Response → Real-time display in UI

LangGraph Flow Management

Intelligent Backend Routing

LangGraph handles all decision-making for operation types: Single Call Operations:
  • Normal chat queries
  • Document-based questions
  • Agent conversations
  • Combined agent + document queries
Two-Call Operations (when tools required):
  • Web search integration
  • Image generation requests
  • Vision model processing

Operation Detection

Backend automatically identifies:
  • Tool requirements (web search, image generation)
  • Document context needs
  • Agent selection
  • Model capabilities and limitations

Service Communication

  • Frontend ↔ Node.js: Single Socket.IO event for all operations
  • Node.js ↔ LLMs: Direct API calls through LangGraph
  • Backend ↔ Database: MongoDB connections
  • Task Processing: Bull + Redis queues
  • Real-time Updates: Socket.IO + Redis Pub/Sub
  • File Processing: Parallel S3 upload and vector embedding

File Upload Optimization

Parallel Processing Architecture

User Upload

Event Streaming to Backend

Parallel Processing (2 chunks at a time):
    ├─ Chunk 1 → S3 Upload
    └─ Chunk 2 → Vector Embedding (Pinecone)

Optimized Speed & Performance

Web Search Architecture

SearxNG Integration

  • Independence: No dependency on OpenAI’s search features
  • Self-hosted: Complete control over search infrastructure
  • Universal: Works with all models except GPT-4o latest, DeepSeek, and Qwen
  • Privacy: No external search API dependencies

Deployment Architecture

All services are containerized using Docker and orchestrated with Docker Compose:
  • Development: Local Docker containers
  • Production: Multi-container deployment
  • Secrets: Environment variables and secret managers
  • Monitoring: Socket.IO event tracking and logging
I