> ## Documentation Index
> Fetch the complete documentation index at: https://docs.s4kit.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Self-Hosting

> Run S4Kit on your own infrastructure

Run S4Kit on your own infrastructure for full control over your data.

## Prerequisites

* **Docker** with Compose support
* **Bun** 1.3.4+ ([install](https://bun.sh))

## Quick Setup

<Steps>
  <Step title="Clone and Install">
    ```bash theme={null}
    git clone https://github.com/michal-majer/s4kit.git
    cd s4kit
    bun install
    ```
  </Step>

  <Step title="Start Database Services">
    ```bash theme={null}
    docker compose up -d postgres redis
    ```
  </Step>

  <Step title="Initialize Database">
    ```bash theme={null}
    cd packages/platform/backend
    bun x drizzle-kit push --force
    bun run db:seed
    bun run db:setup-admin
    ```
  </Step>

  <Step title="Build and Start">
    ```bash theme={null}
    cd ../..
    bun run build

    # Start services (3 terminals or use PM2)
    cd packages/platform/backend && bun run start
    cd packages/platform/frontend && bun run start
    cd packages/platform/proxy && bun run start
    ```
  </Step>
</Steps>

**Access**: [http://localhost:3001](http://localhost:3001) | **Login**: `admin@example.com` / `changeme123`

## Service Ports

| Service    | Port | Description               |
| ---------- | ---- | ------------------------- |
| Frontend   | 3001 | Admin dashboard (Next.js) |
| Backend    | 3000 | Admin API                 |
| Proxy      | 3002 | SDK proxy                 |
| PostgreSQL | 5433 | Database                  |
| Redis      | 6379 | Cache                     |

## Configuration

Main config in `packages/platform/backend/.env`:

```bash theme={null}
DATABASE_URL=postgresql://s4kit:s4kit_dev_password@localhost:5433/s4kit
REDIS_URL=redis://localhost:6379
ENCRYPTION_KEY=<openssl rand -hex 32>
BETTER_AUTH_SECRET=<openssl rand -base64 32>
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=changeme123
FRONTEND_URL=http://localhost:3001
```

<Warning>
  Generate new `ENCRYPTION_KEY` and `BETTER_AUTH_SECRET` for production!
</Warning>

## Process Management (PM2)

```bash theme={null}
npm install -g pm2
pm2 start packages/platform/backend/src/index.ts --name backend --interpreter ~/.bun/bin/bun
pm2 start packages/platform/frontend/server.js --name frontend
pm2 start packages/platform/proxy/src/index.ts --name proxy --interpreter ~/.bun/bin/bun
pm2 save && pm2 startup
```

## Health Checks

```bash theme={null}
curl http://localhost:3000/api/health  # Backend
curl http://localhost:3002/health      # Proxy
```

<Card title="Production Deployment" icon="rocket" href="https://github.com/michal-majer/s4kit/blob/main/DEPLOY.md">
  See DEPLOY.md for infrastructure, SSL, and scaling →
</Card>
