Skip to content

Repository files navigation

Backend CILicense: MITJavaSpring BootTypeScript

CodeHive

A collaborative platform for programming education. Teachers create assignments with automated test generation; students submit code that is evaluated in sandboxed Docker containers.

Features

  • Secure Authentication — JWT-based login, password recovery, role-based access (Student, Teacher, Admin)
  • Bulk User Registration — CSV upload with real-time WebSocket progress streaming
  • Assignment Management — Teachers upload reference solutions and test case inputs; expected outputs are generated automatically by the worker
  • Sandboxed Code Execution — Submissions run in isolated Docker containers with CPU, memory, and time limits
  • Multi-language Support — Java, Python, C, C++
  • Two Execution Modes — Practice (inline test cases vs reference solution) and Definitive (pre-generated expected outputs)
  • Output Comparison — Exact match and floating-point comparators
  • Asynchronous Pipeline — Execution and test generation fully decoupled via RabbitMQ
  • Object Storage — Source code, test inputs, expected outputs, and execution artifacts stored in MinIO
  • API Documentation — Interactive Swagger/OpenAPI at /swagger-ui.html
  • Rate Limiting — Per-endpoint throttling to prevent abuse
  • CI/CD — Automated testing and coverage via GitHub Actions

Architecture

┌─────────────┐ REST API ┌──────────────────────────────────────────────┐
│ Frontend │ ◄────────────► │ Backend │
│ React/TS │ │ Spring Boot · PostgreSQL · MinIO │
└─────────────┘ │ │
│ ┌──────────┐ ┌───────────────────────┐ │
│ │ Auth │ │ Assignment Service │ │
│ │ Service │ │ (upload + queue job) │ │
│ └──────────┘ └───────────┬───────────┘ │
│ ┌──────────────────────┐ │ │
│ │ Execution Service │ │ │
│ │ (load assignment, │ │ │
│ │ queue job) │ │ │
│ └──────────┬───────────┘ │ │
└─────────────┼──────────────┼────────────────┘
│ RabbitMQ │
┌─────────────▼──────────────▼────────────────┐
│ Worker │
│ Spring Boot · Docker SDK · MinIO │
│ │
│ ┌──────────────────┐ ┌─────────────────┐ │
│ │ TestExecutionSvc │ │ TestGenerationSvc│ │
│ │ (run submission) │ │ (gen outputs) │ │
│ └──────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────┘

Queue Topology

QueueDirectionPurpose
codehive_queuebackend → workerStudent code execution jobs
codehive_result_queueworker → backendExecution results
codehive_test_generation_queuebackend → workerGenerate expected test outputs
codehive_test_generation_result_queueworker → backendOutput generation result

MinIO Object Layout

test-suites/assignments/{assignmentId}/
reference/Main.{ext} ← reference solution
tc-{testCaseId}/tc{testCaseId}.in ← test case input
tc-{testCaseId}/tc{testCaseId}.out ← expected output (worker-generated)
test-execution/execution-{executionId}/
source.{ext} ← submitted code
output/tc-{n}/stdout.txt ← actual output
output/tc-{n}/stderr.txt
submissions/assignments/{assignmentId}/submission-{id}/Main.{ext}

Tech Stack

LayerTechnology
Backend APISpring Boot 3, Java 21, Spring Security, JPA/Hibernate
FrontendReact Router v7, TypeScript, Vite
WorkerSpring Boot 3, Java 21, Docker Java SDK
DatabasePostgreSQL
Message BrokerRabbitMQ
Object StorageMinIO
AuthJWT (stateless), BCrypt
TestingJUnit 5, Mockito, AssertJ
DocsSpringDoc OpenAPI / Swagger

Getting Started

Prerequisites

  • Java 21+
  • Node.js 18+
  • Docker and Docker Compose

1. Start Infrastructure

cd codehive-backend
docker compose up -d

This starts PostgreSQL, RabbitMQ, and MinIO.

2. Backend

cd codehive-backend
./gradlew bootRun

Available at: http://localhost:8080
Swagger UI: http://localhost:8080/swagger-ui.html

3. Worker

cd codehive-worker
./gradlew bootRun

The worker connects to RabbitMQ and MinIO on startup and begins consuming jobs.

4. Frontend

cd codehive-frontend
npm install
npm run dev

Available at: http://localhost:3000

API Reference

Authentication

MethodEndpointAuthDescription
POST/api/auth/loginLogin with email or enrollment number
POST/api/auth/signupADMINCreate a single user account
POST/api/auth/signup/csvADMINBulk register users from CSV
GET/api/auth/meBearerGet current authenticated user

