Development Guide
This guide covers how to set up a development environment for NextJudge and contribute to the project.
Prerequisites
Section titled “Prerequisites”- Docker and Docker Compose
- Go 1.21+ (for data-layer development)
- Node.js 18+ and npm/bun (for web development)
- Python 3.10+ (for judge development)
- Git
Development Setup
Section titled “Development Setup”Using Docker Compose (Recommended)
Section titled “Using Docker Compose (Recommended)”The easiest way to develop is using the development Docker Compose setup with hot reload:
./dev-deploy.shThis starts all services with:
- Source code mounted as volumes
- Hot reload enabled
- Development-friendly configurations
Individual Service Development
Section titled “Individual Service Development”You can also run services individually for faster iteration:
Data Layer
Section titled “Data Layer”cd src/data-layergo mod downloadgo run src/main.go -d -p 5000Make sure PostgreSQL and RabbitMQ are running (via Docker Compose).
Web Application
Section titled “Web Application”cd src/webnpm install # or bun installnpm run dev # or bun devThe web app will run on http://localhost:3000.
Judge Service
Section titled “Judge Service”cd src/judgepip install -r requirements.txtpython src/app.pyMake sure RabbitMQ and the data layer are running.
Project Structure
Section titled “Project Structure”NextJudge/├── src/│ ├── cli/ # Command-line interface│ │ ├── bin/ # Executable scripts│ │ └── dev/ # Development utilities│ ├── data-layer/ # Go REST API service│ │ ├── src/ # Go source code│ │ ├── tests/ # API tests (Tavern)│ │ └── docker-compose.*.yml│ ├── judge/ # Python judge service│ │ ├── src/ # Python source code│ │ ├── tests/ # Judge tests│ │ └── languages.toml # Language configurations│ ├── web/ # Next.js web application│ │ ├── src/ # React/Next.js source│ │ │ ├── app/ # Next.js app router pages│ │ │ ├── components/ # React components│ │ │ └── lib/ # Utilities│ │ └── public/ # Static assets│ └── docs/ # Documentation site└── compose/ # Docker Compose filesCode Style
Section titled “Code Style”Go (Data Layer)
Section titled “Go (Data Layer)”- Follow standard Go formatting (
gofmt) - Use
golangci-lintfor linting - Follow Go naming conventions
- Use early returns for error handling
TypeScript/React (Web)
Section titled “TypeScript/React (Web)”- Use TypeScript strict mode
- Follow React best practices
- Use functional components with hooks
- Prefer
constoverfunctionfor components - Use TailwindCSS for styling
- No
anytypes - always specify types
Python (Judge)
Section titled “Python (Judge)”- Follow PEP 8 style guide
- Use type hints where possible
- Use descriptive variable names
- Handle errors explicitly
Database Migrations
Section titled “Database Migrations”The data layer uses GORM’s AutoMigrate feature. When modifying models:
- Update the model struct in
src/data-layer/src/models.go - Run the service - migrations run automatically on startup
- For production, consider using explicit migration scripts
Testing
Section titled “Testing”Data Layer API Tests
Section titled “Data Layer API Tests”API tests use Tavern (Python testing framework):
cd src/data-layerpip install -r tests/requirements.txtpytest tests/ -p no:warningsMake sure the data layer is running before running tests.
Judge Tests
Section titled “Judge Tests”Judge tests verify compilation and execution:
cd src/judgepython -m pytest tests/Or use the test script:
./tests.shWeb Application
Section titled “Web Application”cd src/webnpm test # or bun testAdding New Features
Section titled “Adding New Features”Adding a New API Endpoint
Section titled “Adding a New API Endpoint”- Define the route in the appropriate file (
users.go,problems.go, etc.) - Implement the handler function
- Add authentication middleware if needed
- Update API documentation
- Add tests
Adding a New Language
Section titled “Adding a New Language”- Install compiler/runtime in judge Docker image
- Add entry to
src/judge/languages.toml - Test compilation and execution
- Register language in database (via API or migration)
Adding a New Web Feature
Section titled “Adding a New Web Feature”- Create components in
src/web/src/components/ - Add pages/routes in
src/web/src/app/ - Update navigation if needed
- Add TypeScript types
- Style with TailwindCSS
Debugging
Section titled “Debugging”Data Layer
Section titled “Data Layer”Enable debug logging:
go run src/main.go -dOr set log level in code:
logrus.SetLevel(logrus.DebugLevel)Judge Service
Section titled “Judge Service”The judge logs to stdout. Check Docker logs:
docker logs <judge-container-name>Web Application
Section titled “Web Application”Use browser DevTools and Next.js debugging. Check terminal output for server-side errors.
Database
Section titled “Database”Connect to PostgreSQL:
docker exec -it <postgres-container> psql -U postgres nextjudgeEnvironment Variables
Section titled “Environment Variables”Each service uses environment variables for configuration. See:
src/data-layer/src/config.go- Data layer configsrc/judge/src/app.py- Judge configsrc/web/.env.example- Web app config (if exists)
Git Workflow
Section titled “Git Workflow”- Create a feature branch from
main - Make changes with descriptive commits
- Test your changes
- Submit a pull request
- Address review feedback
Common Tasks
Section titled “Common Tasks”Resetting the Database
Section titled “Resetting the Database”./fully-reset.shThis removes all containers and volumes, giving you a fresh start.
Building Docker Images
Section titled “Building Docker Images”docker build -f src/data-layer/Dockerfile -t nextjudge/data-layer .docker build -f src/judge/Dockerfile -t nextjudge/judge .docker build -f src/web/Dockerfile -t nextjudge/web .Running Migrations Manually
Section titled “Running Migrations Manually”cd src/data-layergo run src/main.go -migrate-onlyGetting Help
Section titled “Getting Help”- Check existing issues on GitHub
- Review the codebase for similar implementations
- Ask questions in discussions
- Read the API documentation
Contributing
Section titled “Contributing”See CONTRIBUTING.md for detailed contribution guidelines.