| """ | |
| Auto-discovery of API routers. | |
| Open/Closed Principle: adding a new feature = adding a new file in this package. | |
| No need to modify app.py — routers are discovered automatically. | |
| """ | |
| import importlib | |
| import pkgutil | |
| from fastapi import APIRouter | |
| def discover_routers() -> list[APIRouter]: | |
| """Scan this package for modules exposing a `router` attribute.""" | |
| routers = [] | |
| for _, modname, _ in pkgutil.iter_modules(__path__): | |
| mod = importlib.import_module(f".{modname}", __package__) | |
| if hasattr(mod, "router"): | |
| routers.append(mod.router) | |
| return routers | |