Architecture overview for the Weam AI platform across Python backend, Node.js API, and Next.js frontend.

Python Backend Architecture

Core Application Stack

ComponentTechnology
Backend FrameworkFastAPI
Task QueueCelery
BrokerRedis
DatabaseMongoDB
AuthenticationJWT + Middleware
Task MonitorFlower
StreamingFastAPI StreamingResponse

AI & Vector Layer

ComponentTechnology
LLMsOpenAI, Gemini, Anthropic, HuggingFace
EmbeddingsLangChain, Gemini, OpenAI
Vector DatabaseQdrant (Primary), Pinecone (Optional)
Web ScrapingPlaywright, BeautifulSoup, Crawler4AI
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

Testing & Debugging

ToolPurpose
PytestUnit testing
LocustLoad testing
WDBWeb-based visual debugger
Docker OverrideTest environment setup

Infrastructure

ComponentDescription
DockerService containerization
Docker ComposeMulti-environment orchestration
GitHub ActionsCI/CD pipeline
PrometheusMetrics and monitoring
Async LoggerCustom logging implementation

Node.js API Architecture

Core Backend

ComponentTechnology
Web ServerExpress.js
Task QueueBull (Redis-based)
Job SchedulerAgenda
AuthenticationJWT Middleware
Database ORMMongoose (MongoDB)
Real-timeSocket.IO

Security & Middleware

  • Role-based access control via JWT
  • Rate limiting with express-rate-limit
  • Encrypted API keys with custom middleware
  • Environment configuration via dotenv

Development Tools

  • Winston + Morgan for logging
  • Chrome DevTools / VSCode debugging
  • Live reload with nodemon

Real-time & Storage

  • Socket.IO for live updates
  • Redis Pub/Sub for socket scaling
  • SMTP email integration
  • MinIO / AWS S3 file storage
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

  • Modular API clients in /src/actions/
  • LLM provider integration (OpenAI, Gemini, Anthropic)
  • Vector search via Qdrant/Pinecone
  • Asset serving through S3/MinIO

Python API Request Lifecycle

Client Request

[gateway/] → FastAPI/Nginx entrypoint

[middleware/] → Auth, logging, rate limits

[schema/] → Pydantic validation

[router/] → Endpoint routing

[controller/] → Request logic

[service/] → Business logic

[models/] → MongoDB interaction

[exceptions/] → Error handling

[utils/] → Helper methods

Response → JSON/Streaming to client

Service Communication

  • Frontend ↔ Node.js: REST API + Socket.IO
  • Node.js ↔ Python: HTTP API calls
  • Backend ↔ Database: MongoDB connections
  • Task Processing: Celery + Redis queues
  • Real-time Updates: Socket.IO + Redis Pub/Sub

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: Prometheus metrics collection