feat(backend): scaffold Rust + axum backend #23

Open
claude-desktop wants to merge 2 commits from feat/backend-scaffold into feat/compose-skeleton
Collaborator

Closes #3. Stacked on top of #22 — please merge that first (this PR's base is feat/compose-skeleton; it will auto-retarget to main once #22 lands).

Summary

  • Cargo workspace under backend/ with koinos binary crate and koinos-core library crate, Rust edition 2021, MSRV 1.88 pinned via rust-toolchain.toml.
  • GET /healthz → 200 JSON {status, version, commit} (commit fed in via KOINOS_GIT_SHA build arg).
  • GET /readyz → 200 when SELECT 1 succeeds against the Postgres pool, 503 otherwise.
  • Structured JSON logs (tracing-subscriber + KOINOS_LOG env filter).
  • SIGTERM / Ctrl-C graceful shutdown.
  • Layered config: defaults → koinos.yamlKOINOS__* env vars.
  • Multi-stage Dockerfile with cargo-chef caching; distroless cc runtime image.
  • docker-compose.yml builds the image from ./backend; Caddyfile routes /api, /healthz, /readyz to koinos-backend:8080.
  • Justfile recipes fmt-check, lint, test, ci-setup, ci-build, ci-package now wired to the real crate (cross-compile branch reads $ARCH).
  • Integration test in backend/crates/koinos/tests/healthz.rs boots the router on a random port and asserts the JSON envelope.

Locally verified: cargo check, cargo test, cargo clippy -- -D warnings, cargo fmt --check all green.

Acceptance criteria

Cargo layout

  • backend/ workspace with koinos bin + koinos-core lib
  • Edition 2021, MSRV pinned in rust-toolchain.toml
  • axum, tokio, tower, tracing, tracing-subscriber, serde, serde_yaml, sqlx (postgres), anyhow, thiserror, config added

Runtime

  • /healthz returns {status:"ok", version, commit}
  • /readyz returns 200 iff DB reachable, 503 otherwise
  • JSON logs via tracing-subscriber
  • Graceful shutdown on SIGTERM

Configuration

  • Defaults → file → env (KOINOS__*)
  • Malformed config exits non-zero with a clear error

Container

  • Multi-stage Dockerfile (cargo-chef) on distroless
  • Image wired into compose from #2

Tests

  • Integration test on random port hitting /healthz

Out of scope

  • OIDC, FHIR client, Matrix client — tracked separately.
  • Prometheus endpoint — later chore.
Closes #3. Stacked on top of #22 — please merge that first (this PR's base is `feat/compose-skeleton`; it will auto-retarget to `main` once #22 lands). ## Summary - Cargo workspace under `backend/` with `koinos` binary crate and `koinos-core` library crate, Rust edition 2021, MSRV 1.88 pinned via `rust-toolchain.toml`. - `GET /healthz` → 200 JSON `{status, version, commit}` (commit fed in via `KOINOS_GIT_SHA` build arg). - `GET /readyz` → 200 when `SELECT 1` succeeds against the Postgres pool, 503 otherwise. - Structured JSON logs (`tracing-subscriber` + `KOINOS_LOG` env filter). - SIGTERM / Ctrl-C graceful shutdown. - Layered config: defaults → `koinos.yaml` → `KOINOS__*` env vars. - Multi-stage Dockerfile with `cargo-chef` caching; distroless `cc` runtime image. - `docker-compose.yml` builds the image from `./backend`; Caddyfile routes `/api`, `/healthz`, `/readyz` to `koinos-backend:8080`. - Justfile recipes `fmt-check`, `lint`, `test`, `ci-setup`, `ci-build`, `ci-package` now wired to the real crate (cross-compile branch reads `$ARCH`). - Integration test in `backend/crates/koinos/tests/healthz.rs` boots the router on a random port and asserts the JSON envelope. Locally verified: `cargo check`, `cargo test`, `cargo clippy -- -D warnings`, `cargo fmt --check` all green. ## Acceptance criteria ### Cargo layout - [x] `backend/` workspace with `koinos` bin + `koinos-core` lib - [x] Edition 2021, MSRV pinned in `rust-toolchain.toml` - [x] `axum`, `tokio`, `tower`, `tracing`, `tracing-subscriber`, `serde`, `serde_yaml`, `sqlx` (postgres), `anyhow`, `thiserror`, `config` added ### Runtime - [x] `/healthz` returns `{status:"ok", version, commit}` - [x] `/readyz` returns 200 iff DB reachable, 503 otherwise - [x] JSON logs via `tracing-subscriber` - [x] Graceful shutdown on SIGTERM ### Configuration - [x] Defaults → file → env (`KOINOS__*`) - [x] Malformed config exits non-zero with a clear error ### Container - [x] Multi-stage `Dockerfile` (cargo-chef) on distroless - [x] Image wired into compose from #2 ### Tests - [x] Integration test on random port hitting `/healthz` ## Out of scope - OIDC, FHIR client, Matrix client — tracked separately. - Prometheus endpoint — later chore.
## Summary

Baseline repository hygiene so contributors can onboard cleanly.

Closes #1.

## Changes

- **CODE_OF_CONDUCT.md** — Contributor Covenant 2.1 (verbatim from upstream).
- **CONTRIBUTING.md** — branching model, commit convention (Conventional Commits + DCO sign-off), SPDX header policy, test contract, PR workflow.
- **SECURITY.md** — 90-day embargo, disclosure scope, hardening pointer.
- **.editorconfig** — project-wide defaults (LF, UTF-8, trailing newline, Rust 4-space).
- **justfile** — implements the user's CI contract recipes (`ci-setup`, `qa`, `ci-build`, `ci-package`) as stubs + `dev-up` / `dev-down` wrappers for the Compose deployment (gated until #2 lands) + a `spec-check` helper.
- **spec/LICENSE-CC-BY-SA-4.0** — note that the spec directory is CC-BY-SA while code is AGPLv3.

## Acceptance criteria (from #1)

### Licensing
- [x] `LICENSE` file contains AGPLv3 text (already in initial commit).
- [x] `spec/` carries a CC-BY-SA-4.0 note.
- [x] SPDX header policy documented in `CONTRIBUTING.md`.

### Project meta
- [x] `CODE_OF_CONDUCT.md` — Contributor Covenant 2.1.
- [x] `CONTRIBUTING.md` — issues, PRs, Conventional Commits, DCO.
- [x] `SECURITY.md` — 90-day default.
- [x] `.editorconfig`.

### Justfile
- [x] `ci-setup`, `qa`, `ci-build`, `ci-package` stubs per convention.
- [x] `just dev-up` / `just dev-down` wrappers (gated until #2 lands).

## Test plan

- [x] `just --list` parses and shows every recipe.
- [x] `just dev-up` without a compose file prints a helpful error pointing to #2.
- [ ] CI pipeline does not exist yet (chore tracked separately).

## Notes

The CoC is the upstream Contributor Covenant 2.1 fetched verbatim — not regenerated — to avoid drift from the canonical text.

Reviewed-on: #21
Co-authored-by: Claude Desktop <claude-desktop@jacquin.app>
Co-committed-by: Claude Desktop <claude-desktop@jacquin.app>
Adds a Cargo workspace under backend/ with a koinos binary crate and
a koinos-core library crate. Exposes GET /healthz (always 200, JSON
with version + git SHA) and GET /readyz (200 when the Postgres pool
answers SELECT 1, 503 otherwise). Layered configuration through
defaults, koinos.yaml and KOINOS__* environment variables; structured
JSON logs via tracing-subscriber; SIGTERM-aware graceful shutdown.

A multi-stage Dockerfile uses cargo-chef to cache dependencies and
ships a distroless runtime image. The koinos-backend compose service
now builds from backend/ by default, and the Caddyfile routes /api,
/healthz and /readyz to port 8080. Justfile recipes for fmt-check,
lint, test, ci-setup, ci-build and ci-package are wired to the new
crate. An integration test boots the router on a random port and
verifies /healthz.

Closes #3

Signed-off-by: Charles Jacquin <charles@jacquin.app>
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/backend-scaffold:feat/backend-scaffold
git switch feat/backend-scaffold

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch feat/compose-skeleton
git merge --no-ff feat/backend-scaffold
git switch feat/backend-scaffold
git rebase feat/compose-skeleton
git switch feat/compose-skeleton
git merge --ff-only feat/backend-scaffold
git switch feat/backend-scaffold
git rebase feat/compose-skeleton
git switch feat/compose-skeleton
git merge --no-ff feat/backend-scaffold
git switch feat/compose-skeleton
git merge --squash feat/backend-scaffold
git switch feat/compose-skeleton
git merge --ff-only feat/backend-scaffold
git switch feat/compose-skeleton
git merge feat/backend-scaffold
git push origin feat/compose-skeleton
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
charles/koinos!23
No description provided.