Skip to content

Files domain: bring it into the target shape #1483

Description

@peteski22

Problem

The files code is in the old shape, measured on main at f82dbc33:

  • api/routes/files.py builds its own queries (the listing and its cursor), commits, and raises HTTPException itself. It is on ROUTE_DATABASE_IMPORT_BASELINE and TRANSACTION_CONTROL_BASELINE.
  • services/file_service.py has fetch_file(db, ...), a module-level function that takes the session. It is on SERVICE_DATABASE_IMPORT_BASELINE and FLAT_MODULE_BASELINE. services/file_store.py is on FLAT_MODULE_BASELINE.
  • services/files/__init__.py exports eight names (five functions, a class and two data types), not one service.
  • repositories/files/ holds module-level functions, not classes over BaseRepository. BaseRepository can serve a declarative table since refactor(repositories): let a repository serve a declarative model #1451.
  • The routes return dict[str, Any], built by FileObject.to_dict() and FileObject.to_anthropic_dict() on the ORM model.

Proposal

The six steps in docs/domains.md ("What one domain change does"), as separate commits, or separate PRs:

  1. Schemas: the request and response models go into schemas/files.py, and the routes return them. Remove to_dict() and to_anthropic_dict() from FileObject.
  2. Repositories: every files query goes into repositories/files/, as classes over BaseRepository, with the bundle the service receives in files_repositories.py.
  3. Service: one files service in services/files/, built in api/deps.py. The other modules become its private modules, and the package root exports the service and its types.
  4. Commits: into Unit of Work blocks.
  5. Errors: into exceptions/files_exceptions.py, on the bases in exceptions/_base.py.
  6. Baselines: remove the moved modules from every baseline.

FileObject moves to models/files.py and joins the import list in models/__init__.py.

Record the domain's counts before and after, as docs/domains.md asks.

Doing #1473, #1475 and #1478 first avoids moving code that is about to change. #1484 lands before or with step 3.

Acceptance

  • api/routes/files.py, services/file_service.py and services/file_store.py are on no baseline.
  • make lint, make typecheck and the files tests pass.
  • make openapi-check, make postman-check and the dashboard client drift check pass.

Depends on #1482.

Part of #1470.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/backendBackend service implementationarea/refactorCodebase structure improvementstype/tech-debtMaintenance and cleanup

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions