How gitcoder052023/streamnet works
Project Type and Purpose
• StreamNet is a full-stack, microservices-based real-time chat application with built-in AI support.
• It comprises multiple Node.js services (Engine, Main Server, ChatLLama frontend & backend) plus static frontend assets, all collaborating over HTTPS/WebSockets and MongoDB.
Key Top-Level Directories
• ChatLLama/ ← AI service (separate frontend & backend)
• src/Engine/ ← Core Engine service handling WebSocket chat and HTTP
• Server/ ← Main HTTPS server (REST API, auth, static file serving)
• Public/ & Routes/ ← Static UI templates, CSS/JS, and routing helpers
• Shared config files (.env, SSL, ESLint, Tailwind)
Main Components
a. Client (Browser)
• Static UI (HTML/CSS/JS) served from the Main Server & Public folder
• ChatLLama UI served on port 3001
b. Engine Service (src/Engine) – Port 3000
• HTTP: health checks, environment config, rate limiting, CORS
• WebSocket: real-time chat socket (socket.io)
• Auth utils (JWT issuance, HMAC signing)
c. Main Server (Server/) – Port 4000 (HTTPS)
• Express routes: /auth, /conversations, /models
• Controllers & middleware (authMiddleware, validation, emailService)
• Static file serving (Public & Templates)
• WebSocket chat socket fallback or REST API for message history
d. ChatLLama Frontend – Port 3001
• Interactive AI chat UI (model selection, streaming controls)
• Communicates over WebSocket to ChatLLama Backend
e. ChatLLama Backend – Port 5000
• WebSocket API forwarding to local Ollama models
• MongoDB storage of AI conversations (ChatLLama database)
f. Databases
• MongoDB “StreamNet” – Users, Messages, Conversations, otps
• MongoDB “ChatLLama” – users, conversations
g. External Dependencies
• Gmail SMTP for OTP emails
• Local Ollama daemon (AI models)
Relationships & Data Flows
• Browser → HTTPS REST (Server: auth, conversation list)
• Browser ↔ WebSocket (Engine: real-time chat)
• Browser ↔ WebSocket (ChatLLama backend: AI streaming)
• Engine & Server → MongoDB StreamNet (CRUD)
• ChatLLama backend → MongoDB ChatLLama
• ChatLLama backend → Ollama daemon (AI inference)
• Server → Gmail SMTP (OTP delivery)
Architectural Patterns & Principles
• Microservices: independent Engine, Main Server, AI service
• Event-driven / Pub-sub: Socket.io for low-latency messaging
• Layered MVC in Main Server (routes → controllers → models)
• Security: SSL/TLS at every service, JWT & HMAC, input sanitization, rate limiting
• Theming & Responsive UI: Tailwind CSS, modular JS components