CodeVetter · Repo Unpack · Extension points
encode/starlette
Composition occurs through ordinary Python interfaces and ASGI callables. Route lists, converter registries, middleware factories, authentication backends, and lifespan context managers are explicit insertion points. Rendering and schema classes support specialization without replacing application dispatch. Optional integrations and mounted third-party applications keep concerns such as databases and GraphQL outside the core lifecycle.
- Custom routing components implement BaseRoute.matches, url_path_for, and handle; Router accepts an ordered route sequence and a custom default ASGI handler.
- register_url_convertor inserts Convertor instances into CONVERTOR_TYPES; compile_path consumes their regex and Route.matches uses convert, while reverse URL generation uses the converter contract.
- Middleware stores a factory and positional/keyword arguments; Starlette, Router, Route, and Mount construct wrappers in reversed declaration order, allowing scoped middleware composition.
- AuthenticationBackend.authenticate returns credentials/user or None, AuthenticationMiddleware accepts on_error, and BaseUser defines authenticated/display-name/identity properties for custom identity implementations.
- Exception mappings accept status codes or exception classes; the wrapper resolves class handlers through exception MRO, while Starlette reserves 500 and Exception mappings for outer server-error handling.
- HTTPEndpoint subclasses supply HTTP method functions; WebSocketEndpoint subclasses override on_connect, on_receive, on_disconnect, and encoding, with dispatch invoking those hooks around the receive loop.
- Response.render is a serializer override point; Jinja2Templates accepts a custom Environment and context processors, and BaseSchemaGenerator defines get_schema with reusable endpoint/docstring extraction.
- Lifespan supplies an async context manager that can yield shared resources; Mount accepts arbitrary ASGI applications, supporting external database ownership and third-party GraphQL integrations documented after built-in GraphQL removal.