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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ node_modules/
.DS_Store
.idea/

CLAUDE.md

# Ignore the output binary of the test app but not its source code.
testapp
Expand Down
110 changes: 110 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Celerity Go SDK

Go SDK for building Celerity applications. Handlers are written once and run either in the
containerised Celerity runtime, over its IPC protocol, or in a provider's serverless
environment through an adapter. The Celerity CLI runs its build tool, `celerity-go`, to
generate platform imports and extract the handler manifest.

## Workspace

This repo is one of NewStack's. NewStack's maintainers develop it alongside the others in a
shared workspace, using the NewStack Claude Code plugin for how work is planned, reviewed,
committed and coordinated across repos. The plugin isn't public, and nothing here depends on it:
this file and the repo's own docs cover what a contribution needs.

## Layout

A Go workspace of eleven modules (`scripts/modules.sh` lists them), split by dependency weight
so that an application that never touches AWS doesn't compile `aws-sdk-go-v2` into its binary.

| Module | Holds |
|---|---|
| `.` (core) | Everything below except the AWS, local, tracing and CLI modules |
| `serverless/aws` | Lambda adapter and event mapping |
| `resources/aws` | S3, SQS, SNS, DynamoDB, RDS, and ElastiCache credentials; a package per resource kind |
| `resources/redis` | The cache, for every platform |
| `resources/local` | The provider a `celerity dev` session runs under, linked by `generate --local` |
| `config/aws`, `config/local` | Config providers: Secrets Manager, Parameter Store, the Lambda extension cache; the Valkey a dev session runs |
| `telemetry/otel`, `resources/redis/otel`, `resources/sqldb/otel` | Tracing, linked by `generate --telemetry otel` or where the blueprint declares a cache or database |
| `cmd/celerity-go` | Build tool: `generate` writes platform imports, `extract` writes the handler manifest |

In core: `celerity/` (app, registration, run), `handler/`, `layer/`, `guard/`, `config/`,
`telemetry/`, `resources/` (provider-agnostic interfaces and handles), `serverless/`,
`manifest/` (handler-manifest.v1), `celeritytest/` (the harness applications test with),
`internal/ipc/` (the IPC client) and `internal/ipcproto/celerityv1/` (generated stubs).
`proto/celerity` is a vendored copy of the runtime's contract.

Why the API and modules are shaped as they are: [docs/DESIGN_DECISIONS.md](docs/DESIGN_DECISIONS.md).
Read the relevant decision before changing a resource contract or a module boundary.

## Checks

