api

module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0

README

api

CI Release CodeQL Latest release Go version Coverage OpenSSF Scorecard License

Code Smells Reliability Rating Security Rating Maintainability Rating Vulnerabilities

The NovaTrail platform service, the only service of the first slice. It checks the account owner's sign-in and keeps the learners, their consent and their attempts in its database — among the platform's parts, the one place where learners' data is stored on the server, and the learner model lives there too, as an append-only log of evidence. It runs each check — tutor reads handwritten work and module-kit gives the verdict, while a choice tapped among options is checked without AI — then has learner-model weigh the attempt's evidence and engine pick the next lesson or task with a reason code: all four are libraries in its own process, and it reaches AI providers only through tutor, without the learner's identifiers.

A component of NovaTrail, a universal open platform for adaptive learning, interactive lessons and AI tutoring. It belongs to stage 2, First slice with learners, with tutor, canvas, app, skill-map and infra.

Status

Detailing is done. The first epic of RUN.md decided everything the component's card left open, and docs/architecture.md now describes the service; the code epics it proposes are in RUN.md. The first, E2 — the skeleton, database, sign-in and deletion — has begun: the service serves the contract on Connect, every request with a token passes the checks before learner data, and an owner with an invite code creates the account and reads it; the other methods answer unimplemented until the tasks that build them. Its first build with app, the first app, which the author alone runs locally, waits for this repository's skeleton, app's code and tutor's first code: the module format's code and content, the learner model and engine have released, and spec's contract between app and api is already out. E2 needs none of these, and spec's cross-repository plan lets it run now (RUN.md, table 1). No child learns here before verifiable parental consent and the contracts with AI providers are in place.

Build and run

Inside the devcontainer, which pins Go and just:

just build              # a static binary, bin/api
./bin/api version       # its version, commit, build date and Go
just run                # serve on PORT, 8080 by default

just ci-lint, just ci-test, just ci-vuln and just ci-licenses are the checks CI runs: gofmt and go vet, the tests with the race detector and their coverage in coverage/go.out, govulncheck and go-licenses.

A release comes out by itself once CI passes on main, from just release-files: static binaries for linux/amd64 and linux/arm64, the Dockerfile, the licenses the binaries come with and SHA256SUMS, each file signed. NovaTrail publishes no image. Whoever deploys checks the files with just -f spec/justfile release-verify api <tag> <file> and builds the image around the binary: docker build --target release --build-context binary=<a folder holding the binary as api> ., with the release's Dockerfile.

The binary reads its configuration from the environment, and only these variables:

Variable Default Meaning
PORT 8080 the port to listen on; 0, off a deployment, asks the kernel for a free one, which the startup line names
API_LOG_LEVEL info debug, info, warn or error
API_HTTP_READ_HEADER_TIMEOUT 5s how long a client may take to send its headers
API_HTTP_READ_TIMEOUT 30s how long a client may take to send its whole request
API_HTTP_WRITE_TIMEOUT 60s how long the server may take to answer
API_HTTP_IDLE_TIMEOUT 120s how long an idle connection is kept
API_SHUTDOWN_TIMEOUT 9s the whole way out after a stop is asked for; under 10s when deployed
API_REQUEST_TIMEOUT 30s the longest a request may run, under API_HTTP_WRITE_TIMEOUT
API_DATABASE_URL — the pooler's connection string of the database api, with sslmode=verify-full; required by serve and invite
API_OPENFGA_DATABASE_URL — the pooler's connection string of openfga, the store of the rights; required by serve
API_FIREBASE_PROJECT_ID — the Firebase project whose ID tokens are accepted; required by serve
API_FIREBASE_CREDENTIALS — a service account's key, required off a deployment and refused on one, where the service's own account is taken, with no key
API_APP_ORIGIN — the exact origin of app, which CORS answers when api has an origin of its own
K_SERVICE — set by Cloud Run; a deployment is known by it

api serve opens the database api, the rights and the sign-in service before it takes its port, and fails to start when one does not open. It serves the contract novatrail.api.v1 on Connect, in binary protobuf and in JSON with the protobuf names, and logs a line for each request: its method, code, cause and time, and nothing of who asked.

api migrate applies the migrations of the database api and of openfga, the store of the rights, makes that store and writes its model when it must, and exits. It reads API_LOG_LEVEL, API_MIGRATE_DATABASE_URL and API_MIGRATE_OPENFGA_DATABASE_URL, the direct connection strings — not the pooler's — with sslmode=verify-full; just migrate runs it. The tests run on a real PostgreSQL that embedded-postgres downloads on their first run, with no Docker.

api invite makes one invite code of the closed slice and prints it on stdout, once: the database api keeps its SHA-256 alone, and the code lets one owner create an account. -tariff names the tariff the code passes to that account, closed_slice by default and the only one so far. It reads API_LOG_LEVEL and API_DATABASE_URL, and logs a failure on stderr, so that stdout holds the code alone. Run it from a terminal of the operator's own: a job's output is kept in its log, the code with it.

A secret — a key, a token, a connection string — comes from its variable or from a file outside the repository whose absolute path the variable with the suffix _FILE names; a file inside a git working tree is refused. The log is JSON on stdout, and writes only the events and fields of its table, internal/logging/events.go: no identifier, address or content of a learner's work.

Documents

The documents are in Russian.

  • docs/architecture.md — the component: what it does and does not do, its data and links, what was decided and how the service is built.
  • docs/decisions.md — the decision log: what was decided, why, and what was rejected.
  • RUN.md — the work plan, in epics.

The working rules, for people and coding agents alike, are in CLAUDE.md and AGENTS.md. The platform's shared vocabulary, formats, contracts and decisions are in spec, checked out here as a git submodule at v0.9.11: clone this repository with git clone --recurse-submodules.

License

Apache-2.0.

Directories

Path Synopsis
cmd
api command
Command api is NovaTrail's platform service, one binary with a command for each thing it is run for: serve, migrate, invite and version.
Command api is NovaTrail's platform service, one binary with a command for each thing it is run for: serve, migrate, invite and version.
internal
account
Package account is api's AccountService of the contract novatrail.api.v1: the account and its invite code, and, task by task, its PIN, profiles and deletion (R04, R34).
Package account is api's AccountService of the contract novatrail.api.v1: the account and its invite code, and, task by task, its PIN, profiles and deletion (R04, R34).
authn
Package authn is api's port to the sign-in service.
Package authn is api's port to the sign-in service.
authn/authntest
Package authntest is a fake of authn.Port for the tests of the code that holds it: a token is whatever the test says it is, and the users are the test's own.
Package authntest is a fake of authn.Port for the tests of the code that holds it: a token is whatever the test says it is, and the users are the test's own.
authz
Package authz is api's rights: OpenFGA, a library in api's own process, on its store in the database openfga (R04, R31).
Package authz is api's rights: OpenFGA, a library in api's own process, on its store in the database openfga (R04, R31).
config
Package config reads the service's configuration from the environment.
Package config reads the service's configuration from the environment.
invite
Package invite is the invite codes of the closed slice (R04, R34): how a code is made, how one given back is read, and the SHA-256 that is all the database keeps of it.
Package invite is the invite codes of the closed slice (R04, R34): how a code is made, how one given back is read, and the SHA-256 that is all the database keeps of it.
logging
Package logging is the service's log: JSON lines on one stream, in the keys Cloud Logging reads, held to the table of events in events.go.
Package logging is the service's log: JSON lines on one stream, in the keys Cloud Logging reads, held to the table of events in events.go.
rpc
Package rpc is api's server of the contract novatrail.api.v1, on Connect v2 (R17, R18, R33): the methods of the contract, its codecs, and the interceptors every request goes through — its line of the log, its time limit and the checks of architecture 3.1, which run before any handler.
Package rpc is api's server of the contract novatrail.api.v1, on Connect v2 (R17, R18, R33): the methods of the contract, its codecs, and the interceptors every request goes through — its line of the log, its time limit and the checks of architecture 3.1, which run before any handler.
server
Package server is the HTTP server of the service and its graceful stop.
Package server is the HTTP server of the service and its graceful stop.
store
Package store is api's database: its schema, the migrations that make it, the pool requests take their connections from, and the transaction a write under an account runs in (R29).
Package store is api's database: its schema, the migrations that make it, the pool requests take their connections from, and the transaction a write under an account runs in (R29).
store/storetest
Package storetest runs the tests of api's database on a real PostgreSQL with no Docker, as the devcontainer and CI have none: embedded-postgres starts one server for a test binary, when its first test asks for a database, migrates a template database once, and gives each test a database of its own made from it, which is a copy and takes milliseconds (R29; amendment of 2026-11-02 to R05).
Package storetest runs the tests of api's database on a real PostgreSQL with no Docker, as the devcontainer and CI have none: embedded-postgres starts one server for a test binary, when its first test asks for a database, migrates a template database once, and gives each test a database of its own made from it, which is a copy and takes milliseconds (R29; amendment of 2026-11-02 to R05).
version
Package version holds the build identity of the binary.
Package version holds the build identity of the binary.

Jump to

Keyboard shortcuts

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