Skip to content

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

HackathonPlus - Advanced Coding Platform

A modern competitive programming platform built with Next.js frontend and Ballerina backend, featuring real-time code execution, test case validation, and comprehensive contest management.

πŸš€ Features

Frontend (Next.js)

  • Modern UI: Built with Tailwind CSS and shadcn/ui components
  • Authentication: Login/signup with JWT token storage
  • Role-based Access Control: Admin and user roles with different permissions
  • Code Editor: Monaco Editor with syntax highlighting for Python, Java, and Ballerina
  • Real-time Code Execution: Execute code against test cases with instant feedback
  • Test Case Validation: Automatic comparison of expected vs actual outputs
  • Performance Analysis: Time complexity, space complexity, and execution metrics
  • Global State Management: React Context for auth and data management
  • Responsive Design: Mobile-friendly interface

Backend (Ballerina)

  • RESTful API: Clean API endpoints for authentication and data management
  • JWT Authentication: Secure token-based authentication with 7-day expiration
  • SQLite Database: Lightweight database with migrations and seeding
  • Role-based Access Control: Admin and user role management
  • Password Hashing: Secure password storage using SHA-256
  • Code Execution Engine: Docker-based secure code execution
  • Multi-language Support: Python, Java, and Ballerina execution
  • Performance Monitoring: Execution time, memory usage, and complexity analysis

Code Execution Engine

  • Secure Containerization: Docker-based isolated execution environment
  • Multi-language Support: Python 3, Java 17, Ballerina 2201.12.7
  • Resource Limits: Memory (256MB), CPU (1.0 cores), Process (50)
  • Network Isolation: No external network access for security
  • Real-time Feedback: Instant execution results and error reporting

πŸ—οΈ Project Structure

HACKATHON_PLUS_BALLERINA/
β”œβ”€β”€ backend-ballerina/          # Ballerina backend
β”‚   β”œβ”€β”€ modules/
β”‚   β”‚   β”œβ”€β”€ auth/              # Authentication logic
β”‚   β”‚   β”œβ”€β”€ database/          # Database operations
β”‚   β”‚   β”œβ”€β”€ jwt/               # JWT token management
β”‚   β”‚   β”œβ”€β”€ migrations/        # Database migrations
β”‚   β”‚   β”œβ”€β”€ models/            # Data models
β”‚   β”‚   └── seeders/           # Database seeding
β”‚   └── main.bal               # Main server file
β”œβ”€β”€ frontend-next/             # Next.js frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/               # App router pages
β”‚   β”‚   β”‚   β”œβ”€β”€ (auth)/        # Authentication pages
β”‚   β”‚   β”‚   β”œβ”€β”€ (private)/     # Protected pages
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ challenges/ # Challenge management
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ contests/  # Contest management
β”‚   β”‚   β”‚   β”‚   └── leaderboard/ # Leaderboards
β”‚   β”‚   β”‚   └── admin/         # Admin dashboard
β”‚   β”‚   β”œβ”€β”€ components/        # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ contexts/          # React Context providers
β”‚   β”‚   └── lib/               # Utility functions and API
β”‚   └── package.json
β”œβ”€β”€ code-execution-engine-docker/ # Docker code execution engine
β”‚   β”œβ”€β”€ Dockerfile             # Multi-language container
β”‚   β”œβ”€β”€ run-code.sh            # Execution script
β”‚   └── README.md              # Engine documentation
└── docker-compose.yml         # Docker configuration

πŸ› οΈ Setup Instructions

Prerequisites

  • Node.js 18+ and npm
  • Ballerina 2201.12.7+
  • Docker (required for code execution)
  • Git

1. Clone the Repository

git clone <repository-url>
cd HACKATHON_PLUS_BALLERINA

2. Backend Setup

  1. Navigate to backend directory:

    cd backend-ballerina
  2. Install dependencies:

    bal build
  3. Run database migrations:

    bal run -- migrate
  4. Seed the database:

    bal run -- seed
  5. Start the server:

    bal run

The backend will start on http://localhost:8080

3. Code Execution Engine Setup

  1. Navigate to code execution directory:

    cd code-execution-engine-docker
  2. Build the Docker image:

    docker build -t multi-lang-runner:latest .
  3. Verify the build:

    docker images | grep multi-lang-runner

4. Frontend Setup

  1. Navigate to frontend directory:

    cd frontend-next
  2. Install dependencies:

    npm install --legacy-peer-deps
  3. Start the development server:

    npm run dev

The frontend will start on http://localhost:3000

πŸ§ͺ Testing the Code Execution

Sample Test Cases

Python Example

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def inorderTraversal(root):
    result = []
    def inorder(node):
        if node:
            inorder(node.left)
            result.append(node.val)
            inorder(node.right)
    inorder(root)
    return result

# Test case
root = TreeNode(1, None, TreeNode(2, TreeNode(3)))
result = inorderTraversal(root)
print(result)

Java Example

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
        for (int i = 0; i < 5; i++) {
            System.out.println("Count: " + i);
        }
    }
}

Ballerina Example

import ballerina/io;

public function main() {
    io:println("Hello from Ballerina!");
    foreach int i in 0..<5 {
        io:println(string`Count: ${i}`);
    }
}

πŸ“‘ API Endpoints

Authentication

  • POST /login - User login
  • POST /register - User registration
  • GET /profile - Get user profile (requires JWT)

Code Execution

  • POST /api/submit - Execute code
  • GET /api/health - Code execution service health
  • GET /api/languages - Get supported languages

Health Check

  • GET /health - Server health check

πŸ—„οΈ Database Commands

Backend Commands

# Run migrations
bal run -- migrate

# Rollback last migration
bal run -- migrate:rollback

# Seed database
bal run -- seed

# Fresh database (clear + seed)
bal run -- db:fresh

πŸ‘₯ Demo Credentials

Admin User

  • Username: admin
  • Password: password
  • Email: admin@codearena.com

Regular Users

  • Username: john

  • Password: password

  • Email: john@example.com

  • Username: jane

  • Password: password

  • Email: jane@example.com

βœ… Features Implemented

Authentication & Authorization

  • User authentication (login/register)
  • JWT token management with 7-day expiration
  • Role-based access control (admin/user)
  • Global authentication context
  • Local storage for JWT tokens

Database & Backend

  • Database migrations and seeding
  • SQLite database with proper schema
  • RESTful API endpoints
  • Error handling and validation

Frontend & UI

  • Responsive login/signup pages
  • Modern UI with Tailwind CSS and shadcn/ui
  • API service layer
  • Protected routes and navigation

Code Execution Engine

  • Multi-language Docker container (Python, Java, Ballerina)
  • Secure code execution with resource limits
  • Real-time code execution API
  • Performance monitoring and analysis
  • Test case validation and comparison
  • Code complexity analysis

Contest Management

  • Contest creation and management
  • Challenge management with test cases
  • Real-time code execution in contests
  • Test case validation and scoring
  • Leaderboard functionality

Admin Features

  • Admin dashboard
  • User management
  • Contest and challenge management
  • Analytics and monitoring

πŸ”„ In Progress

  • Real-time collaboration features
  • Advanced analytics and reporting
  • Email notifications
  • Social features and user profiles
  • Advanced contest features (teams, time limits)

πŸ“‹ Planned Features

  • Code plagiarism detection
  • Advanced code analysis tools
  • Integration with external APIs
  • Mobile app development
  • Advanced security features

πŸ›‘οΈ Security Features

Code Execution Security

  • Container Isolation: Each execution runs in isolated Docker containers
  • Resource Limits: Memory (256MB), CPU (1.0 cores), Process (50)
  • Network Isolation: No external network access
  • Time Limits: 30-second execution timeout
  • Read-only Filesystem: Prevents file system attacks
  • Non-root User: Code runs as unprivileged user

Application Security

  • JWT Authentication: Secure token-based authentication
  • Password Hashing: SHA-256 password hashing
  • CORS Protection: Configured CORS policies
  • Input Validation: Comprehensive input validation
  • SQL Injection Protection: Parameterized queries

πŸš€ Performance Features

Code Analysis

  • Time Complexity: Automatic detection of algorithm complexity
  • Space Complexity: Memory usage analysis
  • Pattern Detection: Identifies common coding patterns
  • Performance Metrics: Execution time and resource usage

System Performance

  • Docker Optimization: Efficient container management
  • Database Optimization: Indexed queries and efficient schema
  • Frontend Optimization: Code splitting and lazy loading
  • Caching: Strategic caching for better performance

πŸ› οΈ Technology Stack

Frontend

  • Framework: Next.js 14 with App Router
  • Styling: Tailwind CSS
  • UI Components: shadcn/ui
  • State Management: React Context
  • Icons: Lucide React
  • Code Editor: Monaco Editor
  • TypeScript: Full type safety

Backend

  • Language: Ballerina 2201.12.7
  • Database: SQLite
  • Authentication: JWT
  • Password Hashing: SHA-256
  • API: RESTful HTTP
  • Code Execution: Docker containers

Infrastructure

  • Containerization: Docker
  • Code Execution: Multi-language Docker containers
  • Security: Container isolation and resource limits
  • Monitoring: Performance metrics and analysis

πŸ§ͺ Testing

Manual Testing

  1. Start both backend and frontend servers
  2. Navigate to http://localhost:3000
  3. Login with demo credentials
  4. Create or join a contest
  5. Write and execute code
  6. Verify test case results

Code Execution Testing

# Test Python execution
curl -X POST http://localhost:8080/api/submit \
  -H "Content-Type: application/json" \
  -d '{"code": "print(\"Hello, World!\")", "language": "python"}'

# Test Java execution
curl -X POST http://localhost:8080/api/submit \
  -H "Content-Type: application/json" \
  -d '{"code": "public class Main { public static void main(String[] args) { System.out.println(\"Hello, World!\"); } }", "language": "java"}'

# Test Ballerina execution
curl -X POST http://localhost:8080/api/submit \
  -H "Content-Type: application/json" \
  -d '{"code": "import ballerina/io; public function main() { io:println(\"Hello, World!\"); }", "language": "ballerina"}'

πŸ› Troubleshooting

Common Issues

  1. Docker not running: Ensure Docker is installed and running
  2. Port conflicts: Check if ports 3000 and 8080 are available
  3. Database errors: Run bal run -- db:fresh to reset database
  4. Code execution fails: Verify Docker image is built correctly

Debug Commands

# Check Docker status
docker ps

# Check backend logs
cd backend-ballerina && bal run

# Check frontend logs
cd frontend-next && npm run dev

# Test code execution health
curl http://localhost:8080/api/health

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Use TypeScript for frontend development
  • Follow Ballerina coding conventions
  • Write comprehensive tests
  • Update documentation for new features
  • Ensure security best practices

πŸ“„ License

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

πŸ™ Acknowledgments

πŸ“ž Support

For support and questions:

  • Create an issue in the repository
  • Contact the development team
  • Check the documentation in each component's README

Built with ❀️ for competitive programming enthusiasts

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages