# API Contract: Dynamic Jinja Routes

## Axum HTTP Endpoints

The server will expose wildcard routes to catch requests that do not match hardcoded static APIs (like the auto-api-layer endpoints).

### Dynamic Route Handler

**Endpoint**: `GET /*path` (and other methods as supported by `system_routes`)
**Content-Type**: `text/html; charset=utf-8`

#### Success Response
- **Status Code**: `200 OK`
- **Body**: The fully rendered HTML generated by evaluating the Jinja template against the context data.

#### Error Responses
- **Status Code**: `404 Not Found`
  - **Reason**: No matching route found in `system_routes` for the requested method and path.
- **Status Code**: `500 Internal Server Error`
  - **Reason**: 
    - The `context_query` contained invalid SQL or execution failed.
    - The Jinja template contained syntax errors.
    - The template referenced in `system_routes` was not found in `system_templates`.

## Internal Database Contract

The handler will interact with the database using the internal library interface:
1. `db.query("SELECT template_name, context_query FROM system_routes WHERE method = ? AND path = ?")`
2. `db.query(context_query)`
3. `db.query("SELECT content FROM system_templates WHERE name = ?")`

The results from step 2 will be serialized to a format compatible with `minijinja` (typically `serde_json::Value`).
