Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

146 Commits

Repository files navigation

BrainVector

Production-grade collaborative workspace with real-time document sync and AI analysis capabilities.

Status: Backend Complete | Real-Time Infrastructure Ready | E2E Tests Passing | Dockerized | CI pipeline with github actions


Overview

BrainVector is a full-stack backend system for real-time document collaboration. The project demonstrates core backend competencies: secure authentication, WebSocket management, relational database design, caching strategies, and end-to-end testing.


Technology Stack

  • Runtime: Node.js + TypeScript
  • Framework: NestJS
  • Database: PostgreSQL with Prisma ORM
  • Cache: Redis
  • Real-Time: Socket.io
  • Testing: Jest (E2E) | supertest
  • Containerization: Docker & Docker Compose

Architecture

Core Modules

Authentication — JWT-based stateless auth with role-based access control. Token refresh mechanism with guard protection on secure routes.

Workspace Management — Multi-user workspace creation and member management. Enforces access control through RBAC guards. Handles concurrent user sessions.

Document Service — Full CRUD operations with real-time sync. Manages document ownership, member permissions, and update broadcasting through WebSocket.

Real-Time Gateway — WebSocket server handling persistent connections. Routes messages to document-specific rooms. Validates JWT on each connection.

Redis Caching — Caches user profiles and workspace metadata. Implements cache invalidation on updates.

Database Schema

  • users — Authentication and profile data
  • workspaces — Workspace metadata and ownership
  • documents — Document content and metadata
  • workspace_members — User-workspace relationships with roles
  • document_members — User-document access permissions

Features Implemented

  • User registration and login with JWT
  • Workspace creation and member invitation
  • Real-time document collaboration
  • Live cursor position tracking
  • WebSocket room-based message routing
  • Role-based access control (Owner, Editor, Viewer)
  • Secure authentication on WebSocket connections
  • Automatic token refresh
  • Connection pooling and caching optimization

E2E Tests

15+ end-to-end tests covering complete user workflows:

  • Authentication flows (signup, login, token refresh, logout)
  • Workspace operations (create, invite, permissions)
  • Document operations (create, update, delete, access control)
  • Real-time collaboration (multiple user sessions, live sync)
  • WebSocket connection and reconnection
  • Permission enforcement

Run tests:

npm run test:e2e # Full suite
npm run test:e2e --watch
npm run test:cov # Coverage

Getting Started

Prerequisites

  • Node.js v18+
  • Docker & Docker Compose

Installation

git clone https://github.com/yourusername/BrainVector.git
cd BrainVector
npm install
cp .env.example .env
# Configure environment variables
docker-compose up --build

Services available at:

  • Backend: http://localhost:3000
  • WebSocket: ws://localhost:3000
  • PgAdmin: http://localhost:5050
  • PostgreSQL: localhost:5432
  • Redis: localhost:6379

Development

# Run tests
npm run test:e2e
# Run with hot reload
npm run start:dev
# Build for production
npm run build
npm run start:prod

API Routes

MethodEndpointDescription
POST/auth/signupRegister new user
POST/auth/loginUser login
GET/auth/meGet current user
POST/workspacesCreate workspace
GET/workspacesList user workspaces
GET/workspaces/:idGet workspace details
POST/workspaces/:id/membersAdd member to workspace
POST/documentsCreate document
GET/documents/:idGet document
PATCH/documents/:idUpdate document
DELETE/documents/:idDelete document
WS/gatewayWebSocket connection

Project Structure

src/
├── auth/
│ ├── auth.service.ts
│ ├── auth.controller.ts
│ ├── jwt.strategy.ts
|
├── workspace/
│ ├── workspace.service.ts
│ ├── workspace.controller.ts
│ └── workspace.module.ts
├── document/
│ ├── document.service.ts
│ ├── document.controller.ts
│ └── document.module.ts
├── real-Time/
│ ├── real-Time.gateway.ts
│ └── real-Time.module.ts
|
└── main.ts
test/
├── auth.e2e-spec.ts
├── workspace.e2e-spec.ts
├── document.e2e-spec.ts
└── gateway.e2e-spec.ts //not written yet..

Key Implementation Details

WebSocket Management — Maintains persistent connections per user. Routes messages to document-specific rooms. Handles disconnection and automatic cleanup.

JWT Validation — Validates tokens on WebSocket connection. Implements refresh token rotation. Guards protect all authenticated endpoints.

Database Optimization — Prisma queries prevent N+1 problems. Indexes on frequently queried fields. Connection pooling configured.

Caching Strategy — Redis stores user and workspace data with TTL. Cache invalidation on updates. Reduces database load on high-traffic routes.

Error Handling — Custom exception filters across all services. Proper HTTP status codes. Structured error responses.


Performance

  • API response time: <100ms (with caching)
  • WebSocket message latency: <50ms
  • Docker image size: ~200MB
  • Test execution: ~15 seconds (full suite)
  • Database connection pool: 10 connections

Future Work

  • AI integration (Gemini RAG) for document Q&A
  • Frontend application (React)
  • CD pipeline with GitHub Actions
  • Advanced conflict resolution for concurrent edits
  • User presence indicators

Contact

Email:arunkoo072@gmail.com

Available for opportunities in backend development and system design.

About

BrainVector unifies team knowledge work by providing a workspace where users can create and manage documents collaboratively, invite members, and chat directly with their documents using LLM-powered insights — all within a secure, high-performance environment built with NestJS,Typescript.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages