Skip to course content
Free FastAPI backend course

FastAPI for AI Backend Development

Module 08 Activity

Scenario

Split the application into layers a second developer can navigate.

What you build

Routers by resource, services with no framework imports, domain exceptions mapped in one place, and the vendor behind one file.

Steps

  1. Split the routes into one router per resource, with the prefix and tag declared once.
  2. Move the logic into services and confirm none imports FastAPI.
  3. Define domain exceptions and map them to status codes in one place in the router layer.
  4. Call one service function directly, with no client and no app, to prove it needs no HTTP.
  5. Confine the model provider to one client module.
  6. Hand the repository to someone who has not seen it and give them three 'where does X go?' questions.

Evidence to hand in

Review checklist