feat(uploads): ADR-002 Phase 1 — ObjectStore driver abstraction#190
Open
lilyshen0722 wants to merge 1 commit intomainfrom
Open
feat(uploads): ADR-002 Phase 1 — ObjectStore driver abstraction#190lilyshen0722 wants to merge 1 commit intomainfrom
lilyshen0722 wants to merge 1 commit intomainfrom
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 1 of ADR-002 Attachments & Object Storage. Introduces a narrow
ObjectStoredriver interface and routes attachment bytes through it, starting with a singlemongodriver that writes to a newMediaObjectcollection.Filestays in place for display metadata and stops carrying inline bytes on new uploads.ObjectStoreinterface (put/get/delete+capabilities) atbackend/services/objectStore/MongoObjectStoredefault driver writing toMediaObjectcollectionFile.datafor pre-ADR-002 recordsFile.datamade optional (additive schema change)limits.fileSize(no redundant route-layer check)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
authmiddleware onGET /api/uploads/:fileNamewould 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.filesystem/gcs/s3drivers. One production driver is enough to validate the interface; shippingfilesystemhere 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-revieweragent againstdocs/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 passingPOST /api/uploads; verifyMediaObjecthas bytes,Filehas metadata only (nodata), GET returns the imageFile.data, still rendersnpm run lintin backend → no new lint errors in changed files🤖 Generated with Claude Code