backend

module
v0.72.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: MIT

README

DataTug backend

Go domain module for the DataTug extension. Module path: github.com/datatug/backend.

Built to the org standard extension-backend-architecture.md: the module depends on dal-go only — never sneat-go-core, sneat-core-modules, or another extension's backend. Anything it needs from outside the domain crosses a port defined here and is satisfied by an adapter in the host composition root.

github.com/sneat-co/sneat-go-core appears in go.mod for tests only: sneatcoretesting.NewMemoryDB() gives the domain tests a real in-memory dal-go database (it also enforces Firestore's transaction rules), so no Firestore emulator or platform bootstrapping is needed.

What's here

Package What it is
const4datatug Extension id (datatug)
models4datatug DBOs and dalgo key builders: the project record ext/datatug/projects/{projectID} and the user's DataTug index users/{userID}/ext/datatug
facade4datatug Facade (injected dal.DB + ports) and the CreateProject command; ports.go holds the IDGenerator port
api4datatug The HTTP layer: POST /v0/datatug/projects/create_project
datatugext Extension(ids) — the extension config the host composes
contract4datatug The test that pins the fixtures of testdata/contract to their CHECKSUMS; the contract itself is the page under spec/

The specification tree is spec/; the contract of plans and AI metering, which clients read, is spec/features/plans-and-ai-metering/README.md, with its fixtures in testdata/contract/.

Only models4datatug and facade4datatug are bound by the dal-go-only rule; api4datatug and datatugext are the thin HTTP/composition layer that necessarily speaks the platform's HTTP framework.

CreateProject

Facade.CreateProject(ctx, userID, storeID, title) creates a project in the DataTug cloud store, in one transaction:

  1. reads the user's DataTug index first — Firestore requires every read in a transaction to happen before the first write;
  2. inserts ext/datatug/projects/{projectID} — title, private access, the creating user, created.at;
  3. registers the project brief in the user's index: inserting users/{userID}/ext/datatug when the user has none, and otherwise updating only the new project's field path, so two concurrent creates cannot clobber each other's briefs.

Only the cloud store (storeID == "firestore") is served. A project in a GitHub repo is created by the client that holds the user's GitHub credential (datatug-apps, with a user PAT), and a local filesystem project by the datatug CLI agent.

Extension-owned user data lives in the user-ext document (users/{uid}/ext/{extID}), never inline in the core users/{uid} document. The module builds that key itself (models4datatug.NewUserExtKey) rather than importing sneat-core-modules' dal4userus, to keep the dal-go-only rule; a test pins the exact path.

Host wiring

Concern Where it lives
HTTP endpoint api4datatug (here) — POST /v0/datatug/projects/create_project?store=firestore
Extension config datatugext.Extension(ids) (here)
Host datatug/datatug-cloud, its own Cloud Run service. It is the only host of the DataTug API routes
Composition root datatug-cloud/cmd/datatug-cloud/main.go calls internal/composition (composition.go), which passes the config to hostmain.Run
IDGenerator adapter datatug-cloud/internal/datatug/adapters.go (datatug.IDGenerator())
Route mounting datatug-cloud/internal/composition/composition.go appends datatugext.ExtensionWithOptions(datatug.IDGenerator(), routeOptions) to cfg.Extensions; internal/composition/datatug.go (configureDataTug) builds the route options

sneat-co/sneat-go does not serve the DataTug API routes. It still imports this module for two packages only: checkout4datatug (the Pro checkout sweep) and host4datatug (the project-relationship policy).

Shipping a change

  1. Land the change here. Push to main auto-tags the next patch version (see CI & versioning).
  2. Bump github.com/datatug/backend in datatug-cloud's go.mod and land that.
  3. datatug-cloud deploys itself: its deploy.yml runs after CI on main (workflow_run), or by manual dispatch.

Bump sneat-go only for changes to checkout4datatug or host4datatug.

Build & test

go build ./...
go test ./...
go vet ./...

CI & versioning

.github/workflows/backend-ci.yml runs strongo's Standard Go CI (lint · test · build) on pushes and PRs touching Go sources, and auto-tags the next vX.Y.Z on push to main from conventional-commit messages.

.github/workflows/security.yml runs govulncheck for reachable known Go vulnerabilities and gosec for source-level security patterns on main, weekly, manual runs, and same-repository PRs. zizmor audits the GitHub Actions workflows, while Gitleaks scans PR commits or the checked-out branch history. Fork PRs receive only the credential-free workflow and secret scans. Scanner reports are retained as private Actions artifacts for seven days. These checks do not replace CodeQL or prove the absence of vulnerabilities; govulncheck blocks known issues reachable through analyzed code and also reports module-level advisories without call traces, while gosec uses static rules that require human triage. The workflow pins govulncheck v1.9.0, gosec at the exact upstream revision 7b1b5cebe007d62fb58eacb90fc571112939ec30 (Go 1.27.2 export-data support), zizmor v1.31.1, and Gitleaks CLI v8.30.1. Local equivalents are govulncheck ./..., zizmor --offline .github/workflows/, and gitleaks git --redact. Run gosec from the repository root with the same exact-file exception used by CI:

gosec_exception_path="$(python3 -c 'import os, re; print(re.escape(os.path.join(os.getcwd(), "githubstore4datatug", "project_create_repository.go")))')"
gosec --exclude-rules="^${gosec_exception_path}$:G505" ./...

Runs use GitHub Actions runner time and do not send source to a hosted scanner; zizmor runs offline, so it skips audits that need GitHub API access.

Directories

Path Synopsis
Package contract4datatug holds the test that pins the fixtures of the contract of DataTug plans and AI metering (testdata/contract) to their CHECKSUMS file.
Package contract4datatug holds the test that pins the fixtures of the contract of DataTug plans and AI metering (testdata/contract) to their CHECKSUMS file.
Package datatugext exposes the DataTug extension config for the platform host to compose.
Package datatugext exposes the DataTug extension config for the platform host to compose.
Package googlecloudlogs4datatug provides durable host adapters for personal Cloud Logging grants.
Package googlecloudlogs4datatug provides durable host adapters for personal Cloud Logging grants.
Package infrastructureroots runs the operator-owned DataTug root check.
Package infrastructureroots runs the operator-owned DataTug root check.
Package personalcloudlogs4datatug defines personal, direct-read Cloud Logging authorization.
Package personalcloudlogs4datatug defines personal, direct-read Cloud Logging authorization.
Package quicksearch4datatug implements consent-controlled project metadata search.
Package quicksearch4datatug implements consent-controlled project metadata search.
Code generated by generate_cloud_demo_template.py; DO NOT EDIT.
Code generated by generate_cloud_demo_template.py; DO NOT EDIT.
Package testsupport4datatug builds the stored state a host test needs to exercise DataTug's protected-project role guard end to end.
Package testsupport4datatug builds the stored state a host test needs to exercise DataTug's protected-project role guard end to end.
fakeoriginallog
Package fakeoriginallog is a test double for the host-composed original-log adapter behind facade4datatug.OriginalLogOpener.
Package fakeoriginallog is a test double for the host-composed original-log adapter behind facade4datatug.OriginalLogOpener.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL