A robust Node.js backend service for the Interstellar Code competition, providing API communication, mission logic processing, and database persistence.
This backend service handles all communication with the Galactic Command Center (GCC) server, processes mission logic for 5 different challenges, and maintains persistent state using SQLite. It serves as the engine for the Interstellar Code Control Panel frontend.
- API Communication Layer: Handles all HTTP requests to the GCC server with proper authentication headers and retry logic
- Mission Processors: Dedicated modules for each of the 5 missions with specific business logic
- Database Layer: SQLite persistence for request logging and mission results
- WebSocket Server: Real-time communication with frontend for progress updates
- Node.js 18+ with Express.js
- SQLite3 for lightweight persistence
- Axios for HTTP requests
- WebSocket for real-time updates
- CORS enabled for frontend integration
- Node.js 18 or higher
- npm or yarn
- Clone the repository
- Navigate to backend directory:
cd backend- Install dependencies:
npm install- Configure environment variables:
cp .env.example .envEdit .env with your team credentials:
TEAM_ID=your_team_id_here
API_TOKEN=your_api_token_here
PORT=3001
cd backend node server.jsMake a new Terminal
Start the backend server:
npm run devYou should see:
π Interstellar Code Backend API running on http://localhost:3001
β
Database initialized successfully
π WebSocket server listening on port 3001
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/status |
Check backend health |
| GET | /api/missions |
List all missions |
| POST | /api/missions/:id/run |
Execute specific mission |
| GET | /api/logs |
View request logs |
| GET | /api/results |
View mission results |
| GET | /api/connection |
Check GCC connection |
| Method | Endpoint | Purpose |
|---|---|---|
| GET | /missions/:id/challenge |
Retrieve mission data |
| POST | /missions/:id/submit |
Submit mission solution |
id: Primary key, auto-incrementtimestamp: UTC datetime of transactionmethod: HTTP verb (GET/POST)endpoint: Target API endpointrequest_payload: JSON of sent dataresponse_payload: JSON of received datastatus_code: HTTP status code
mission_id: Integer (1-5)key_metric: Critical return value (checksum, digest, hash, recovered string)status: Boolean indicating success
- Objective: Decrypt cipher strings using various algorithms
- Algorithms: Base64, Caesar cipher, Reverse
- Output: Decoded string + checksum (sum of ASCII values)
- Objective: Filter packets based on complex rules
- Rules: Forbidden flags, required flags, bit count limits, parity checks
- Output: Valid PIDs array + XOR digest
- Objective: Maintain SHA256 hash chain integrity
- Process: Sequential hashing of combined strings
- Output: Final hash + record count
- Objective: Reconstruct message from noisy channels
- Method: Statistical frequency analysis
- Output: Recovered string
- Objective: Authenticate using aggregated mission data
- Requirement: All previous missions must be successful
- Process: Dynamic payload construction from database values
# Team Configuration
TEAM_ID=your_team_id
API_TOKEN=your_api_token
# Server Configuration
PORT=3001
NODE_ENV=development
# API Configuration
API_BASE_URL=https://codewars-server.itpg-varna.bg/final/api
API_RETRY_ATTEMPTS=3
API_RETRY_DELAY=1000
# Database Configuration
DB_PATH=./database/interstellar.dbAll requests to the GCC server include:
X-Team-Id: Team identifierX-Token: API access tokenX-Secure: Always "True"
The backend provides:
- REST API endpoints for mission control
- WebSocket server for real-time updates
- CORS enabled for local frontend (http://localhost:5173)
- Structured error responses
Frontend connection status is visible in the "BACKEND SERVER CONTROL" section.
- HTTP 503 Retries: Exponential backoff for service unavailable
- Database Errors: Graceful degradation with fallback logging
- Network Issues: Timeout handling and connection monitoring
- Mission Failures: Detailed error messages with context
- All API requests/responses logged to SQLite
- Mission execution history
- Error tracking and debugging
- Mission progress via WebSocket
- Connection status indicators
- Success/failure notifications
- API tokens stored in environment variables
- No sensitive data in codebase
- Input validation for all missions
- SQL injection protection via parameterized queries
- Backend not starting: Check if port 3001 is available
- GCC connection failed: Verify team ID and API token
- Database errors: Ensure write permissions in backend directory
- Mission failures: Check request logs for detailed error information
- Database:
./database/interstellar.db - Console: Real-time execution logs
- Connection pooling for database
- Cached mission results
- Efficient algorithm implementations
- Minimal dependencies