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
- 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
- Set up the database:
# Start XAMPP and open phpMyAdmin
# Create a database named "code_editor"
# Import database/schema.sql
- 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
- 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
- Access the application:
- Frontend: http://localhost:3000
- Backend API: http://localhost:3001
- 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
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++
};
- Next.js
- React
- Monaco Editor (@monaco-editor/react)
- Socket.IO Client
- TailwindCSS
- Lucide React (for UI icons)
- Judge0 RapidAPI (code execution)
- Node.js
- Express
- Ballerina (WebSocket service)
- Socket.IO
- MySQL
- JWT Authentication
- Ballerina WebSocket (User registration & real-time features)
- Judge0 RapidAPI (Code execution)
- Socket.IO (Real-time collaboration)
- Lucide React Icons
- Monaco Editor
- Custom Tailwind Components
- XAMPP (MySQL)
- Nodemon
- ESLint
- JWT-based authentication
- Password hashing with bcrypt
- Protected API routes
- Secure WebSocket connections
- Secure code execution via Judge0 API
- Input validation and sanitization
- Judge0 RapidAPI:
- Sign up at RapidAPI
- Subscribe to Judge0 CE API
- Copy API key to .env.local
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.