Repository navigation
Split the SDK into internal layer packages behind a dify.X facade - #1
Merged
Merged
Conversation
Resources held *transport and could reach its fields, retries and raw responses. They now hold a port interface that says which operation to perform and nothing about how it is sent; streams come back as an open body rather than an *http.Response. The constructors move to client.go, the one place that knows a transport stands behind the port. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What Dify answers is now read in one of three places: model_app.go and model_knowledge.go hold the types a call returns and their behaviour, decode_app.go and decode_knowledge.go turn Dify's JSON into them, and the resource files keep only the verbs, their params, and which request each sends. Reads that were inline in a verb (Info, Parameters, Site, the envelope fallbacks for documents, segments and metadata) became decoders of their own, with the same fallbacks in the same order. results.go is now model_app.go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One package leaves the compiler nothing to enforce between layers, so architecture_test.go type-checks the package and fails when a file uses a declaration from an outer layer, when a resource reads fields out of Dify's JSON instead of handing it to a decoder, or when a new file is in no layer. It found two crossings, both fixed here: TransportError's message asked the transport whether a method is idempotent, and WaitUntilSettled borrowed the transport's sleep. Both now live in the kernel (errors.go, clock.go). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TransportError.timeout and APIError.isUpload were set by the transport, the use cases built MessageStream and WorkflowRunStream around the event stream inside them, and the constructors filled App's and Knowledge's unexported port field. Each now goes through a constructor in the layer that owns the field, so the layers can become packages without widening the public API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each layer is now a package under internal/ — kernel, entity, codec, port, usecase, infra — so the compiler holds the dependency direction instead of a test reading file names. The root keeps client.go and a dify.go that re-declares every name callers use as an alias or a forwarding func, with its doc comment, so callers still write dify.X and the public API is the same: every exported name, field and method compares equal under go/types. Names one layer needs from another are exported inside internal/, where no caller can reach them. The tests that drive the SDK through dify.X move to tests/, with their fixtures in tests/testdata; usage_test.go, which tests entity internals, sits in internal/entity. tests/architecture_test.go checks which layer imports which, and that a resource hands Dify's JSON to a codec decoder rather than reading it. Page[T] is re-exported as a generic type alias, which needs Go 1.24, so go.mod and the CI floor move from 1.23 to 1.24. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
r-hashi01
force-pushed
the
refactor/clean-architecture
branch
from
September 28, 2026 07:54
5073161 to
69ea08e
Compare
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.
Callers still import one package and write
dify.X. Inside, the code is split into layers underinternal/, one package each, so the compiler enforces the dependency direction.Commits
*transport.TransportError.timeout,APIError.isUpload, the stream wrappers, andApp/Knowledgeconstruction now go through constructors. That way the split does not widen the public API.go/typescodemod: names are exported only insideinternal/and qualified across packages, and the facade is generated with its doc comments.tests/architecture_test.gochecks which layer imports which, and thatusecasenever reads Dify's JSON itself.Compatibility
go/types, before and after, and compared the two. The only differences are in how types are printed.Page[T]is re-exported as a generic type alias, which Go supports from 1.24.go.mod, CI and the README are updated.dify.Appetc. show as aliases. The type doc is copied to the root; field and method docs live on theinternaldeclaration.Verification
gofmt -l .andgo vet ./...are clean.go test -race ./...passes on Go 1.24.0 and 1.26.4: 120 top-level tests, the same set as before, with the architecture test replaced.kernel.Object. Both were reported.The console client (
Management) builds on this and is in #2.🤖 Generated with Claude Code