backend

module
v0.39.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 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 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 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)
IDGenerator adapter the host: sneat-go/pkg/modules/datatug/adapters.go
Route mounting the host: datatugext.Extension(...) added to pkg/sneatmain/sneat_main.go's extraModules

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 api4datatug is the DataTug module's HTTP API layer.
Package api4datatug is the DataTug module's HTTP API layer.
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 models4datatug holds this extension's database objects and the DALgo keys they are stored under.
Package models4datatug holds this extension's database objects and the DALgo keys they are stored under.
Package personalcloudlogs4datatug defines personal, direct-read Cloud Logging authorization.
Package personalcloudlogs4datatug defines personal, direct-read Cloud Logging authorization.
Package template4datatug holds a reviewed, immutable DataTug demo template.
Package template4datatug holds a reviewed, immutable DataTug demo template.
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.

Jump to

Keyboard shortcuts

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