Refactor auth and setup services

- Updated auth_service.py to improve authentication logic
- Modified setup_service.py for better configuration handling
- Added comprehensive tests for setup_service
- Updated documentation in Tasks.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-04-30 20:10:00 +02:00
parent 7f68d6b7d7
commit 9afdbe2852
4 changed files with 23 additions and 51 deletions

View File

@@ -1,42 +1,3 @@
## [Backend] Module-level imports inside dependency provider functions
**Where found**
- `backend/app/dependencies.py:151``from app.db import open_db` inside `get_db()`
- `backend/app/dependencies.py:258, 270, 282, 294, 307, 319, 332` — local imports inside each `get_<repo>()` provider
- Similar patterns in service provider functions
**Why this is needed**
FastAPI calls dependency provider functions on every request. While Python caches modules, the import statement still has overhead. More importantly, the pattern is inconsistent — some providers have module-level imports while others have local imports, making it unclear which providers are safe to call at high frequency.
**Goal**
Move all repository and service imports to module level in `dependencies.py`.
**What to do**
1. Move all repository imports to module level near the top
2. Similarly move `from app.services import health_service` to module level
3. Keep `from app.db import open_db` as local import (only needed within `get_db()`)
4. Move `from app.services import auth_service` to module level with `TYPE_CHECKING` guard if circular deps prevent it
**Possible traps and issues**
- Moving imports to module level may expose hidden circular imports
- Current local-import pattern was likely chosen to avoid circular deps — verify no circular dependencies before making change
**Docs changes needed**
- Update `Docs/Architekture.md` § 2.3 (Dependency Wiring) — repository and service imports should be at module level
**Doc references**
- `Docs/Architekture.md` § 2.3 (Dependency Wiring)
- `backend/app/dependencies.py` (composition root)
---
## [Backend] `get_password_hash` lives in `setup_service` but is used by `auth_service`
**Where found**