mirror of
https://github.com/codeflash-ai/codeflash-internal.git
synced 2026-05-04 18:25:18 +00:00
1.9 KiB
1.9 KiB
Scenario: Add a code-complexity analysis endpoint to both aiservice and cf-api
Context
The team needs a new "code complexity" endpoint that accepts source code and returns complexity metrics (cyclomatic complexity, lines of code, etc.). This endpoint must exist in both:
- aiservice (Django-Ninja) at
/ai/code-complexity-- performs the actual analysis - cf-api (Express) at
/code-complexity-- proxies to aiservice, requires API key auth
The aiservice endpoint should:
- Accept
source_code(required string) andlanguage(optional, default "python") - Return
cyclomatic_complexity(int),lines_of_code(int), andmaintainability_index(float) - Use
AuthenticatedRequestfor auth - Be async
The cf-api endpoint should:
- Be a protected route (behind
checkForValidAPIKey) - Forward the request to aiservice
- Track usage via
trackUsagemiddleware
Task
Write the implementation skeleton for both endpoints. Provide:
- The Django-Ninja schemas (request and response).
- The aiservice router with the endpoint function signature.
- The
aiservice/urls.pyregistration line. - The Express endpoint handler in
js/cf-api/endpoints/. - The route registration in
js/cf-api/routes/index.tswith correct middleware ordering.
Expected Outputs
- Request schema using
ninja.Schemawithsource_code: strandlanguage: str = "python". - Response schema with
cyclomatic_complexity: int,lines_of_code: int,maintainability_index: float. - Async endpoint function using
AuthenticatedRequestand returningtuple[int, ResponseSchema | ErrorSchema]. - URL registration:
path("ai/code-complexity", code_complexity_api.urls)inaiservice/urls.py. - Express handler as an async function in
js/cf-api/endpoints/code-complexity.ts. - Route registered in the protected routes section of
js/cf-api/routes/index.ts(aftercheckForValidAPIKey), withtrackUsagemiddleware applied.