How a0xnirudh/kurukshetra works
Main Components
• Frontend – Divide this into two parts:
◦ The User Interface: Served from the “challenges” directory (challenge listing, challenge execution, results view, and public pages).
◦ The Admin Portal: Located in the “admin” directory, which includes pages for viewing and editing challenges, FAQs, container management, and statistics.
• Backend/API – Several PHP endpoints exist throughout directories such as “api” and “admin/api”. These endpoints handle:
◦ Challenge analytics (e.g., challenges_per_difficulty, challenges_per_language, challenges_per_type).
◦ User state updates and administrative actions (e.g., approve challenges, update user/faq state, kill challenges).
• Authentication Module – Managed via the “login” directory which integrates with Google OAuth. This portion encapsulates:
◦ Google API client libraries
◦ Authentication, token caching, and user session management.
• Database – Housed under the “database” directory, it consists of scripts for connection credentials and DB setup. It stores user data, challenge configuration, logs, and scores.
• Docker/Sandbox Integration – The backend framework utilizes Docker to securely run user-submitted code inside isolated containers. The “installation/optional” directory contains a Dockerfile and installation scripts to build the Kurukshetra sandbox image.
• Static Files – In “staticfiles”, you have assets such as CSS, JS (including Ace editor components), images (logos, screenshots), and fonts. This component supports both frontend UI and interactive coding functionalities.
Relationships and Interactions
• API Communication: Illustrate the connections between the admin API endpoints and backend services for updating challenge states, retrieving statistics, etc.
• Authentication Flow: Outline how the login module (Google OAuth in “login”) manages user authentication and bridges with other components.
• Docker Integration: Clearly map that when a challenge is submitted, the request passes from the backend to a Docker container (sandbox) for secure execution, then the result is relayed back to the user interface.
Architectural Patterns or Design Principles
• API-Based Communication: The use of REST-like endpoints (as seen in the “api” and “admin/api” directories) suggests a modular design where frontends consume backend services.
• Secure Execution: The integration of Docker for sandboxed execution is a key architectural element – mark this clearly as an isolated environment that the backend “orchestrates” for code execution.
• Third-Party Integration: Note the integration with Google OAuth for user authentication and external API calls managed by subcomponents in the “login/src/contrib” directory.
Technologies and Frameworks
• PHP is the primary server-side language.
• MySQL (as indicated by the database scripts) is used for data persistence.
• Docker is leveraged for creating a secure, isolated challenge execution environment.
• Frontend technologies include HTML/CSS/JavaScript and third-party libraries like Ace (from “staticfiles/ace”) for code editing and interactivity.
• Google OAuth libraries in PHP for authentication.
Specific Elements
• Clear labels for each component:
• “Frontend User Interface” (from challenges/)
• “Admin Portal” (from admin/)
• “REST API Endpoints” (backend PHP scripts in api/ and admin/api/)
• “Database” (MySQL, accessed via scripts in database/)
• “Authentication Service” (Google OAuth integration in login/)
• “Docker Sandbox” (execution environment built from installation/optional/)
• User request flow from browser to frontend and then backend.
• API and data exchanges between backend and database.
• Docker container interactions triggered by challenge submissions.