Litestar Routing
Use this skill for route handlers, Controllers, Routers, domain clustering, and endpoint module layout.
Code Style Rules
- Cluster Controllers by domain, not HTTP method.
- Keep handlers thin: parse request data, call a service, return a DTO or response object.
- Put shared path, dependencies, guards, and tags on the Controller class.
- Use
FromPath[T], FromQuery[T], FromHeader[T], and FromCookie[T] for
unconstrained request parameters.
- Use
Annotated[T, PathParameter(...)], QueryParameter(...),
HeaderParameter(...), or CookieParameter(...) when the parameter needs
constraints, metadata, or a wire name. Do not use implicit parameters or the
deprecated field: T = Parameter(...) form.
- Use typed path parameters and explicit return annotations.
Quick Reference
- Controller and route patterns: routing.md
- Domain folder layout: domains.md
- End-to-end vertical slice: example.md
- Automatic domain-package registration: litestar-autowire
Workflow
- Identify the domain boundary and URL prefix.
- Pick a Controller when routes share path, guards, dependencies, or tags.
- Keep data access in services and validation in DTOs.
- Wire the Controller into the app explicitly or through Litestar Autowire.
Guardrails
- Do not group Controllers by HTTP method.
- Do not put authorization logic in handlers; use Guards.
- Do not hand-roll query parameter pagination; use the data-services skill.
- Do not put app-wide plugin setup in route modules.
Validation Checkpoint
Example
from litestar import Controller, get
from litestar.di import NamedDependency
class UserController(Controller):
path = "/users"
@get("/")
async def list_users(
self,
users_service: NamedDependency[UserService],
) -> list[UserRead]:
return await users_service.list_users()
References Index
- routing.md
- domains.md
- example.md
Official References
Shared Styleguide Baseline
1---2name: litestar-routing3description: Auto-activate for Controller, Router, @get/@post/@put/@patch/@delete, route_handler, path params, app/domain modules, or Autowire layout. Not for frontend routers.4---56# Litestar Routing78Use this skill for route handlers, Controllers, Routers, domain clustering, and endpoint module layout.910## Code Style Rules1112- Cluster Controllers by domain, not HTTP method.13- Keep handlers thin: parse request data, call a service, return a DTO or response object.14- Put shared path, dependencies, guards, and tags on the Controller class.15- Use `FromPath[T]`, `FromQuery[T]`, `FromHeader[T]`, and `FromCookie[T]` for16 unconstrained request parameters.17- Use `Annotated[T, PathParameter(...)]`, `QueryParameter(...)`,18 `HeaderParameter(...)`, or `CookieParameter(...)` when the parameter needs19 constraints, metadata, or a wire name. Do not use implicit parameters or the20 deprecated `field: T = Parameter(...)` form.21- Use typed path parameters and explicit return annotations.2223## Quick Reference2425- Controller and route patterns: [routing.md](references/routing.md)26- Domain folder layout: [domains.md](references/domains.md)27- End-to-end vertical slice: [example.md](references/example.md)28- Automatic domain-package registration: [litestar-autowire](../litestar-autowire/SKILL.md)2930<workflow>3132## Workflow33341. Identify the domain boundary and URL prefix.352. Pick a Controller when routes share path, guards, dependencies, or tags.363. Keep data access in services and validation in DTOs.374. Wire the Controller into the app explicitly or through Litestar Autowire.3839</workflow>4041<guardrails>4243## Guardrails4445- Do not group Controllers by HTTP method.46- Do not put authorization logic in handlers; use Guards.47- Do not hand-roll query parameter pagination; use the data-services skill.48- Do not put app-wide plugin setup in route modules.4950</guardrails>5152<validation>5354## Validation Checkpoint5556- [ ] Routes are domain-clustered.57- [ ] Handlers are async when they perform I/O.58- [ ] Shared guards and dependencies live on the Controller.59- [ ] DTO and service concerns link to their owning skills.6061</validation>6263<example>6465## Example6667```python68from litestar import Controller, get69from litestar.di import NamedDependency707172class UserController(Controller):73 path = "/users"7475 @get("/")76 async def list_users(77 self,78 users_service: NamedDependency[UserService],79 ) -> list[UserRead]:80 return await users_service.list_users()81```8283</example>8485## References Index8687- [routing.md](references/routing.md)88- [domains.md](references/domains.md)89- [example.md](references/example.md)9091## Official References9293- <https://docs.litestar.dev/> - Litestar documentation94- <https://docs.litestar.dev/latest/reference/> - Litestar API reference95- <https://github.com/litestar-org/litestar/tree/v2.24.0> - Audited Litestar 2.24.0 source9697## Shared Styleguide Baseline9899- [General](../litestar-styleguide/references/general.md)100- [Python](../litestar-styleguide/references/python.md)101- [Litestar](../litestar-styleguide/references/litestar.md)