Skip to content

Advanced Code Editor Setup Guide – A powerful, collaborative code editor with real-time editing, multi-language execution, WebSocket integration, and modern UI built using Next.js, Node.js, and Ballerina. πŸ’»βœ¨

License

Notifications You must be signed in to change notification settings

pamaljayasinghe/Advanced-Code-Editor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Advanced Code Editor Setup Guide

Project Structure

code-editor/
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ CodeEditor.js
β”‚   β”‚   β”œβ”€β”€ Header.js
β”‚   β”‚   β”œβ”€β”€ Layout.js
β”‚   β”‚   └── UsersPanel.js
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ api.js
β”‚   β”‚   β”œβ”€β”€ auth.js
β”‚   β”‚   β”œβ”€β”€ socket.js
β”‚   β”‚   └── codeExecution.js
β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”œβ”€β”€ index.js
β”‚   β”‚   β”œβ”€β”€ login.js
β”‚   β”‚   └── register.js
β”‚   β”œβ”€β”€ styles/
β”‚   β”‚   └── globals.css
β”‚   β”œβ”€β”€ .env.local
β”‚   β”œβ”€β”€ next.config.js
β”‚   └── package.json
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── database.js
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ auth.js
β”‚   β”‚   └── files.js
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   └── auth.js
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ auth.js
β”‚   β”‚   └── files.js
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── websocket.bal     # Ballerina WebSocket service
β”‚   β”œβ”€β”€ .env
β”‚   β”œβ”€β”€ Ballerina.toml
β”‚   β”œβ”€β”€ package.json
β”‚   └── server.js
└── database/
    └── schema.sql

Setup Instructions

  1. Clone the repository and install dependencies:
# Clone the project
git clone https://github.com/pamaljayasinghe/Advanced-Code-Editor.git
cd code-editor

# Install frontend dependencies
cd frontend
npm install
# Install required UI packages
npm install lucide-react @monaco-editor/react
  1. Set up the database:
# Start XAMPP and open phpMyAdmin
# Create a database named "code_editor"
# Import database/schema.sql
  1. Configure environment variables:
# Frontend (.env.local)
NEXT_PUBLIC_API_URL=http://localhost:3001
NEXT_PUBLIC_WS_URL=ws://localhost:8080  # Ballerina WebSocket URL
RAPIDAPI_KEY=your-rapidapi-key-here    # Get from RapidAPI Judge0 API (Free)

# Backend (.env)
PORT=3001
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=
DB_NAME=code_editor
JWT_SECRET=your-secret-key-here
  1. Start the services:
# Terminal 1: Start frontend
cd frontend
npm run dev

# Terminal 2: Start backend
cd backend
npm run dev


#Terminal 3: Start Ballarina
cd backend
bal run services/websocket.bal
  1. Access the application:

Features

  • Real-time collaborative editing
  • Multi-language code execution via Judge0 API
    • JavaScript (Node.js)
    • Python
    • Java
    • C++
  • User authentication & authorization
  • File saving and loading
  • Syntax highlighting
  • Active user presence
  • Dark/Light theme support
  • Real-time code execution
  • Live output display
  • Modern UI with Lucide icons

Code Execution

The editor uses Judge0 RapidAPI for code execution:

  • Sign up at RapidAPI
  • Subscribe to Judge0 API
  • Get your API key and add it to codeExecution.js file

Supported Languages and IDs:

const LANGUAGE_IDS = {
  javascript: 63, // Node.js
  python: 71,    // Python 3
  java: 62,      // Java
  cpp: 54,       // C++
};

Tech Stack

Frontend

  • Next.js
  • React
  • Monaco Editor (@monaco-editor/react)
  • Socket.IO Client
  • TailwindCSS
  • Lucide React (for UI icons)
  • Judge0 RapidAPI (code execution)

Backend

  • Node.js
  • Express
  • Ballerina (WebSocket service)
  • Socket.IO
  • MySQL
  • JWT Authentication

Services

  • Ballerina WebSocket (User registration & real-time features)
  • Judge0 RapidAPI (Code execution)
  • Socket.IO (Real-time collaboration)

UI Components

  • Lucide React Icons
  • Monaco Editor
  • Custom Tailwind Components

Development Tools

  • XAMPP (MySQL)
  • Nodemon
  • ESLint

Security Features

  • JWT-based authentication
  • Password hashing with bcrypt
  • Protected API routes
  • Secure WebSocket connections
  • Secure code execution via Judge0 API
  • Input validation and sanitization

Required API Keys

  1. Judge0 RapidAPI:
    • Sign up at RapidAPI
    • Subscribe to Judge0 CE API
    • Copy API key to .env.local

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Advanced Code Editor Setup Guide – A powerful, collaborative code editor with real-time editing, multi-language execution, WebSocket integration, and modern UI built using Next.js, Node.js, and Ballerina. πŸ’»βœ¨

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published