Skip to content

feat(storage): integrate Cloudflare R2 for object storage - #31

Merged
GRACENOBLE merged 1 commit into
mainfrom
22-feat-cloudflare-r2-storage
Jun 23, 2026
Merged

GRACENOBLE merged 1 commit into
mainfrom
22-feat-cloudflare-r2-storage

Conversation

@GRACENOBLE

Copy link
Copy Markdown
Member

Summary

  • Wires the existing R2 infrastructure layer end-to-end across backend, web, and mobile
  • Adds POST /api/v1/storage/presign and DELETE /api/v1/storage/:key — both Firebase-auth-protected and gated on R2_ACCOUNT_ID being set
  • Adds useUpload() hook on web for presign → direct-to-R2 PUT flow
  • Adds R2UploadRepository on Android using OkHttp with injectable client for testing

Changes by layer

Backend

  • usecase/storage.go — StorageService interface at the correct Clean Architecture layer
  • infrastructure/storage/r2/storage.go — updated to return usecase.StorageService; adds NewWithHTTPClient for test injection
  • Bootstrap wiring: App.StorageService, R2 Config fields, optional init block
  • Two new authenticated handlers with swaggo annotations; Swagger docs regenerated
  • .env.example updated with R2_ACCOUNT_ID, R2_ACCESS_KEY, R2_SECRET_KEY, R2_BUCKET, R2_PUBLIC_URL

Web

  • lib/storage.ts — presign() and uploadToR2() utilities
  • lib/useUpload.ts — useUpload() hook with isUploading, publicUrl, error, upload

Mobile

  • storage/UploadRepository.kt — UploadRepository interface + R2UploadRepository impl
  • okhttp-mockwebserver added as testImplementation

Docs

  • New: backend/docs/storage.md, web/docs/storage.md, mobile/docs/storage.md
  • Updated: environment.md, bootstrap.md
  • Fixed stale: error-handling.md, routing.md, websocket.md

Test plan

  • Backend: go test ./internal/transport/handlers/... ./internal/infrastructure/storage/... — handler unit tests + R2 package tests (custom RoundTripper mock)
  • Web: pnpm test — 40 tests pass including 13 new storage/useUpload tests
  • Mobile: .\gradlew.bat test — UploadRepositoryTest passes with MockWebServer
  • Manual: set R2 env vars, call POST /api/v1/storage/presign, upload a file to the returned URL, verify it appears at the public URL
  • Manual: call DELETE /api/v1/storage/:key, verify the object is removed

Closes #22

Wires the existing R2 infrastructure layer end-to-end across all three
app layers. The service is optional — enabled only when R2_ACCOUNT_ID
is set in the environment.

Backend:
- Add StorageService interface to usecase/ (Clean Architecture placement)
- Update r2.New() to return usecase.StorageService; add NewWithHTTPClient
  constructor for test injection via custom RoundTripper
- Bootstrap: add R2 config fields, App.StorageService, and init block
- POST /api/v1/storage/presign — returns presigned PUT URL + public URL
- DELETE /api/v1/storage/:key — deletes an object; both routes require
  Firebase auth and are gated on h.storageService != nil
- Regenerate Swagger docs; add R2 vars to .env.example

Web:
- lib/storage.ts: presign() utility and uploadToR2() direct-to-R2 PUT
- lib/useUpload.ts: useUpload() hook (isUploading, publicUrl, error, upload)

Mobile:
- storage/UploadRepository.kt: UploadRepository interface +
  R2UploadRepository (injectable OkHttpClient, coroutine-safe,
  Result<String> return); add okhttp-mockwebserver test dependency

Docs:
- Create backend/docs/storage.md, web/docs/storage.md, mobile/docs/storage.md
- Update environment.md, bootstrap.md, and three stale docs
  (error-handling.md, routing.md, websocket.md)

Closes #22

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@GRACENOBLE, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 21 minutes and 10 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ab8bdc9a-0121-422d-a1f4-28da8e1406db

📥 Commits

Reviewing files that changed from the base of the PR and between fe3b1af and d922b2c.

📒 Files selected for processing (33)
  • backend/.env.example
  • backend/docs/_index.md
  • backend/docs/bootstrap.md
  • backend/docs/environment.md
  • backend/docs/error-handling.md
  • backend/docs/routing.md
  • backend/docs/storage.md
  • backend/docs/swagger/docs.go
  • backend/docs/swagger/swagger.json
  • backend/docs/swagger/swagger.yaml
  • backend/docs/websocket.md
  • backend/internal/bootstrap/bootstrap.go
  • backend/internal/infrastructure/storage/r2/storage.go
  • backend/internal/infrastructure/storage/r2/storage_test.go
  • backend/internal/server/server.go
  • backend/internal/transport/handlers/handler.go
  • backend/internal/transport/handlers/health_handler_test.go
  • backend/internal/transport/handlers/routes.go
  • backend/internal/transport/handlers/storage_handler.go
  • backend/internal/transport/handlers/storage_handler_test.go
  • backend/internal/usecase/storage.go
  • mobile/app/build.gradle.kts
  • mobile/app/src/main/java/com/company/template/storage/UploadRepository.kt
  • mobile/app/src/test/java/com/company/template/storage/UploadRepositoryTest.kt
  • mobile/docs/_index.md
  • mobile/docs/storage.md
  • mobile/gradle/libs.versions.toml
  • web/docs/_index.md
  • web/docs/storage.md
  • web/lib/storage.test.ts
  • web/lib/storage.ts
  • web/lib/useUpload.test.ts
  • web/lib/useUpload.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 22-feat-cloudflare-r2-storage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added area: backend Go REST API area: web Next.js web app area: mobile Android app (Kotlin + Jetpack Compose) type: chore Cleanup or maintenance tasks labels Jun 22, 2026
@GRACENOBLE
GRACENOBLE merged commit 658e0ec into main Jun 23, 2026
5 checks passed
@GRACENOBLE
GRACENOBLE deleted the 22-feat-cloudflare-r2-storage branch June 23, 2026 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: backend Go REST API area: mobile Android app (Kotlin + Jetpack Compose) area: web Next.js web app type: chore Cleanup or maintenance tasks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: complete Cloudflare R2 storage integration

1 participant