Commands are in [CONTRIBUTING.md](CONTRIBUTING.md#commands); each runs over every module.

- **Tools:** Go 1.26, `staticcheck` for lint, `buf` for the protocol scripts, docker for the
integration run, and `npm install` for the commit-msg hook.
- **Tests:** `bash scripts/run-tests.sh` runs unit tests with `-race` (needs cgo and a C compiler), and
nothing else.
`--with-integration` also starts `docker-compose.test-deps.yml` (the pinned
`celerity-runtime-core` image, Valkey, LocalStack, Postgres, MySQL), builds `tests/testapp`
for the image, and runs `tests/` and each module's `integration`-tagged suites.
- It binds host ports 8080, 6379, 4566, 5432 and 3306, so it clashes with any other stack
on those ports, including Bluelink's test stacks.
- The runtime version is pinned in `.env.test`.
- The AWS suites use LocalStack unless `CELERITY_TEST_AWS_EMULATOR=false` is exported; then
they use the default credential chain and create resources in that account, and leave
them. Values already exported override `.env.test`'s.
- **Lint:** `bash scripts/lint.sh` (`go vet` and staticcheck), `scripts/check-format.sh`.
- **Protocol:** `scripts/check-proto.sh` checks `proto/celerity` against celerity's `main`
(fetched over the network) and fails on any difference, reporting whether it's breaking; it
also checks the committed stubs match.
`scripts/gen-proto.sh` regenerates them; don't edit `*.pb.go` by hand.
- **Gates:**
- With `git config core.hooksPath .githooks`, pre-commit checks gofmt on staged Go files and
commit-msg runs commitlint.
- CI (`ci.yml`) runs format, proto, vet, lint, build and `run-tests.sh --with-integration`
on pull requests and pushes to `main`, builds each module with `GOWORK=off`, and runs
`sync-module-versions.sh --check`.
`security.yml` runs `govulncheck`; CodeQL runs too.

## Compatibility

- **Public Go API:** pre-1.0 (`v0.x`); a breaking change bumps the minor version. Resource
contracts are kept at parity with the Node and Python SDKs (`docs/DESIGN_DECISIONS.md`
names where they differ); a contract change says what each other SDK needs.
- **The Celerity CLI's interface:** `celerity-go generate` and `extract`, every flag of each
(the CLI passes `--target`, `--local`, `--sql-engine`, `--telemetry`, `--package`,
`--resource`, `--test-packages` and `--out`; see celerity
`apps/cli/internal/handlertoolchain/golang.go`), and the handler-manifest.v1 format. Additive
only; anything else needs a matching change in the Celerity CLI first.
- **IPC protocol:** owned by celerity's `libs/runtime/proto`. Change it there, then re-vendor.
- **Persisted state:** none.

## Conventions

- Commits: conventional, scopes in `commitlint.config.js`. Every module shares one release
whatever the scope. Only `feat`, `fix`, `perf` and `deps` release and appear in the
changelog, so use another type (`ci`, `docs`, `chore`, `refactor`, `test`) for changes that
don't change what a module does.
- Releases: every module at one version, through one release pull request
([docs/RELEASING.md](docs/RELEASING.md)). Don't edit `CHANGELOG.md`, the manifest, sibling
`require` versions or tags by hand; the release workflow sets them.
- A module that requires a sibling keeps a `replace` to the sibling's checkout. It's
permanent; don't remove it.
- Complexity 15 or less, nesting 3 or less, lines under 120 characters.
- Doc comments in godoc form on exported API; on unexported code only for a constraint or
rationale the code can't show. Tests go through the public API, table-driven, with cases
named for the behaviour.
- Dependency updates: Renovate for versions, Dependabot for security only, so there's no
`.github/dependabot.yml` ([docs/RENOVATE.md](docs/RENOVATE.md)).

## Safety

- Don't run the integration suites against a real AWS account unless asked. Before
`--with-integration`, check `CELERITY_TEST_AWS_EMULATOR` isn't exported as `false`.
- Don't create tags or releases, or run `tag-modules.sh`, which pushes every local tag
(`git push origin --tags`), or `warm-proxy.sh`.

## Known mistakes

<!-- One line per mistake an agent has made here, phrased as the rule that prevents it. -->
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@AGENTS.md
63 changes: 26 additions & 37 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,32 @@ Conventional commits, enforced by commitlint through `.githooks/commit-msg`.

```
feat(core): register websocket handlers by route key
fix(ipc): grant credit when a handler panics
docs(repo): describe the two-pass extraction
fix(core): grant credit when a handler panics
docs: describe the two-pass extraction
```

**Types**: `feat`, `fix`, `build`, `revert`, `wip`, `chore`, `ci`, `docs`,
`style`, `refactor`, `perf`, `test`, `instr`, `deps`

**Scopes**: one per release unit, so a scope names the module a commit releases
and nothing finer.
**Scopes**: one per module, so a scope names the module a commit changes and
nothing finer. `commitlint.config.js` holds the list.

| Scope | Module | Import path |
|---|---|---|
| `core` | `.` | `github.com/newstack-cloud/celerity-go-sdk` |
| `serverless-aws` | `serverless/aws` | `.../serverless/aws` |
| `resources-aws` | `resources/aws` | `.../resources/aws` |
| `resources-redis` | `resources/redis` | `.../resources/redis` |
| `resources-local` | `resources/local` | `.../resources/local` |
| `resources-redis-otel` | `resources/redis/otel` | `.../resources/redis/otel` |
| `resources-sqldb-otel` | `resources/sqldb/otel` | `.../resources/sqldb/otel` |
| `telemetry-otel` | `telemetry/otel` | `.../telemetry/otel` |
| `config-aws` | `config/aws` | `.../config/aws` |
| `config-local` | `config/local` | `.../config/local` |
| `cli` | `cmd/celerity-go` | `.../cmd/celerity-go` |
| `deps` | — | dependency updates belonging to no module |

A scope naming a package rather than a module would read as though it decided
which module released, which it does not, and would drift as packages move
A scope naming a package rather than a module would drift as packages move
between modules.

The scope is optional. A repository-wide change that belongs to no module is
Expand All @@ -109,42 +112,28 @@ scope for it.

## Releases

release-please opens a release PR per module. Merging it tags the module; Go
derives a submodule's version from a tag carrying its directory prefix, so
`serverless/aws` releases as `serverless/aws/v0.2.0` and core as `v0.2.0`.

**A commit belongs to a module by the files it touches, not by its scope.**
Editing `serverless/aws/adapter.go` releases `serverless/aws` whatever the
commit says; `feat(serverless-aws): ...` on a commit that only edits core
releases core. The scope drives the changelog and the PR title and nothing else,
so it is worth keeping it honest, but it is not what routes the release.

Two consequences of core being the repository root:

- Core would otherwise pick up every change in the repository, including the
submodules'. `exclude-paths` in `release-please-config.json` keeps their
directories out of it, so a `resources/aws` fix does not also bump core.
- Everything else at the root, the workflows, scripts, README and this file, is
still core's. Use a type that does not release for those, `ci`, `docs`,
`chore`, `refactor`, `style` or `test`, and reserve `feat` and `fix` for
commits that change what core does. A `docs:` commit touching only the README
produces no release; a `fix:` commit touching only the README produces one
that changes no code.

Modules are versioned independently: a `resources/aws` fix should not bump core.
CI builds each module with `GOWORK=off`, so a workspace replace cannot mask a
`require` that a consumer would fail to resolve. For the same reason, when the
build tool's `require` of core moves, core is released first.

Library modules need no publishing step beyond the tag. `cmd/celerity-go` is
built and attached to its release by a job of the same workflow, using
`scripts/package-cli.sh`; run it locally with a `TAG` to see what a release
carries:
Every module releases together, at one version. release-please keeps one release pull request
for the repository; merging it tags the root module (`v0.2.1`), and `scripts/tag-modules.sh`
tags every other module at the same version with its directory prefix
(`serverless/aws/v0.2.1`), as Go requires. There is one changelog, at the root.

Every module shares that release, whatever a commit's scope. Only `feat`, `fix`, `perf` and
`deps` release and appear in the changelog, so use another type (`ci`, `docs`, `chore`,
`refactor`, `style` or `test`) for changes that don't change what a module does.

CI builds each module with `GOWORK=off`, against its own `go.mod` and `replace` directives
rather than the workspace.

Library modules need no publishing step beyond the tag. `cmd/celerity-go` is built and
attached to its release by a job of the same workflow, using `scripts/package-cli.sh`; run it
locally with a `TAG` to see what a release carries:

```bash
TAG=cmd/celerity-go/v0.1.0 bash scripts/package-cli.sh
```

Why it works this way, and what broke the releases that didn't: [docs/RELEASING.md](docs/RELEASING.md).

## Tests

Two layers, and the split is about what each can actually establish.
Expand Down
Loading
Loading