Password Recovery

MethodEndpointAuthDescription
POST/api/recovery-password/forgotRequest a password reset email
POST/api/recovery-password/resetReset password with token

Assignments

MethodEndpointAuthDescription
POST/api/assignmentsTEACHER / ADMINCreate assignment with reference solution and test inputs

The assignment endpoint accepts multipart/form-data with three parts:

  • metadata — JSON with title, description, limits, comparator, languages, sampleFlags
  • referenceSolution — source file
  • testCaseInputs — one or more input files (order determines test case index)

The assignment is created as inactive. The worker runs the reference solution against each input and stores the expected outputs. Once complete the assignment is automatically activated.

Code Execution

MethodEndpointAuthDescription
POST/api/execution/checkSubmit code for execution
GET/api/execution/check/{id}Poll execution status

Execution request body:

{
"code": "...",
"language": "JAVA",
"executionType": "PRACTICE",
"assignmentId": "uuid",
"requesterId": "uuid",
"testCases": ["input1", "input2"]
}

PRACTICE — inline test cases are compared against the reference solution output.
DEFINITIVE — submission is compared against pre-generated expected outputs from MinIO.

Rate Limits

EndpointLimitWindow
POST /api/auth/login5 requests60 s
POST /api/auth/signup3 requests5 min
POST /api/recovery-password/forgot3 requests5 min
POST /api/recovery-password/reset5 requests5 min
POST /api/execution/check10 requests60 s

Execution Verdict Reference

StatusMeaning
PENDINGQueued, not yet processed
ACAccepted — all test cases passed
WAWrong Answer
CECompilation Error
RTERuntime Error
TLETime Limit Exceeded
MLEMemory Limit Exceeded

Overall verdict priority when tests fail: CE > TLE > MLE > RTE > WA.

Supported Languages

LanguageCompile commandRun command
Javajavac Main.javajava Main
Pythonpython main.py
Cgcc -o program main.c -lm./program
C++g++ -o program main.cpp -std=c++17 -lm./program

Testing

# Backend unit and integration testscd codehive-backend
./gradlew test# With coverage report
./gradlew test jacocoTestReport
open build/reports/jacoco/test/html/index.html
# Worker testscd codehive-worker
./gradlew test# Frontend type checkcd codehive-frontend
npm run typecheck

Project Structure

CodeHive/
├── codehive-backend/ ← Spring Boot REST API
│ ├── src/main/java/com/github/codehive/
│ │ ├── config/ ← RabbitMQ, MinIO, Security, WebSocket, Async
│ │ ├── controller/ ← Auth, RecoveryPassword, Assignment, CheckExecution
│ │ ├── messaging/ ← Producers and listeners for both queue pairs
│ │ ├── model/ ← Entities, DTOs, queue DTOs, requests, responses
│ │ ├── repository/ ← JPA repositories (UUID primary keys)
│ │ ├── security/ ← JWT filter, UserDetailsService
│ │ ├── service/ ← Auth, Assignment, Execution, ObjectStorage, Mail
│ │ ├── ratelimit/ ← @RateLimit annotation and aspect
│ │ ├── websocket/ ← CSV progress handler
│ │ └── utils/ ← ObjectKeyBuilder, FileExtensionUtil, JwtUtil
│ └── src/test/ ← Unit and integration tests
│
├── codehive-worker/ ← Sandboxed execution worker
│ └── src/main/java/com/github/codehive/worker/
│ ├── config/ ← Docker client, MinIO, RabbitMQ
│ ├── messaging/ ← Listeners (execution + generation) and producers
│ ├── model/ ← DTOs and enums
│ ├── sandbox/ ← LanguageExecutor interface and implementations
│ └── service/ ← TestExecutionService, TestGenerationService
│
├── codehive-frontend/ ← React Router v7 SPA
│ └── app/
│ ├── components/ ← Reusable UI and ProtectedRoute guard
│ ├── context/ ← Auth and theme providers
│ ├── pages/ ← Admin, login, recovery pages
│ ├── routes/ ← Route entry files
│ ├── services/ ← AuthService, RecoveryPasswordService
│ └── types/ ← TypeScript contracts
│
└── llms/ ← Implementation documentation for AI agents
├── backend/
├── frontend/
└── worker/

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Write tests for your changes
  4. Ensure all tests pass
  5. Open a Pull Request against main

License

MIT — see LICENSE for details.

Authors


About

Web application for teachers and students who wants an environment to develop, run and evaluate the code in the same platform

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages