refactor: split codebase into submodules (closes #19) #24

Merged
unkinben merged 3 commits from benvin/issue-19-submodules into master 2026-04-28 22:47:38 +10:00
Owner

Summary

Resolves #19 — refactors the flat module layout into a proper subpackage hierarchy with no functional changes.

New structure

src/artifactapi/
├── main.py               — FastAPI app + thin route declarations only
├── config.py             — ConfigManager
├── metrics.py            — MetricsManager
├── docker_auth.py        — backwards-compat shim → auth/docker.py
├── artifact/             — route handler implementations
│   ├── proxy.py          — GET /api/v1/remote (caching, mutable revalidation)
│   ├── local.py          — PUT/HEAD/DELETE for local repos
│   ├── docker.py         — Docker Registry v2 proxy + ping
│   ├── discovery.py      — artifact discovery + bulk cache
│   └── flush.py          — PUT /cache/flush
├── auth/
│   └── docker.py         — Bearer token fetching + in-memory cache
├── cache/
│   └── redis.py          — RedisCache
├── database/
│   └── postgres.py       — DatabaseManager
├── storage/
│   └── s3.py             — S3Storage
└── remote/
    ├── base.py           — content-type detection
    ├── helm.py           — Helm index.yaml URL rewriting
    ├── npm.py            — npm metadata URL rewriting
    ├── python.py         — PyPI URL construction + HTML rewriting
    ├── rpm.py            — RPM remotes
    └── generic.py        — generic HTTP remotes

Key points

  • Each @app.route() in main.py is now a single delegating call into artifact/
  • All backwards-compat import paths preserved via __init__.py re-exports and the docker_auth.py shim
  • UpstreamUnreachable, cache_single_artifact, _upstream_reachable, check_upstream_changed moved from main.py to artifact/proxy.py; tests updated to patch at their new locations
  • Wheel builds with uv build; Docker stack (make docker-up) starts clean

Test plan

  • make test — all 187 tests pass
  • uv build --wheel succeeds
  • make docker-up starts all services healthy
  • /health, /, /v2/ endpoints respond correctly
## Summary Resolves #19 — refactors the flat module layout into a proper subpackage hierarchy with no functional changes. ### New structure ``` src/artifactapi/ ├── main.py — FastAPI app + thin route declarations only ├── config.py — ConfigManager ├── metrics.py — MetricsManager ├── docker_auth.py — backwards-compat shim → auth/docker.py ├── artifact/ — route handler implementations │ ├── proxy.py — GET /api/v1/remote (caching, mutable revalidation) │ ├── local.py — PUT/HEAD/DELETE for local repos │ ├── docker.py — Docker Registry v2 proxy + ping │ ├── discovery.py — artifact discovery + bulk cache │ └── flush.py — PUT /cache/flush ├── auth/ │ └── docker.py — Bearer token fetching + in-memory cache ├── cache/ │ └── redis.py — RedisCache ├── database/ │ └── postgres.py — DatabaseManager ├── storage/ │ └── s3.py — S3Storage └── remote/ ├── base.py — content-type detection ├── helm.py — Helm index.yaml URL rewriting ├── npm.py — npm metadata URL rewriting ├── python.py — PyPI URL construction + HTML rewriting ├── rpm.py — RPM remotes └── generic.py — generic HTTP remotes ``` ### Key points - Each `@app.route()` in `main.py` is now a single delegating call into `artifact/` - All backwards-compat import paths preserved via `__init__.py` re-exports and the `docker_auth.py` shim - `UpstreamUnreachable`, `cache_single_artifact`, `_upstream_reachable`, `check_upstream_changed` moved from `main.py` to `artifact/proxy.py`; tests updated to patch at their new locations - Wheel builds with `uv build`; Docker stack (`make docker-up`) starts clean ## Test plan - [x] `make test` — all 187 tests pass - [x] `uv build --wheel` succeeds - [x] `make docker-up` starts all services healthy - [x] `/health`, `/`, `/v2/` endpoints respond correctly
unkinben added 3 commits 2026-04-28 22:44:46 +10:00
cache/redis.py, database/postgres.py, and remote/{base,generic,helm,npm,python,rpm}.py
replace the flat modules. All public symbols re-exported from their package
__init__.py for backwards compatibility. No functional changes; all 187 tests pass.

Closes #19
- storage/s3.py: S3Storage moved from storage.py; storage/__init__.py re-exports it
- auth/docker.py: Docker Bearer token logic moved from docker_auth.py
- docker_auth.py: thin shim re-exporting all public symbols (including _token_cache)
  for backwards compatibility with existing test and import paths
- main.py: now imports get_docker_token_for_response from .auth

All 187 tests pass.
refactor: extract route handler logic into artifact/ subpackage
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
e6d9b175ce
Each route in main.py is now a single-line delegation to an artifact submodule:
- artifact/proxy.py  — remote artifact GET, caching, mutable revalidation
- artifact/local.py  — local repo upload/check/delete
- artifact/docker.py — Docker Registry v2 proxy + ping
- artifact/discovery.py — GitHub release discovery + bulk cache
- artifact/flush.py  — cache flush

UpstreamUnreachable, cache_single_artifact, _upstream_reachable and
check_upstream_changed moved from main.py to artifact/proxy.py.
Tests updated to patch at their new locations.

All 187 tests pass.
unkinben merged commit 373366e695 into master 2026-04-28 22:47:38 +10:00
unkinben deleted branch benvin/issue-19-submodules 2026-04-28 22:47:39 +10:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: unkin/artifactapi#24