# Deployment

## Container

Start the full stack (app + Redis + MongoDB):

```sh
docker compose up --build
```

Start in the background:

```sh
docker compose up --build -d
docker compose down
```

Infrastructure only (run app via PM2 on host):

```sh
docker compose up redis mongodb -d
```

## Services

| Service | Host port | Purpose |
| --- | --- | --- |
| `repo-sync-service` | `6001` | HTTP control plane |
| `redis` | `6379` | Redis Streams backbone |
| `mongodb` | `27018` | Metadata store (TW-19; dedicated local instance) |

The app container sets:

- `REDIS_URL=redis://redis:6379`
- `MONGO_URI=mongodb://mongodb:27017/adpilot_repo_sync`

It waits for Redis and Mongo health checks before starting.

Optional dev UI: `docker compose --profile dev up mongo-express -d` → http://localhost:8082

See [mongodb.md](mongodb.md) for Atlas production setup.

## Health Checks

- Liveness: `GET /healthz` — process is running
- Readiness: `GET /readyz` — Redis and MongoDB must respond

If Redis or MongoDB is down, `/readyz` returns `503` with `not_ready`.

## Graceful shutdown

On `SIGINT` / `SIGTERM`:

1. Stop accepting new HTTP requests (10s timeout)
2. Wait up to **30 seconds** for in-flight repository syncs to finish
3. Close Redis and MongoDB connections

If syncs are still running after the drain timeout, shutdown proceeds and a warning is logged.

## Notes

- Redis connectivity is provided by `internal/redis/client.go` (TW-15).
- Stream publishing via `XADD` is implemented in `internal/redis/publisher.go` (TW-16).
- Git sync and event orchestration are implemented in TW-17/TW-18.
- MongoDB metadata persistence (TW-19); compose includes Mongo for local dev.
- App wiring, readiness, and graceful shutdown (TW-22).
