A high-performance, self-hostable API service for AlgoHive puzzle distribution
BeeAPI Go is a robust Go implementation of the BeeAPI service, designed with a microservice architecture for high availability and horizontal scaling. It provides a comprehensive API for loading, managing, and serving puzzles from .alghive
files to the AlgoHive platform. The service is built with performance and reliability in mind, allowing for independent deployment across multiple environments.
- Dynamic Puzzle Management: Automatically extracts, loads, and unloads puzzles from
.alghive
files - Stateless Architecture: Designed for easy replication across multiple instances
- High Availability Design: Can be deployed in redundant configurations for zero downtime
- Secure API Authentication: API key-based authentication for protected endpoints
- Comprehensive API: Full suite of endpoints for puzzle discovery and interaction
- Swagger Documentation: Interactive API documentation for easy integration
- Container-Ready: Optimized for Docker and container orchestration platforms
- Efficient Resource Usage: Intelligent memory management for puzzle loading/unloading
BeeAPI Go implements a clean architecture pattern with clear separation between:
- Service Layer: Handles core business logic including puzzle extraction and loading
- Controller Layer: Manages API endpoints and request/response handling
- Model Layer: Defines data structures for puzzles and themes
- Middleware Layer: Provides authentication and request processing
The service is designed to be stateless, making it ideal for horizontal scaling in high availability environments. Multiple BeeAPI instances can be deployed behind a load balancer to distribute traffic and provide redundancy.
BeeAPI employs a sophisticated puzzle management system:
- Initial Loading: When the server starts, it scans the
puzzles
directory structure - Extraction Process:
.alghive
files are automatically extracted into their component files - Memory Management: Puzzles are loaded into memory with optimized resource usage
- Graceful Unloading: On shutdown, puzzle resources are properly released
- Dynamic Reloading: Themes and puzzles can be reloaded without service interruption
This design allows for efficient management of puzzle resources while maintaining high performance.
AlgoHive is a web-based, self-hostable platform that enables developers to create and solve coding puzzles. Each puzzle contains two parts to solve, challenging developers to apply different skills and approaches. The puzzles are distributed using the proprietary .alghive
file format, which BeeAPI is designed to process.
# Clone the repository
git clone https://github.com/AlgoHive-Coding-Puzzles/BeeAPI.git
cd BeeAPI
# Build the application
go build -o beeapi
# Run the application
./beeapi
# Build the Docker image
docker build -t beeapi-go .
# Run as a container
docker run -d -p 8080:8080 --name beeapi-go \
-v $(pwd)/puzzles:/app/puzzles \
-v $(pwd)/data:/app/data \
beeapi-go
For production environments, BeeAPI can be deployed in a high availability configuration:
- Deploy multiple instances behind a load balancer
- Use a shared storage volume for puzzle files (NFS, S3, etc.)
- Implement health checks for automatic instance recovery
- Configure instance auto-scaling based on load
beeapi/
├── puzzles/ # Root directory for puzzle content
│ ├── theme1/ # Theme directory
│ │ ├── puzzle1.alghive # Compressed puzzle file
│ │ ├── puzzle1/ # Extracted puzzle directory (created at runtime)
│ │ ├── puzzle2.alghive
│ │ ├── puzzle2/
│ ├── theme2/
│ │ ├── puzzle3.alghive
│ │ ├── puzzle3/
BeeAPI Go implements a secure API key authentication system for protected endpoints:
- An API key is automatically generated on first startup
- The key is stored in a
.api-key
file in the root directory - Protected endpoints (POST, PUT, DELETE) require this key in the Authorization header
- The key can be retrieved via the authenticated
/apikey
endpoint
# Example authenticated request
curl -X POST "http://localhost:5000/theme" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d "name=new-theme"
The API documentation is accessible through Swagger UI at /swagger/index.html
when the server is running. This provides:
- Interactive API testing interface
- Complete endpoint documentation
- Request/response schema details
- Authentication requirements
BeeAPI can be configured using environment variables:
SERVER_NAME
: The name of the server (default: "Local")SERVER_DESCRIPTION
: A description of the server (default: "Local Dev Server")PORT
: The port to run the server on (default: 5000)PYTHON_PATH
: Path to Python interpreter for puzzle execution (default: "python")
This project is licensed under the MIT License - see the LICENSE file for details.