This document describes the full architecture, workflow, and development setup for the Ask-With-Context platform — a distributed system designed for file-based knowledge extraction, real-time communication, and LLM-powered conversation.
| Service | Description | Port |
|---|---|---|
client |
Frontend application (React) | 3000 |
http-server |
Handles user authentication and APIs | 3001 |
file-handler |
Manages file uploads and processing | 3002 |
worker-server |
LLM worker that processes chat queries | 3003 |
ws-server |
WebSocket gateway for real-time messaging | 8080 |
nats-server |
Message broker for live file update broadcasts | 4222 |
kafka-broker |
Kafka cluster for async event-driven processing | 9092 |
The file handler follows these steps:
- Listens to
file-handlerKafka topic - Downloads the file from S3
- Processes and summarizes it
- Stores summarized content along with
chatIdandsessionId - Sends status updates to NATS so that clients can see real-time progress
Subject: file.update.${sessionId}
Payload:
{
"status": "processing",
"progress": 80
}When a user sends a chat message via WebSocket:
- Message → Published to Kafka topic
llm-query - Worker Server consumes
llm-querytopic, processes query with the LLM - Worker publishes output to Kafka topic
llm-response - WebSocket Server consumes
llm-responseand sends result back to the correct user
sequenceDiagram
participant Client
participant WebSocket Server
participant Kafka
participant Worker Server
Client->>WebSocket Server: Send message
WebSocket Server->>Kafka: Publish to "llm-query"
Kafka->>Worker Server: Consume message
Worker Server->>Kafka: Publish to "llm-response"
Kafka->>WebSocket Server: Consume response
WebSocket Server->>Client: Send LLM response
✅ Real-time updates for file summaries and chat results are sent through NATS.
| Method | Endpoint | Description |
|---|---|---|
| POST | /user/signup |
Register a new user |
| POST | /user/signin |
Authenticate a user |
| GET | /api/userCredentials |
Get user info |
| Method | Endpoint | Description |
|---|---|---|
| POST | /uploadFile/uploadFile |
Upload file and initiate processing |
| Method | Endpoint | Description |
|---|---|---|
| GET | /getSessions/getUserSessions/session |
Get active sessions |
| GET | /getSessions/getUserSessions/getSessionData |
Fetch session data with summaries |
| Topic | Publisher | Consumer | Purpose |
|---|---|---|---|
file-handler |
HTTP Server | File Handler | File processing queue |
llm-query |
WebSocket Server | Worker Server | Incoming chat queries |
llm-response |
Worker Server | WebSocket Server | LLM responses to client |
| Subject Pattern | Producer | Consumer | Description |
|---|---|---|---|
file.update.${sessionId} |
File Handler | WebSocket Server / Client | File processing progress |
llm.update.${chatId} |
Worker Server | WebSocket Server | LLM response updates |
git clone https://github.com/<your-username>/ask-with-context.git
cd ask-with-contextCreate .env in the root:
# Core
NODE_ENV=development
BASE_URL=http://localhost:3001
# Ports
HTTP_PORT=3001
WS_PORT=8080
FILE_HANDLER_PORT=3002
WORKER_PORT=3003
# AWS
AWS_ACCESS_KEY_ID=your_key
AWS_SECRET_ACCESS_KEY=your_secret
S3_BUCKET=your_bucket
# Kafka
KAFKA_BROKER=kafka:9092
KAFKA_CLIENT_ID=ask_with_context
# Redis / NATS
REDIS_HOST=redis
NATS_URL=nats://nats:4222docker compose up --buildThis starts all core services:
- HTTP Server →
:3001 - File Handler →
:3002 - Worker Server →
:3003 - WebSocket Server →
:8080 - Kafka, NATS, Redis → Internal containers
Check logs:
docker ps
docker logs http-server -fAccess:
- API: http://localhost:3001
- Client: http://localhost:3000
- Kafka UI: http://localhost:8085
- NATS: http://localhost:8222
| Component | Scalable | Description |
|---|---|---|
| WebSocket Servers | ✅ Horizontal | Each manages its own clients |
| Kafka Topics | ✅ High throughput | Decoupled message passing |
| File Handler | ✅ Parallelizable | Multiple consumers per topic |
| Worker Server | ✅ Horizontally scalable | Each handles a share of LLM queries |
| NATS | ✅ Real-time | Lightweight push-based communication |
This system uses Turborepo to manage multiple services efficiently.
apps/
├─ client/
├─ http-server/
├─ file-handler/
├─ worker-server/
└─ ws-server/