Skip to content

jeujai/collaborative-editor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Collaborative Document Editor

A real-time collaborative document editing application that allows multiple users to edit the same document simultaneously from different devices.

Features

  • Real-time collaborative editing - Multiple users can edit the same document simultaneously
  • Rich text formatting - Support for bold, italic, underline, headers, lists, and colors
  • Conflict resolution - Uses Operational Transformation to merge concurrent edits
  • WebSocket synchronization - Low-latency bidirectional communication
  • Offline support - Queue changes when disconnected and sync on reconnection
  • Auto-save - Documents are automatically persisted to storage
  • AWS deployment - Production-ready infrastructure with auto-scaling

Architecture

  • Frontend: React 18 + Vite + Quill editor + Socket.io-client
  • Backend: Node.js + Express + Socket.io WebSocket server
  • Database: AWS DynamoDB for document persistence
  • Infrastructure: AWS ECS Fargate, Application Load Balancer, S3 + CloudFront CDN
  • IaC: AWS CDK for infrastructure as code

Getting Started

Prerequisites

  • Node.js 18+ - Download
  • npm - Comes with Node.js
  • AWS CLI (for deployment) - Installation guide
  • AWS CDK (for deployment) - Install with npm install -g aws-cdk

Installation

  1. Clone the repository

    git clone <repository-url>
    cd collaborative-editor
  2. Install dependencies

    # Install all dependencies at once
    cd client && npm install
    cd ../server && npm install
    cd ../infrastructure && npm install
    cd ..
  3. Configure environment variables

    Client configuration:

    cd client
    cp .env.example .env
    # Edit .env if needed (default: http://localhost:3001)

    Server configuration:

    cd server
    cp .env.example .env
    # Edit .env if needed (defaults are set for local development)

Development

Running the application locally

Option 1: Run both servers together (recommended)

npm run dev

Option 2: Run servers separately

# Terminal 1 - Start the backend server
npm run dev:server

# Terminal 2 - Start the frontend dev server
npm run dev:client

The application will be available at:

Development mode features

  • Hot reloading - Both frontend and backend support hot reloading
  • In-memory storage - No DynamoDB required for local development
  • CORS enabled - Configured for localhost development

Testing

Run all tests:

npm test

Run tests for specific components:

npm run test:client   # Frontend tests
npm run test:server   # Backend tests

Run tests in watch mode (for development):

cd client && npm run test:watch
# or
cd server && npm run test:watch

Building for Production

Build the frontend application:

npm run build

This creates an optimized production build in client/dist/.

Deployment to AWS

First-time AWS Setup

  1. Configure AWS credentials

    aws configure

    Enter your AWS Access Key ID, Secret Access Key, and preferred region.

  2. Bootstrap CDK (only needed once per AWS account/region)

    npm run deploy:bootstrap

Deploying the Application

  1. Review infrastructure changes (optional)

    npm run deploy:diff
  2. Deploy to AWS

    npm run deploy

    This command will:

    • Build the frontend application
    • Deploy the CDK stack (DynamoDB, ECS, ALB, S3, CloudFront)
    • Upload frontend assets to S3
    • Deploy the backend container to ECS Fargate

    The deployment takes approximately 10-15 minutes.

  3. Get deployment URLs

    After deployment completes, CDK will output:

    • CloudFront URL - Your frontend application URL
    • ALB DNS Name - Your backend WebSocket server URL
    • DynamoDB Table Name - The document storage table
  4. Update frontend environment

    Update client/.env with the production backend URL:

    VITE_SERVER_URL=https://your-alb-url.amazonaws.com
    

    Then redeploy:

    npm run deploy

Destroying AWS Resources

To remove all AWS resources and avoid charges:

npm run deploy:destroy

Warning: This will delete all documents stored in DynamoDB.

Project Structure

collaborative-editor/
├── client/                      # React frontend application
│   ├── src/
│   │   ├── components/
│   │   │   ├── Editor.jsx      # Quill editor component
│   │   │   └── Editor.test.jsx # Editor tests
│   │   ├── App.jsx             # Root component
│   │   ├── socket.js           # WebSocket connection
│   │   └── main.jsx            # Application entry point
│   ├── .env.example            # Environment variables template
│   └── package.json
│
├── server/                      # Node.js WebSocket server
│   ├── server.js               # Main server file
│   ├── documentStore.js        # Storage abstraction
│   ├── server.test.js          # Server tests
│   ├── .env.example            # Environment variables template
│   ├── Dockerfile              # Container image definition
│   └── package.json
│
├── infrastructure/              # AWS CDK infrastructure code
│   ├── lib/
│   │   └── stack.js            # CDK stack definition
│   ├── app.js                  # CDK app entry point
│   └── package.json
│
├── package.json                 # Root package.json with scripts
└── README.md                    # This file

Environment Variables

Client (.env)

Variable Description Default
VITE_SERVER_URL WebSocket server URL http://localhost:3001

Server (.env)

Variable Description Default
PORT Server port 3001
CLIENT_URL Frontend URL for CORS http://localhost:5173
USE_DYNAMODB Enable DynamoDB storage false
DYNAMODB_TABLE_NAME DynamoDB table name CollaborativeDocuments
AWS_REGION AWS region us-east-1

Available Scripts

Root Level

Script Description
npm run dev Run both client and server in development mode
npm run dev:client Run only the frontend dev server
npm run dev:server Run only the backend dev server
npm run build Build the frontend for production
npm test Run all tests (client + server)
npm run test:client Run frontend tests
npm run test:server Run backend tests
npm run deploy Deploy to AWS
npm run deploy:bootstrap Bootstrap CDK (first-time setup)
npm run deploy:diff Preview infrastructure changes
npm run deploy:destroy Remove all AWS resources

Usage

  1. Open the application in your browser
  2. Start typing - Your changes are automatically saved
  3. Share the URL with collaborators - They'll see your changes in real-time
  4. Format text using the toolbar (bold, italic, headers, lists, colors)
  5. Connection status is shown in the header (green = connected, red = disconnected)
  6. Active users count is displayed in the header

Troubleshooting

Port already in use

If port 3001 or 5173 is already in use:

# Change the port in server/.env
PORT=3002

# Change the port in client/.env
VITE_SERVER_URL=http://localhost:3002

WebSocket connection fails

  • Ensure the backend server is running
  • Check that VITE_SERVER_URL in client/.env matches the server URL
  • Verify firewall settings allow WebSocket connections

DynamoDB errors in production

  • Ensure the ECS task role has DynamoDB permissions
  • Verify USE_DYNAMODB=true in production environment
  • Check CloudWatch logs for detailed error messages

CDK deployment fails

  • Ensure AWS credentials are configured: aws configure
  • Run npm run deploy:bootstrap if you haven't bootstrapped CDK
  • Check that you have sufficient AWS permissions

Performance

  • Document load time: < 1 second for documents up to 100KB
  • Change propagation: < 100ms latency
  • Concurrent users: Supports 1000+ users per document
  • Document size limit: 10 MB maximum
  • Auto-scaling: ECS tasks scale based on CPU/memory utilization

Security

  • HTTPS/WSS: All production traffic uses secure connections
  • CORS: Configured to allow only specified origins
  • Input validation: Document IDs and operations are validated
  • Rate limiting: 100 operations per second per client
  • DynamoDB encryption: Data encrypted at rest

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages