2 min read · 391 wordsapiroutersdependency-injection
Module 4: API & Business Logic
Overview
This is where the models and services from Modules 2–3 become an actual HTTP API. You'll walk every one of the 20 endpoints across routers/agents.py (937 lines — the largest file in the backend) and routers/documents.py, including a real, verified bug found by reading the source rather than running it. Then dependency injection, the current (non-existent) auth story, and how an "AI agent" is really just configuration data.
What You'll Learn
- All 20 endpoints, their request/response schemas, and the pattern every one of them follows
- The 7 module-level helper functions in
routers/agents.pyand what each one does - How FastAPI's
Depends()actually works — and the one dependency this codebase actually uses - Why there's no authentication today, and what adding JWT/OAuth2 would look like
- The tool-gating pattern (
enabled_tools+agent_has_tool()) that stands in for real authorization
Prerequisites
- Module 3: Services Deep Dive — every endpoint in this module calls straight into a service you've already covered
Lessons in This Module
| # | Lesson | What it covers |
|---|---|---|
| 09 | API Routers Overview | All 20 endpoints, the shared pattern |
| 09a | Agents Router Deep Dive | All 15 endpoints + 7 helpers, including a verified bug |
| 09b | Documents Router Deep Dive | All 5 endpoints: upload, search, corrective-RAG ask |
| 10 | Dependency Injection | Depends(), and the one real dependency here |
| 11 | Authentication | Current state (none), how JWT/OAuth2 would fit |
| 12 | Multi-Agent Workflows | The email workflow's sequential orchestration |
| 13 | AI Agents | The Agent model, tool gating, and what "tool calling" means here |
Learning Outcomes
By the end of this module you can:
- List all 20 endpoints and their HTTP methods from memory
- Explain exactly what's wrong with
GET /agents/{id}/statsand why it can't succeed - Explain why
get_dbis the only real FastAPI dependency in this codebase - Explain the difference between OpenAI-native tool calling and this codebase's
enabled_toolspattern