Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ jobs:
go mod tidy
git diff --exit-code -- go.mod go.sum

- name: Verify generated SQL code
- name: Verify generated code
run: |
make generate/sqlc
make generate
git diff --exit-code

- name: Lint Go
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Verify generated and module files
run: |
go mod tidy
make generate/sqlc
make generate
git diff --exit-code

- name: Lint Go
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SQLC ?= $(CURDIR)/../../cache/bin/sqlc-$(SQLC_VERSION)
COMPOSE_FILES = --env-file deploy/.env -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml
GO_PACKAGES = ./api/... ./cmd/... ./internal/... ./pkg/... ./migrations/...

.PHONY: build test integration-test vet lint frontend-build frontend-i18n frontend-lint generate generate/sqlc compose-dev-up compose-dev-down e2e-live check
.PHONY: build test integration-test vet lint frontend-build frontend-i18n frontend-lint generate generate/sqlc generate/wire compose-dev-up compose-dev-down e2e-live check

build:
GOCACHE=$(GOCACHE) GOMODCACHE=$(GOMODCACHE) GOFLAGS=$(GOFLAGS) $(GO) build ./cmd/mooncode
Expand All @@ -20,7 +20,7 @@ test:
GOCACHE=$(GOCACHE) GOMODCACHE=$(GOMODCACHE) GOFLAGS=$(GOFLAGS) $(GO) test $(GO_PACKAGES)

integration-test:
GOCACHE=$(GOCACHE) GOMODCACHE=$(GOMODCACHE) GOFLAGS=$(GOFLAGS) $(GO) test -tags=integration -count=1 ./internal/identity/data ./internal/repository/data ./internal/analysis/data ./internal/channel/data ./internal/retention/data ./internal/platform/audit ./internal/workflow/data ./pkg/gitrepo
GOCACHE=$(GOCACHE) GOMODCACHE=$(GOMODCACHE) GOFLAGS=$(GOFLAGS) $(GO) test -tags=integration -count=1 ./internal/data/identity ./internal/data/repository ./internal/data/analysis ./internal/data/channel ./internal/data/retention ./internal/data/audit ./internal/data/workflow ./pkg/gitrepo

vet:
GOCACHE=$(GOCACHE) GOMODCACHE=$(GOMODCACHE) GOFLAGS=$(GOFLAGS) $(GO) vet $(GO_PACKAGES)
Expand All @@ -37,7 +37,7 @@ frontend-lint:
frontend-i18n:
$(NPM) --prefix frontend run check:i18n

generate: generate/sqlc
generate: generate/sqlc generate/wire

generate/sqlc:
@if [ -x "$(SQLC)" ]; then \
Expand All @@ -46,6 +46,9 @@ generate/sqlc:
GOCACHE=$(GOCACHE) GOMODCACHE=$(GOMODCACHE) GOPATH=$(GO_TOOL_PATH) $(GO) run github.com/sqlc-dev/sqlc/cmd/sqlc@$(SQLC_VERSION) generate; \
fi

generate/wire:
GOCACHE=$(GOCACHE) GOMODCACHE=$(GOMODCACHE) GOPATH=$(GO_TOOL_PATH) GOFLAGS=$(GOFLAGS) $(GO) tool wire ./internal/app

