# Infra

This directory contains everything needed to run Arche as a full stack (local and VPS): reverse proxy, database, networks, and hardening.

## Entry Points

- Local development stack (Traefik + Postgres + Web): `infra/compose/README.md`
- One-click deployer (VPS + local-dev): `infra/deploy/README.md`
- Coolify deployment (VPS with Coolify): `infra/coolify/README.md`
- Workspace image (OpenCode + git): `infra/workspace-image/README.md`

## Knowledge Base (KB)

The system includes a shared Knowledge Base injected into each user workspace.

### Architecture

```
Host (VPS)
├── /opt/arche/kb-content/   ← KB content bare repo
├── /opt/arche/kb-config/    ← Config bare repo
│
└── Containers (per user)
└── /workspace/          ← Persistent volume
    ├── .git/            ← Local repo with `kb` remote
    ├── Company/         ← Generated by kickstart during initial setup
    ├── ...
    └── opencode.json    ← Generated at runtime from kb-config
```

### KB Setup

1. **Build the workspace image** (includes git):
   ```bash
   cd infra/workspace-image
   podman build --build-arg OPENCODE_VERSION="$(cat ../../versions/opencode.version)" -t arche-workspace:latest .
   ```

2. **Initialize KB and config bare repos (empty)**:
   ```bash
   ./scripts/deploy-kb.sh /opt/arche/kb-content
   ./scripts/deploy-config.sh /opt/arche/kb-config
   ```

3. **Set environment variables** in compose or production:
   ```
   KB_CONTENT_HOST_PATH=/opt/arche/kb-content
   KB_CONFIG_HOST_PATH=/opt/arche/kb-config
   ```

### Sync

On a fresh installation, the workspace remains blocked until kickstart is completed at `/u/[slug]/kickstart`, which writes initial KB content and config.

Users can sync their workspace with the central KB:

1. **From the UI**: "Sync KB" button in the workspace header
2. **Manually** (inside container):
   ```bash
   git fetch kb
   git merge kb/main
   ```

If conflicts appear, the user resolves them in the integrated editor.
