> 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/fr/compiler-depuis-les-sources/backend.md). Agents can also search and read this documentation through its [MCP server](https://docs.aethercube.fr/~gitbook/mcp).

# Backend

Cette page explique comment compiler et lancer le backend en local, ses programmes et ses cibles `make`. Elle sert à celles et ceux qui compilent ou modifient le backend.

Le backend est un service Go dans `backend-services/`. Il utilise PostgreSQL 16 comme source de vérité et Redis 7 pour l'annuaire des serveurs, les limites de débit, les nonces et les marqueurs de révocation. La couche HTTP est `chi`, et le contrat est `api/openapi.yaml` (OpenAPI 3.1).

## Prérequis

* Go 1.26 ou plus. La commande `go` récupère par défaut la toolchain fixée (`go1.27.4`).
* PostgreSQL et Redis. `make dev-up` démarre les deux avec Docker, avec MinIO comme CDN factice, depuis `deployments/docker-compose.dev.yml`.

## Démarrage rapide

```sh
cd backend-services
make dev-up                                        # PostgreSQL, Redis et MinIO
cp configs/config.example.yaml configs/config.yaml
go run ./cmd/keygen --out ./keys --kid jwt-dev     # clés de développement, non commitées
# renseigne authentication.jwt_key_id et jwt_signing_key_path dans configs/config.yaml
export AETHERCUBE_DATABASE_PASSWORD=...            # jamais dans le YAML
go run ./cmd/migrate up                            # explicite : l'API ne migre jamais
go run ./cmd/api                                   # http://127.0.0.1:8080
curl http://127.0.0.1:8080/health/ready
```

Il n'existe pas d'administrateur par défaut. Crée un compte via l'API, puis accorde le rôle en ligne de commande :

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

## Programmes

| Programme     | Rôle                                                                                       |
| ------------- | ------------------------------------------------------------------------------------------ |
| `cmd/api`     | L'API HTTP, avec un listener Prometheus optionnel.                                         |
| `cmd/migrate` | `up`, `down`, `goto`, `version` et `force` sur les migrations embarquées.                  |
| `cmd/worker`  | Réconciliation périodique et idempotente : expirations, purges et cohérence de l'annuaire. |
| `cmd/admin`   | Outil d'opérateur : gestion des rôles et des actualités.                                   |
| `cmd/keygen`  | Génère les clés JWT, de tickets et de secrets de serveurs.                                 |

`make build` construit les cinq dans `bin/`.

## Cibles make

| Cible                          | Fait                                                                                                        |
| ------------------------------ | ----------------------------------------------------------------------------------------------------------- |
| `make build`                   | Construit les cinq programmes.                                                                              |
| `make keys`                    | Génère les clés de développement.                                                                           |
| `make migrate`                 | Applique les migrations.                                                                                    |
| `make run`                     | Lance l'API avec `configs/config.yaml`.                                                                     |
| `make worker`                  | Lance le worker.                                                                                            |
| `make test`                    | Tests unitaires avec `-race`, et tests d'intégration quand les variables `AETHERCUBE_TEST_*` sont définies. |
| `make test-integration`        | Tests d'intégration seulement.                                                                              |
| `make lint`                    | `go vet` et `golangci-lint`.                                                                                |
| `make vuln`                    | `govulncheck`.                                                                                              |
| `make fmt`                     | `gofmt -s -w .`.                                                                                            |
| `make dev-up`, `make dev-down` | Démarre et arrête la pile de développement.                                                                 |

## Docker

`backend-services/Dockerfile` construit l'image.

## OpenAPI

`api/openapi.yaml` est généré et contrôlé par deux scripts :

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

Lance les deux après avoir changé un endpoint.

## API publique

Les endpoints publics sont documentés dans [API du backend](https://docs.aethercube.fr/developers/fr/api-du-backend/vue-d-ensemble.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/fr/compiler-depuis-les-sources/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.
