Skip to content
This repository was archived by the owner on Jan 28, 2026. It is now read-only.

Repository files navigation

πŸš€ Prometeus-8

A robust Node.js backend service for the Interstellar Code competition, providing API communication, mission logic processing, and database persistence.

πŸ“‹ Overview

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.

πŸ—οΈ Architecture

Core Components

  • 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

Technology Stack

  • Node.js 18+ with Express.js
  • SQLite3 for lightweight persistence
  • Axios for HTTP requests
  • WebSocket for real-time updates
  • CORS enabled for frontend integration

πŸš€ Quick Start

Prerequisites

  • Node.js 18 or higher
  • npm or yarn

Installation

  1. Clone the repository
  2. Navigate to backend directory:
cd backend
  1. Install dependencies:
npm install
  1. Configure environment variables:
cp .env.example .env

Edit .env with your team credentials:

TEAM_ID=your_team_id_here
API_TOKEN=your_api_token_here
PORT=3001

Running the Backend

cd backend 
node server.js

Make a new Terminal

Start the backend server:

npm run dev

You should see:

πŸš€ Interstellar Code Backend API running on http://localhost:3001
βœ… Database initialized successfully
πŸ”Œ WebSocket server listening on port 3001

πŸ”§ API Endpoints

Backend API (Local)

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

GCC API (External)

Method Endpoint Purpose
GET /missions/:id/challenge Retrieve mission data
POST /missions/:id/submit Submit mission solution

πŸ—ƒοΈ Database Schema

RequestLogs Table

  • id: Primary key, auto-increment
  • timestamp: UTC datetime of transaction
  • method: HTTP verb (GET/POST)
  • endpoint: Target API endpoint
  • request_payload: JSON of sent data
  • response_payload: JSON of received data
  • status_code: HTTP status code

MissionResults Table

  • mission_id: Integer (1-5)
  • key_metric: Critical return value (checksum, digest, hash, recovered string)
  • status: Boolean indicating success

🎯 Mission Details

Mission 1: Message Decryption

  • Objective: Decrypt cipher strings using various algorithms
  • Algorithms: Base64, Caesar cipher, Reverse
  • Output: Decoded string + checksum (sum of ASCII values)

Mission 2: Packet Filtering

  • Objective: Filter packets based on complex rules
  • Rules: Forbidden flags, required flags, bit count limits, parity checks
  • Output: Valid PIDs array + XOR digest

Mission 3: Cryptographic Hash Chain

  • Objective: Maintain SHA256 hash chain integrity
  • Process: Sequential hashing of combined strings
  • Output: Final hash + record count

Mission 4: Signal Reconstruction

  • Objective: Reconstruct message from noisy channels
  • Method: Statistical frequency analysis
  • Output: Recovered string

Mission 5: The Evacuation

  • Objective: Authenticate using aggregated mission data
  • Requirement: All previous missions must be successful
  • Process: Dynamic payload construction from database values

βš™οΈ Configuration

Environment Variables

# 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.db

Headers for GCC Requests

All requests to the GCC server include:

  • X-Team-Id: Team identifier
  • X-Token: API access token
  • X-Secure: Always "True"

πŸ”Œ Integration with Frontend

The backend provides:

  1. REST API endpoints for mission control
  2. WebSocket server for real-time updates
  3. CORS enabled for local frontend (http://localhost:5173)
  4. Structured error responses

Frontend connection status is visible in the "BACKEND SERVER CONTROL" section.

🚨 Error Handling

  • 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

πŸ“Š Monitoring

Log Files

  • All API requests/responses logged to SQLite
  • Mission execution history
  • Error tracking and debugging

Real-time Updates

  • Mission progress via WebSocket
  • Connection status indicators
  • Success/failure notifications

πŸ”’ Security

  • API tokens stored in environment variables
  • No sensitive data in codebase
  • Input validation for all missions
  • SQL injection protection via parameterized queries

πŸ› Troubleshooting

Common Issues

  1. Backend not starting: Check if port 3001 is available
  2. GCC connection failed: Verify team ID and API token
  3. Database errors: Ensure write permissions in backend directory
  4. Mission failures: Check request logs for detailed error information

Logs Location

  • Database: ./database/interstellar.db
  • Console: Real-time execution logs

πŸ“ˆ Performance

  • Connection pooling for database
  • Cached mission results
  • Efficient algorithm implementations
  • Minimal dependencies

πŸ”— Related Resources

About

codewars-2025-final-round-star_coders created by GitHub Classroom

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages