05.05

Routers and project structure

skillmaxingPython with AIRouters and project structure
Visual lesson

Routers and project structure

Included with Pro · 4:18
Lessons · 1,029 words

A single main.py is right for the first afternoon and wrong by the end of the week. Relay already has tickets, customers, a chat endpoint, and a health check, each with its own models and dependencies, and they do not belong in one file. FastAPI's unit of organisation is the APIRouter: a mini-application that holds a set of routes and is mounted into the real app with a prefix. The app file becomes a short assembly point, and each feature lives in its own module.

The second half of this lesson is the layout around the routers. A router should be thin: it parses the request, calls a service function, and shapes the response. The rules about tickets live in a service module that knows nothing about HTTP, which is what makes them testable and reusable from the agent later.

Pro

Continue reading

Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.

Unlock full access to
Python with AIAI researchComplete system design
30% off with LAUNCH30ends in 7h 40m
Buy now
View all plans ·Already Pro? Sign in
124 online