Skip to content

refactor: organise code by domain with a service layer - #3

Merged
Artmann merged 1 commit into
mainfrom
refactor/domain-services
Oct 18, 2026
Merged

Artmann merged 1 commit into
mainfrom
refactor/domain-services

Conversation

@Artmann

@Artmann Artmann commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

The API handlers were doing everything: parsing requests, validating, running the use case (locks, idempotency markers, embedding, write order) and building responses. This PR separates HTTP handling from business logic and organises the code by domain instead of by layer.

src/datapoints/   model · ingest · delete · list · http   (DatapointService)
src/recall/       select (pure algorithm) · http          (RecallService)
src/webhooks/     model · service · rate · http           (WebhookService)
src/app.rs        Infra (store, index, embedder, ready) + Services wiring
src/error.rs      ServiceError, with no HTTP in it
src/http/         shared router, JSON extractor, error envelope
src/locks.rs      per-key locks shared by datapoints and webhooks
  • Handlers (*/http.rs) only parse the request, call the service and shape the response. Each domain registers its own routes(), and http::router merges them.
  • Services take plain commands (DeleteCommand, RecallQuery, ListQuery, …) and return domain results, e.g. Ingested with an outcome of Created, Deduplicated or Replaced. The handler turns that into a status code and response flags.
  • Errors: ApiError wraps ServiceError, plus the errors that only exist over HTTP (malformed request, body too large). Error codes, statuses and the envelope are unchanged.
  • Webhook events go through authenticate and then receive, so a wrong id or token still returns 404 before the body is checked.
  • CONTRIBUTING.md code layout updated.

No change to the HTTP contract or storage layout. The tests only needed import and path changes.

Split HTTP handling from business logic. Each domain (datapoints, recall,
webhooks) now holds its model, a service with the use cases, and an http
module that only parses requests, calls the service and shapes responses.
Services return domain results and a transport-agnostic ServiceError,
which the shared http module maps to the error envelope.

No change to the HTTP contract or storage layout.
@Artmann
Artmann merged commit 785eef1 into main Oct 18, 2026
2 checks passed
@Artmann
Artmann deleted the refactor/domain-services branch October 18, 2026 12:35
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