compose-dev-up:
$(DOCKER) compose $(COMPOSE_FILES) up -d --build --wait

Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ make compose-dev-down
```bash
npm ci --prefix frontend

make generate/sqlc
make generate
make test
make vet
make frontend-i18n frontend-lint frontend-build
Expand Down Expand Up @@ -142,12 +142,14 @@ go run ./cmd/mooncode version

```text
cmd/mooncode/ Cobra 命令入口
internal/<domain>/biz/ 业务模型与用例
internal/<domain>/data/ PostgreSQL/sqlc 实现
internal/<domain>/workflow/ Hatchet Task Runner
internal/channel/runtime/ 长连接生命周期、策略与入站编排
internal/platform/ HTTP、认证、数据库、Hatchet、加密装配
pkg/ 可被第三方独立使用的接口与默认实现
internal/app/ 进程生命周期与 Wire 顶层装配
internal/conf/ 配置加载与校验
internal/server/ HTTP 协议适配与认证中间件
internal/service/ 面向传输层的应用服务门面
internal/biz/ 业务模型、用例与工作流规则
internal/data/ PostgreSQL/sqlc 与外部数据适配
internal/worker/ Hatchet、调度器与长连接运行时
pkg/ 可被第三方独立使用的接口、Options 与默认实现
migrations/ 唯一初始 PostgreSQL migration
sql/queries/ sqlc 查询定义
frontend/ React 前端
Expand Down
16 changes: 9 additions & 7 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Source worktrees belong under the workspace root's `worktree/` directory. Cross-
```bash
npm ci --prefix frontend

make generate/sqlc
make generate
make test
make vet
make frontend-i18n frontend-lint frontend-build
Expand Down Expand Up @@ -142,12 +142,14 @@ go run ./cmd/mooncode version

```text
cmd/mooncode/ Cobra entry point
internal/<domain>/biz/ Business models and use cases
internal/<domain>/data/ PostgreSQL/sqlc implementations
internal/<domain>/workflow/ Hatchet task runners
internal/channel/runtime/ Connection lifecycle, policy, and inbound orchestration
internal/platform/ HTTP, auth, database, Hatchet, and encryption assembly
pkg/ Independently reusable interfaces and defaults
internal/app/ Process lifecycle and top-level Wire assembly
internal/conf/ Configuration loading and validation
internal/server/ HTTP protocol adapters and auth middleware
internal/service/ Transport-facing application service facades
internal/biz/ Business models, use cases, and workflow rules
internal/data/ PostgreSQL/sqlc and external data adapters
internal/worker/ Hatchet, dispatchers, and connection runtimes
pkg/ Independently reusable interfaces, options, and defaults
migrations/ The single initial PostgreSQL migration
sql/queries/ sqlc query definitions
frontend/ React frontend
Expand Down
20 changes: 20 additions & 0 deletions api/openapi/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ func TestDocumentIsValidOpenAPI(t *testing.T) {
}
}

func TestPublishedOperationInventory(t *testing.T) {
document, err := Document()
if err != nil {
t.Fatal(err)
}
specification, err := openapi3.NewLoader().LoadFromData(document)
if err != nil {
t.Fatal(err)
}

paths := specification.Paths.Map()
operations := 0
for _, item := range paths {
operations += len(item.Operations())
}
if len(paths) != 44 || operations != 54 {
t.Fatalf("published operation inventory = %d paths/%d operations, want 44/54", len(paths), operations)
}
}

