Because the Problems module is incredibly dense, its services are divided into two distinct categories: Standard Logic and AI Generation Engines.
File Location: api/src/services/problems/
The core CRUD manager. It bridges the problem.repository with the API payload. Nothing fancy, just clean, validated data access.
The test case manager.
- Security: When
getTestsis called by a regular user, this service actively filters out any test cases marked astype === "hidden", ensuring users cannot scrape the hidden tests used by theJudgemodule to evaluate their code.
A strict syntax validation service. It uses acorn (a JS parser) to parse function_signature or class_signature JSON payloads and ensure that the provided syntax is valid JavaScript/TypeScript before saving it to the database.
These services utilize LLMs to automate the heavy lifting of content creation.
- Engine: LLM via One API Gateway
- Role: Takes a text prompt (e.g., "Create a Leetcode Medium about Two Pointers") and returns a fully structured JSON problem document.
- Complexity: Highly complex system prompt engineering to enforce exact JSON schemas (title, description, difficulty, tags, function signature, boilerplate code in 7 languages).
- Engine: LLM via One API Gateway
- Role: Automatically generates 15-20 robust edge-case test validations for a given problem signature.
- Execution: Because the AI only generates the inputs, this service actually calls the backend
CompilerServiceto run the AI's inputs against the official solution to mathematically generate theexpected_output!
- Engine: LLM via One API Gateway
- Role: A parsing assistant. If an admin pastes raw text from a website like Codeforces, this service uses the LLM to intelligently extract the inputs and expected outputs and convert them into the strict
[{ input, expected_output }]JSON array required by our database.
- Engine: AWS Bedrock (Anthropic Claude 3.5 Sonnet)
- Role: The ultimate solver. It takes a newly generated problem and uses Claude Sonnet's superior reasoning capabilities to write the perfect
canonical_solution(official solution) for it. It then updates the database directly.