Skip to content

refactor(billing): extract domain module - #272

Merged
astaxie merged 1 commit into
astaxie:mainfrom
bailu-ZZ:refactor/169-billing-module
Aug 21, 2026
Merged

refactor(billing): extract domain module#272
astaxie merged 1 commit into
astaxie:mainfrom
bailu-ZZ:refactor/169-billing-module

Conversation

@bailu-ZZ

@bailu-ZZ bailu-ZZ commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Billing synchronization, retry handling, checkpoint recovery, and scheduler lifecycle were implemented inside the server package, which left the billing domain without an enforceable boundary. This PR introduces a standalone billing domain package while preserving the existing server-facing API and persistence behavior through temporary compatibility adapters.

Related Issue

Related to #169

Changes

  • Added the backend/internal/billing domain package with billing types, synchronization orchestration, narrow persistence and upstream adapter ports, and domain error types.
  • Moved retry, range resolution, checkpoint, concurrency, scheduled execution, and scheduler lifecycle behavior into billing.Service.
  • Added server-to-domain bridges for existing GORM persistence, upstream billing adapters, HTTP error mapping, and response representations.
  • Added domain and bridge regression tests for synchronization, retries, error classification, status mapping, rate-limit headers, and scheduler restart behavior.
  • Kept the remaining server HTTP, persistence, and upstream adapter implementations as explicit inputs for a follow-up PR.

Type of Change

  • Bug fix
  • New feature
  • Refactor or maintenance
  • Documentation
  • Deployment or configuration

Verification

  • go test ./... pass
  • go vet ./... pass
  • go test -race ./internal/billing pass
  • go test -race ./internal/server -run '^(TestBillingSchedulerRestartsAfterShutdown|TestBillingConnectorTestAndScheduledSync|TestDomainBilling)' pass
  • node --test tools/*.test.mjs pass
  • node tools/check-doc-translations.mjs pass
  • node tools/check-ui-translations.mjs pass
  • node tools/check-env-contract.mjs pass
  • node tools/check-source-lines.mjs pass
  • git diff --check pass

Compatibility, Security, and Operations

No public API, response format, authentication, authorization, routing, billing rule, database schema, migration result, environment variable, or deployment change is included.

The server compatibility bridge is intentionally temporary. A follow-up PR will move the remaining persistence, admin HTTP, and upstream adapter implementations, then remove the bridge and server billing wrapper. This PR can be rolled back by removing the new billing package and restoring the prior server billing implementation.

Checklist

  • The PR title and body are written in English.
  • Tests were added or updated for behavior changes, or the reason they are unnecessary is documented.
  • No credentials, local .env files, databases, backups, or runtime logs are included.
  • Environment variable changes are synchronized across examples, Compose, start.sh, and deployment documentation where applicable.
  • Shared user-facing behavior is documented consistently in English, Simplified Chinese, and Japanese where applicable.
  • data/model-catalog.yaml remains tracked and catalog changes were reviewed where applicable.
  • git diff --check passes.

@astaxie astaxie left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the complete current diff at exact head d0b2a1f. The new billing package establishes the intended domain service and narrow ports while the temporary server bridge keeps the incremental slice compatible. No blocking standards, behavior, or security findings remain.

The full backend suite, go vet, billing and server race-focused regressions, all repository tests and gates, git diff checks, and all GitHub checks pass. Approving this exact head.

@astaxie
astaxie merged commit bdff5cf into astaxie:main Aug 21, 2026
8 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.

2 participants