func TestAnalysisReportUsesClosedCodeScaleResult(t *testing.T) {
document, err := Document()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion deploy/backend.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ COPY migrations ./migrations
COPY pkg ./pkg

RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -buildvcs=false \
-ldflags="-s -w -X github.com/fuchencong/mooncode/internal/platform/buildinfo.Version=${VERSION} -X github.com/fuchencong/mooncode/internal/platform/buildinfo.Commit=${COMMIT} -X github.com/fuchencong/mooncode/internal/platform/buildinfo.BuildTime=${BUILD_TIME}" \
-ldflags="-s -w -X github.com/fuchencong/mooncode/internal/buildinfo.Version=${VERSION} -X github.com/fuchencong/mooncode/internal/buildinfo.Commit=${COMMIT} -X github.com/fuchencong/mooncode/internal/buildinfo.BuildTime=${BUILD_TIME}" \
-o /out/mooncode ./cmd/mooncode

RUN mkdir /tmp/scc \
Expand Down
13 changes: 10 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/getkin/kin-openapi v0.144.0
github.com/gin-gonic/gin v1.10.1
github.com/google/uuid v1.6.0
github.com/google/wire v0.7.0
github.com/hatchet-dev/hatchet v0.98.9
github.com/jackc/pgx/v5 v5.9.2
github.com/larksuite/oapi-sdk-go/v3 v3.9.4
Expand Down Expand Up @@ -44,6 +45,7 @@ require (
github.com/goccy/go-json v0.10.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/cel-go v0.29.0 // indirect
github.com/google/subcommands v1.2.0 // indirect
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect
Expand All @@ -69,6 +71,7 @@ require (
github.com/oasdiff/yaml3 v0.0.14 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/rs/zerolog v1.35.1 // indirect
Expand All @@ -93,15 +96,19 @@ require (
go.opentelemetry.io/proto/otlp v1.10.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.52.0 // indirect
golang.org/x/crypto v0.53.0 // indirect
golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f // indirect
golang.org/x/net v0.55.0 // indirect
golang.org/x/mod v0.37.0 // indirect
golang.org/x/net v0.56.0 // indirect
golang.org/x/sync v0.21.0 // indirect
golang.org/x/sys v0.45.0 // indirect
golang.org/x/sys v0.46.0 // indirect
golang.org/x/text v0.39.0 // indirect
golang.org/x/tools v0.47.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260414002931-afd174a4e478 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260420184626-e10c466a9529 // indirect
google.golang.org/grpc v1.82.1 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

tool github.com/google/wire/cmd/wire
20 changes: 14 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ github.com/google/cel-go v0.29.0/go.mod h1:X0bD6iVNR8pkROSOoHVdgTkzmRcosof7WQqCD
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/wire v0.7.0 h1:JxUKI6+CVBgCO2WToKy/nQk0sS+amI9z9EjVmdaocj4=
github.com/google/wire v0.7.0/go.mod h1:n6YbUQD9cPKTnHXEBN2DXlOp/mVADhVErcMFb0v3J18=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 h1:JeSE6pjso5THxAzdVpqr6/geYxZytqFMBCOtn/ujyeo=
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674/go.mod h1:r4w70xmWCQKmi1ONH4KIaBptdivuRPyosB9RmPlGEwA=
Expand Down Expand Up @@ -247,18 +251,20 @@ golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.52.0 h1:RMs7fP2rXdep0CftQlK8Uf+kibLm7qkCcradZWYz988=
golang.org/x/crypto v0.52.0/go.mod h1:1QgfPxDqh0T2M/elOJtp9RvuR95kVjir0e6/BvEmGbc=
golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto=
golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio=
golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f h1:W3F4c+6OLc6H2lb//N1q4WpJkhzJCK5J6kUi1NTVXfM=
golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f/go.mod h1:J1xhfL/vlindoeF/aINzNzt2Bket5bjo9sdOYzOsU80=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.37.0 h1:vF1DjpVEshcIqoEaauuHebaLk1O1forxjxBaVn884JQ=
golang.org/x/mod v0.37.0/go.mod h1:m8S8VeM9r4dzDwjrKO0a1sZP3YjeMamRRlD+fmR2Q/0=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o=
golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -268,8 +274,8 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.39.0 h1:UbZz4pLOvn600D6Oh6GGEI6VAmndrEBLv8/6BEXzyus=
Expand All @@ -278,6 +284,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.47.0 h1:7Kn5x/d1svx/PzryTsqeoZN4TZwqeH5pGWjefhLi/1Q=
golang.org/x/tools v0.47.0/go.mod h1:dFHnyTvFWY212G+h7ZY4Vsp/K3U4/7W9TyVaAul8uCA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
20 changes: 20 additions & 0 deletions internal/app/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package app

import (
"context"

"github.com/fuchencong/mooncode/internal/data"
)

// Migrator applies MoonCode's embedded database migrations.
type Migrator struct {
data *data.Data
}

func NewMigrator(data *data.Data) *Migrator {
return &Migrator{data: data}
}

func (m *Migrator) Run(ctx context.Context) error {
return m.data.Migrate(ctx)
}
Loading
Loading