Skip to content

feat(uploads): ADR-002 Phase 1 — ObjectStore driver abstraction#190

Open
lilyshen0722 wants to merge 1 commit intomainfrom
feat/adr-002-phase1-objectstore
Open

feat(uploads): ADR-002 Phase 1 — ObjectStore driver abstraction#190
lilyshen0722 wants to merge 1 commit intomainfrom
feat/adr-002-phase1-objectstore

Conversation

@lilyshen0722
Copy link
Copy Markdown
Contributor

Summary

Phase 1 of ADR-002 Attachments & Object Storage. Introduces a narrow ObjectStore driver interface and routes attachment bytes through it, starting with a single mongo driver that writes to a new MediaObject collection. File stays in place for display metadata and stops carrying inline bytes on new uploads.

  • New ObjectStore interface (put / get / delete + capabilities) at backend/services/objectStore/
  • MongoObjectStore default driver writing to MediaObject collection
  • Route refactored to call the driver; GET falls back to legacy File.data for pre-ADR-002 records
  • File.data made optional (additive schema change)
  • Upload size cap now flows from driver capability through multer's limits.fileSize (no redundant route-layer check)
  • 18 unit tests: driver contract, env-based selection, route GET (driver hit, legacy fallback, 404 paths, 500 on throw), route POST (driver.put + metadata-only File save, 400 no-file, bad MIME)

No data migration, no user-visible change. Legacy records keep serving via the fallback; new uploads write through the driver.

What Phase 1 is NOT

  • Does not close the GET authorization gap. Plain auth middleware on GET /api/uploads/:fileName would break every <img src> in the app (browsers can't attach JWTs to image requests). The fix — signed short-TTL tokens + frontend URL rewriting — lands in Phase 1b as its own PR. Called out loudly in the route header comment and the updated ADR. Do not approve this to production without Phase 1b.
  • Does not ship filesystem / gcs / s3 drivers. One production driver is enough to validate the interface; shipping filesystem here without a Helm caller would be half of Phase 5 wearing a Phase 1 hat (REVIEW.md §Over-engineering).

Reviewed by

Two passes of the code-reviewer agent against docs/REVIEW.md. Final verdict: "Approve, ready to ship as Phase 1." Remaining non-blocking nits captured in commit message.

Test plan

  • cd backend && npx jest __tests__/unit/services/objectStore __tests__/unit/routes/uploads __tests__/unit/models/File.test.js → 18/18 passing
  • Dev smoke: upload a new image via POST /api/uploads; verify MediaObject has bytes, File has metadata only (no data), GET returns the image
  • Dev smoke: fetch an existing pre-ADR-002 image URL → GET falls back to File.data, still renders
  • npm run lint in backend → no new lint errors in changed files

🤖 Generated with Claude Code

…ta split

Introduce a narrow `ObjectStore` interface (put / get / delete +
capabilities) and route attachment bytes through it, starting with a
single `mongo` driver that writes to a new `MediaObject` collection.
`File` stays in place for display metadata and stops carrying inline
bytes for new uploads; `File.data` is now optional so pre-ADR-002
records remain readable via a fallback in the GET handler. No data
migration needed; no user-visible change.

What lands:
- backend/services/objectStore/ObjectStore.ts — interface
- backend/services/objectStore/drivers/mongoDriver.ts — default driver
- backend/services/objectStore/index.ts — singleton, env-based selection
- backend/models/MediaObject.ts — bytes + byte-level mime/size
- backend/models/File.ts — data field optional (additive change)
- backend/routes/uploads.ts — POST writes via driver; GET tries driver
  then falls back to legacy `File.data`; size cap flows through multer
  from `driver.capabilities.maxObjectBytes`
- 18 new unit tests: driver contract, env-based driver selection, route
  GET (driver hit, legacy fallback, 404 paths, 500 on throw), route
  POST (driver.put + metadata-only File save, 400 no-file, bad MIME)

What Phase 1 intentionally does NOT do:
- Close the pre-existing GET authorization gap. Adding plain `auth`
  middleware breaks every `<img src>` in the app since browsers cannot
  attach JWTs to image requests. The fix (signed short-TTL tokens +
  frontend URL-rewrite) lands in Phase 1b as its own PR. The gap is
  documented loudly in the route header comment and called out in the
  ADR as a prerequisite for any production-scale launch.
- Ship `filesystem`, `gcs`, or `s3` drivers. One production driver is
  enough to validate the interface; contract tests will cover the
  others as they arrive. Shipping `filesystem` here without a Helm
  caller would be half of Phase 5 wearing a Phase 1 hat.

Reviewed via the `code-reviewer` agent against docs/REVIEW.md; verdict
"Approve, ready to ship as Phase 1."

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant