Skip to content

refactor(backend): Clean Architecture layering#7

Merged
GRACENOBLE merged 1 commit into
mainfrom
backend-setup
Jun 14, 2026
Merged

refactor(backend): Clean Architecture layering#7
GRACENOBLE merged 1 commit into
mainfrom
backend-setup

Conversation

@GRACENOBLE

@GRACENOBLE GRACENOBLE commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replaces the flat internal/database + internal/server monolith with explicit Clean Architecture layers: domainusecaserepository/postgres + handlerserver
  • HealthStats promoted from map[string]string to a typed struct with JSON tags
  • Business logic (connection pool threshold messages) moved from the repository into the use case, where policy decisions belong
  • HealthHandler exported for naming consistency with HelloWorldHandler
  • NewServer() now returns (*http.Server, error) instead of panicking on DB failure
  • All backend docs updated to reflect the new layout and patterns

Test plan

  • go vet ./... passes (no output)
  • make test passes unit tests (handler httptest)
  • make itest passes integration tests against Testcontainers Postgres (requires Docker)
  • GET / returns {"message":"Hello World"} with 200
  • GET /health returns typed JSON stats with 200 when DB is up; 503 when DB is down

Replaces the flat database/server monolith with explicit domain,
usecase, repository, and handler layers that strictly enforce the
dependency rule (inner circles never import outer circles).

Key changes:
- internal/domain/        — HealthStats typed struct (was map[string]string)
- internal/usecase/       — HealthReader interface + HealthUseCase with message thresholds
- internal/repository/postgres/ — raw DB adapter; business logic moved out
- internal/handler/       — Handler struct wired on use case interfaces; HealthHandler exported
- internal/server/server.go — composition root only, NewServer() returns error
- Deleted internal/database/ and internal/server/routes.go
- Updated all backend docs and CLAUDE.md to reflect new layout
@coderabbitai

coderabbitai Bot commented Jun 14, 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 9 minutes and 20 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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bd87266d-f518-443c-86f4-9dc7f55e7dc5

📥 Commits

Reviewing files that changed from the base of the PR and between a9c6e2f and 396733e.

📒 Files selected for processing (24)
  • CLAUDE.md
  • backend/.env.example
  • backend/Makefile
  • backend/cmd/api/main.go
  • backend/docs/_index.md
  • backend/docs/database.md
  • backend/docs/error-handling.md
  • backend/docs/routing.md
  • backend/docs/testing.md
  • backend/internal/database/database.go
  • backend/internal/database/database_test.go
  • backend/internal/domain/health.go
  • backend/internal/handler/handler.go
  • backend/internal/handler/health_handler.go
  • backend/internal/handler/hello_handler.go
  • backend/internal/handler/hello_handler_test.go
  • backend/internal/handler/routes.go
  • backend/internal/repository/postgres/db.go
  • backend/internal/repository/postgres/health_repository.go
  • backend/internal/repository/postgres/health_repository_test.go
  • backend/internal/server/routes.go
  • backend/internal/server/server.go
  • backend/internal/usecase/health_usecase.go
  • web/app/page.tsx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch backend-setup

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 and usage tips.

@GRACENOBLE GRACENOBLE merged commit 381ef15 into main Jun 14, 2026
2 checks passed
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