# 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:

1. **aiservice** (Django-Ninja) at `/ai/code-complexity` -- performs the actual analysis
2. **cf-api** (Express) at `/code-complexity` -- proxies to aiservice, requires API key auth

The aiservice endpoint should:
- Accept `source_code` (required string) and `language` (optional, default "python")
- Return `cyclomatic_complexity` (int), `lines_of_code` (int), and `maintainability_index` (float)
- Use `AuthenticatedRequest` for auth
- Be async

The cf-api endpoint should:
- Be a protected route (behind `checkForValidAPIKey`)
- Forward the request to aiservice
- Track usage via `trackUsage` middleware

## Task

Write the implementation skeleton for both endpoints. Provide:

1. The Django-Ninja schemas (request and response).
2. The aiservice router with the endpoint function signature.
3. The `aiservice/urls.py` registration line.
4. The Express endpoint handler in `js/cf-api/endpoints/`.
5. The route registration in `js/cf-api/routes/index.ts` with correct middleware ordering.

## Expected Outputs

- Request schema using `ninja.Schema` with `source_code: str` and `language: str = "python"`.
- Response schema with `cyclomatic_complexity: int`, `lines_of_code: int`, `maintainability_index: float`.
- Async endpoint function using `AuthenticatedRequest` and returning `tuple[int, ResponseSchema | ErrorSchema]`.
- URL registration: `path("ai/code-complexity", code_complexity_api.urls)` in `aiservice/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` (after `checkForValidAPIKey`), with `trackUsage` middleware applied.
