Skip to content

sachinggsingh/Sync-Backend

Repository files navigation

πŸš€ SyncEditor Server

Node Version Express Version Socket.io Version OTel License

Backend server for the SyncEditor collaborative code editor platform. Built for performance, security, and real-time synchronization.


πŸ“– Overview

SyncEditor Server is a high-performance Node.js service providing the backbone for real-time collaboration. It leverages Socket.IO for low-latency communication and integrated OpenTelemetry for production-grade observability.

Authentication model: the current implementation is intentionally simple – clients supply a plain username when emitting the join event; the server does not perform any credentials check. This keeps the focus on the collaboration features and makes the service easier to run locally.

✨ Features

  • ⚑ Real-Time Sync: Low-latency code and chat synchronization.
  • 🏒 Room Management: Secure, isolated collaborative environments.
  • πŸ›‘οΈ Production Security: Rate limiting, XSS protection, and CSP headers.
  • πŸ” First-Class Observability: Distributed tracing with Jaeger v2 and log aggregation with Grafana/Loki.
  • πŸ§ͺ Simple auth: clients provide a username when joining; no backend login required.

Flow of the things how it's going on

System representation

πŸ“Š Monitoring & Observability

Standardized observability using OpenTelemetry and Jaeger v2.

πŸ” Distributed Tracing

Visualize the entire lifecycle of collaborative events.

Trace 1
System interaction visualization and latency analysis.

Trace 2
Deep dive into span processing and event execution.

Trace 3
Real-time collaboration concurrency tracking.

πŸ“ Structured Logs & Aggregation

Powered by winston, enriched with OpenTelemetry context, and aggregated via Loki.

  1. Enrichment: Logs are automatically injected with trace_id and span_id.
  2. Scraping: Promtail tails the JSON log files.
  3. Aggregation: Logs are pushed to Loki for indexing.
  4. Visualization: View and query logs in Grafana, with direct links to distributed traces.
  5. Insights: Real-time log monitoring for rapid debugging.
Loki Logs
Centralized log aggregation in Grafana Loki.

πŸ› οΈ Tech Stack


πŸš€ Quick Start

1. Installation

npm install

2. Configuration

Create a .env file:

PORT=5555
FRONTEND_URL=http://localhost:5173
NODE_ENV=development
SOCKET_PING_TIMEOUT=120000
SOCKET_PING_INTERVAL=30000

3. Execution

Command Description
npm run dev Start development server with Nodemon
npm start Run production-ready server

πŸ”Œ Socket.IO API

πŸ“€ Outgoing (Client β†’ Server)

  • join: { roomId, username }
  • leave: { roomId, username }
  • code-change: { roomId, code, sender }
  • send-message: { roomId, message, sender, time }

πŸ“₯ Incoming (Server β†’ Client)

  • user-joined: { clients, username, socketId }
  • user-left: { socketId, username }
  • code-change: { code, sender }
  • receive-message: { message, sender, time }
  • error: { message }

πŸ—οΈ Project Structure

Server/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.js             # Entry point: Starts server & initializes OTel
β”‚   β”œβ”€β”€ app.js               # Application setup: Middleware, routes, & error handling
β”‚   β”œβ”€β”€ config/              # Configuration files
β”‚   β”‚   β”œβ”€β”€ otel.js          # OpenTelemetry SDK configuration
β”‚   β”‚   └── clerk.js         # Authentication configuration (Clerk)
β”‚   β”œβ”€β”€ middleware/          # Express middleware
β”‚   β”‚   β”œβ”€β”€ auth.js          # Authentication & user identification
β”‚   β”‚   β”œβ”€β”€ rateLimiter.js   # Resource usage control
β”‚   β”‚   └── validator.js     # Input schema validation
β”‚   β”œβ”€β”€ sockets/             # Socket.IO implementation
β”‚   β”‚   β”œβ”€β”€ index.js         # Socket server initialization
β”‚   β”‚   └── handlers.js      # Core logic for code sync, chat, & room management
β”‚   └── utils/               # Helper functions
β”‚       └── logger.js        # Winston structured logging setup
β”œβ”€β”€ otel-config/             # Observability infrastructure config
β”‚   β”œβ”€β”€ logging/             # Loki, Promtail, & Grafana setup
β”‚   └── otel/                # OTel Collector configurations
β”œβ”€β”€ k8s/                     # Kubernetes manifests
β”‚   β”œβ”€β”€ deployment.yaml      # App deployment & container spec
β”‚   β”œβ”€β”€ service.yaml         # LoadBalancer & port config
β”‚   └── hpa.yaml             # Horizontal Pod Autoscaler
β”œβ”€β”€ assets/                  # Documentation images & screenshots
β”œβ”€β”€ tests/                   # Integration & Unit test suites
β”œβ”€β”€ Dockerfile               # Production container definition
└── package.json             # Dependencies & scripts

πŸ› οΈ Detailed Component Roles

  • Socket Handlers: The brain of the real-time engine, handling complex concurrency for code edits and ensuring all room participants stay in sync.
  • OTel Infrastructure: Provides the full observability pipeline, mapping application events to distributed traces for debugging production issues.
  • K8s Manifests: Production-ready configurations for deploying the server in a scalable Kubernetes environment with automated scaling.
  • Security Middleware: Multi-layered protection including rate limiting to prevent abuse and schema validation for all incoming socket/HTTP payloads.

πŸ›‘οΈ Security

  • Rate Limiting: 100 req/15min per IP.
  • Validation: Strict schema validation for all inputs.
  • Headers: Helmet-secured headers (XSS, HSTS, CSP).

πŸ—ΊοΈ Roadmap

  • Tracing (Jaeger)
  • Centralized Log Aggregation (Loki/Grafana)
  • Distributed Metrics (Prometheus)
  • Health Dashboard UI
  • Custom Performance Spans

βš–οΈ License

Distributed under the MIT License. See LICENSE for more information.

About

SyncEditor Server is a high-performance Node.js service providing the backbone for real-time collaboration. It leverages Socket.IO for low-latency communication and integrated OpenTelemetry for production-grade observability

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors