Skip to content

neyamulhasan/BrainJam

Repository files navigation

🧠 BrainJam Arena

A complete competitive programming platform with Docker support, Judge0 API integration, and military-style ranking system. Perfect for coding competitions, practice, and learning.

BrainJam Arena Node.js MySQL Docker

✨ Features

  • πŸ” Complete Authentication System - JWT-based secure login/registration
  • πŸ’» Multi-Language Code Execution - C++, Python, Java, JavaScript support via Judge0 API
  • πŸ† Military Ranking System - From Private Recruit to Legendary General
  • 🏁 Contest Management - Create, manage, and participate in coding contests
  • πŸ“š Learning Resources - Structured learning paths and tutorials
  • πŸ‘¨β€πŸ’Ό Admin Dashboard - Complete platform management
  • 🎯 Problem Categories - Algorithmic challenges with difficulty levels
  • πŸ“Š Progress Tracking - Statistics, streaks, and performance analytics
  • 🌐 Responsive Design - Works on desktop, tablet, and mobile
  • 🐳 Docker Ready - One-command deployment

πŸš€ Quick Start (Docker - Recommended)

Prerequisites

  • Docker Desktop (Windows/Mac) or Docker Engine (Linux)
  • Git (to clone the repository)

One-Command Setup

# 1. Clone the repository
git clone https://github.com/neyamulhasan/BrainJam.git
cd BrainJam

# 2. Quick setup (Windows)
quick-setup.bat

# 2. Quick setup (Linux/macOS)
chmod +x quick-setup.sh && ./quick-setup.sh

Manual Docker Setup

# 1. Copy environment configuration
cp .env.shared .env

# 2. Start containers
docker-compose up -d

# 3. Initialize database
docker-compose exec app npm run init-db

# 4. Access application
# http://localhost:3000

πŸ› οΈ Local Development Setup

Prerequisites

  • Node.js v18 or higher
  • MySQL 8.0 or XAMPP
  • Git

Installation Steps

  1. Clone and Install

    git clone https://github.com/neyamulhasan/BrainJam.git
    cd BrainJam
    npm install
  2. Database Setup

    # Option A: Use existing MySQL
    # Make sure MySQL is running on port 3306
    
    # Option B: Use XAMPP
    # Start Apache and MySQL services (port 4306)
  3. Environment Configuration

    cp .env.example .env
    # Edit .env with your database credentials
  4. Initialize Database

    npm run init-db
    npm run init-learning
  5. Start Application

    # Development mode
    npm run dev
    
    # Production mode  
    npm start
    
    # Production mode
    npm start

πŸ”§ Configuration

Environment Variables

For Docker (Recommended):

  • Uses .env.shared (pre-configured with Judge0 API)
  • No setup required - everything works out of the box

For Local Development:

NODE_ENV=development
PORT=3000

# Database (supports auto-detection)
DB_HOST=localhost
DB_PORT=3306,4306
DB_USER=root
DB_PASSWORD=your-password
DB_NAME=brain_jam

# JWT Security
JWT_SECRET=your-secret-key
JWT_EXPIRE=24h

# Judge0 API (Optional for local dev)
JUDGE0_API_URL=https://judge0-ce.p.rapidapi.com
JUDGE0_API_KEY=your-rapidapi-key

🐳 Docker Configuration

Files Structure

BrainJam/
β”œβ”€β”€ Dockerfile               # Production container
β”œβ”€β”€ docker-compose.yml       # Complete setup (app + database)
β”œβ”€β”€ .dockerignore           # Docker build exclusions
β”œβ”€β”€ .env.shared             # Shared environment (with Judge0 API)
β”œβ”€β”€ .env.example            # Template for local development
└── quick-setup.sh/bat      # One-command setup scripts

Docker Services

  • App Container: Node.js application with health checks
  • MySQL Container: Database with persistent storage and auto-initialization
  • Networking: Internal Docker network for secure communication
  • Volumes: Persistent data storage for database and uploads

Docker Management

# Start services
docker-compose up -d

# View logs
docker-compose logs -f app

# Stop services
docker-compose down

# Rebuild after changes
docker-compose up -d --build

# Access container shell
docker-compose exec app sh

# Database access
docker-compose exec mysql mysql -u brainjam_user -p brain_jam

🎯 Platform Features

Core Functionality

  • πŸ” User System: Registration, login, profile management
  • πŸ’» Code Execution: Multi-language support via Judge0 API
  • πŸ“Š Problem Database: Algorithmic challenges with test cases
  • 🏁 Contest System: Create and manage coding competitions
  • πŸ“š Learning Hub: Tutorials and educational resources
  • πŸ‘¨β€πŸ’Ό Admin Panel: Complete platform management

Military Ranking System

Rank Rating Badge Requirements
πŸŽ–οΈ Private Recruit 800-999 Starter Complete registration
⭐ Cadet Coder 1000-1199 Learner Solve 10+ problems
🎯 Code Corporal 1200-1399 Solver Win 3+ contests
πŸ›‘οΈ Tech Lieutenant 1400-1599 Expert 50+ problems solved
πŸ‘‘ Algorithm Captain 1600-1899 Master Top 10% in contests
πŸ† Legendary General 1900+ Legend Elite performance

πŸ”Œ Complete API Reference

Authentication Endpoints

POST /api/auth/register      # User registration
POST /api/auth/login         # User authentication  
GET  /api/auth/profile       # Get user profile (JWT required)

Problem & Contest Endpoints

GET  /api/problems           # List all problems
POST /api/problems/submit    # Submit solution
GET  /api/contests          # List contests
POST /api/contests/create   # Create contest (admin)

Admin Endpoints

GET  /api/admin/users       # Manage users
POST /api/admin/problems    # Create problems
GET  /api/admin/stats       # Platform statistics

System Endpoints

GET  /health                # Health check
GET  /api/test-db          # Database connection test

πŸ”’ Security & Best Practices

Authentication Security

  • βœ… bcrypt Hashing: 12 salt rounds for password security
  • βœ… JWT Tokens: Secure session management
  • βœ… Input Validation: Server-side validation with express-validator
  • βœ… SQL Injection Prevention: Parameterized queries only
  • βœ… XSS Protection: Input sanitization and escaping

Docker Security

  • βœ… Non-root User: Application runs as non-privileged user
  • βœ… Environment Isolation: Separate networks and containers
  • βœ… Secret Management: Environment variables for sensitive data
  • βœ… Health Monitoring: Automatic health checks and restart policies

πŸ§ͺ Testing & Validation

Manual Testing Checklist

  • Registration: Create new account with validation
  • Login: Authenticate with JWT token generation
  • Problem Solving: Submit code and get execution results
  • Contest Participation: Join and compete in contests
  • Admin Functions: Manage users, problems, and contests
  • Docker Deployment: One-command setup works

API Testing

# Health check
curl http://localhost:3000/health

# Database test
curl http://localhost:3000/api/test-db

# Registration test
curl -X POST http://localhost:3000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"username":"testuser","email":"test@example.com","password":"password123","confirmPassword":"password123"}'

# Login test  
curl -X POST http://localhost:3000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"identifier":"testuser","password":"password123"}'

πŸ› οΈ Database Management

Available Scripts

npm start              # Start production server
npm run dev           # Development server with auto-reload
npm run init-db       # Initialize/reset database
npm run init-learning # Load learning resources
npm run update-db     # Run database updates

Database Operations

# Reset database (Docker)
docker-compose exec app npm run init-db

# Update database schema (Docker)  
docker-compose exec app npm run update-db

# Access MySQL directly (Docker)
docker-compose exec mysql mysql -u brainjam_user -p brain_jam

# Backup database (Docker)
docker-compose exec mysql mysqldump -u brainjam_user -p brain_jam > backup.sql

# Restore database (Docker)
docker-compose exec -T mysql mysql -u brainjam_user -p brain_jam < backup.sql

πŸš€ Deployment Options

1. Docker (Recommended)

# One-command deployment
quick-setup.sh  # Linux/macOS
quick-setup.bat # Windows

2. Cloud Platforms

  • Railway: Connect GitHub repo for auto-deployment
  • Heroku: Use Docker container deployment
  • DigitalOcean Apps: Docker-based deployment
  • AWS/GCP/Azure: Container instances or app services

3. VPS/Dedicated Server

# Clone repository
git clone https://github.com/neyamulhasan/BrainJam.git
cd BrainJam

# Setup with Docker
docker-compose up -d

# Or manual setup
npm install
npm run init-db
npm start

🀝 Contributing & Sharing

For Contributors

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/new-feature
  3. Make changes and test thoroughly
  4. Commit: git commit -m "Add new feature"
  5. Push: git push origin feature/new-feature
  6. Create Pull Request

For Users

  1. Easy Setup: Use quick-setup.sh/bat for instant deployment
  2. Shared Resources: Uses project owner's Judge0 API (no setup needed)
  3. Complete Platform: Get full competitive programming environment
  4. Zero Configuration: Everything works out of the box

πŸ“ž Support & Documentation

Quick Help

  • Issue Tracking: GitHub Issues
  • Docker Problems: Check docker-compose logs -f
  • Database Issues: Run docker-compose exec app npm run init-db
  • Port Conflicts: Application auto-detects available ports

Common Solutions

# Port already in use
netstat -tlnp | grep :3000  # Find process using port
sudo kill -9 <PID>          # Kill the process

# Database connection failed
docker-compose restart mysql # Restart MySQL container

# Permission errors (Linux)
sudo chown -R $USER:$USER .  # Fix file permissions
chmod +x quick-setup.sh      # Make script executable

πŸ“„ License

This project is open source and available under the MIT License.


πŸŽ‰ Get Started Now!

# Quick start (anyone can run this!)
git clone https://github.com/neyamulhasan/BrainJam.git
cd BrainJam
quick-setup.bat  # Windows
# or
./quick-setup.sh # Linux/macOS

# Access your platform at: http://localhost:3000

Ready to compete? Start coding and climb the military ranks! πŸš€

  • Should return {"success":true,"message":"Database connected successfully"}

πŸ” Troubleshooting

Common Issues

Port 3000 in use:

netstat -ano | findstr :3000
taskkill /F /PID <PID>

Database connection failed:

  • Ensure MySQL/XAMPP is running
  • Check credentials in .env
  • Run npm run init-db

Registration/Login errors:

  • Check browser console for JavaScript errors
  • Verify database tables exist
  • Check server logs for detailed errors

XAMPP Users

  • βœ… MySQL runs on port 4306 (auto-detected)
  • βœ… Usually no password required
  • βœ… Compatible with MariaDB

🚧 Future Features

  • Contest system with real-time competitions
  • Code editor with syntax highlighting
  • Judge0 integration for code execution
  • Real-time leaderboards with Socket.io
  • Friend system and challenges
  • Problem difficulty progression
  • Badge and achievement system

πŸ“„ License

This project is licensed under the MIT License.

πŸŽ–οΈ Credits

BrainJam Arena - Where Code Warriors Are Born! βš”οΈ


Built for Software Engineering Laboratory - 9th Trimester

About

BrainJam Arena is a Judge0-powered competitive programming platform with Dockerized services, contest hosting, problem management, and a military-style ranking system for tracking progress.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors