> For the complete documentation index, see [llms.txt](https://docs.aethercube.fr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aethercube.fr/developers/building-from-source/backend.md). Agents can also search and read this documentation through its [MCP server](https://docs.aethercube.fr/~gitbook/mcp).

# Backend

Build this if you want your own backend for testing the launcher, a tool or a server in online mode. The backend is a Go service in `backend-services/`. It uses PostgreSQL 16 as the source of truth and Redis 7 for the server directory, rate limits, nonces and revocation markers. The HTTP layer is `chi`, and the contract is `api/openapi.yaml` (OpenAPI 3.1).

## Requirements

* Go 1.26 or later. The `go` command fetches the pinned toolchain (`go1.27.4`) by default.
* PostgreSQL and Redis. `make dev-up` starts both with Docker, together with MinIO as a CDN stub, from `deployments/docker-compose.dev.yml`.

## Quick start

```sh
cd backend-services
make dev-up                                        # PostgreSQL, Redis and MinIO
cp configs/config.example.yaml configs/config.yaml
go run ./cmd/keygen --out ./keys --kid jwt-dev     # development keys, not committed
# set authentication.jwt_key_id and jwt_signing_key_path in configs/config.yaml
export AETHERCUBE_DATABASE_PASSWORD=...            # never in the YAML
go run ./cmd/migrate up                            # explicit: the API never migrates
go run ./cmd/api                                   # http://127.0.0.1:8080
curl http://127.0.0.1:8080/health/ready
```

No default administrator exists. Register an account through the API, then grant the role from the command line:

```sh
go run ./cmd/admin roles grant --username YourName --role administrator
```

## Programs

| Program       | Purpose                                                                        |
| ------------- | ------------------------------------------------------------------------------ |
| `cmd/api`     | The HTTP API, with an optional Prometheus listener.                            |
| `cmd/migrate` | `up`, `down`, `goto`, `version` and `force` over the embedded migrations.      |
| `cmd/worker`  | Periodic, idempotent reconciliation: expiry, purges and directory consistency. |
| `cmd/admin`   | Operator tool: role management and news.                                       |
| `cmd/keygen`  | Generates JWT, ticket and server-secret keys.                                  |

`make build` builds all five into `bin/`.

## Make targets

| Target                         | Does                                                                                           |
| ------------------------------ | ---------------------------------------------------------------------------------------------- |
| `make build`                   | Build the five programs.                                                                       |
| `make keys`                    | Generate development keys.                                                                     |
| `make migrate`                 | Apply the migrations.                                                                          |
| `make run`                     | Run the API with `configs/config.yaml`.                                                        |
| `make worker`                  | Run the worker.                                                                                |
| `make test`                    | Unit tests with `-race`, and integration tests when the `AETHERCUBE_TEST_*` variables are set. |
| `make test-integration`        | Integration tests only.                                                                        |
| `make lint`                    | `go vet` and `golangci-lint`.                                                                  |
| `make vuln`                    | `govulncheck`.                                                                                 |
| `make fmt`                     | `gofmt -s -w .`.                                                                               |
| `make dev-up`, `make dev-down` | Start and stop the development stack.                                                          |

## Docker

`backend-services/Dockerfile` builds the image.

## OpenAPI

`api/openapi.yaml` is generated and checked by two scripts:

```sh
python scripts/gen_openapi.py api/openapi.yaml
python scripts/check_openapi.py .
```

Run both after you change an endpoint, so the contract file always matches the code.

## Public API

The public endpoints are documented in [Backend API](https://docs.aethercube.fr/developers/backend-api/overview.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.aethercube.fr/developers/building-from-source/backend.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
