# Installation Guide

## Prerequisites

- Docker 24.x or later
- Docker Compose 2.x or later
- Domain name with DNS configured
- SSL certificate (or use Let's Encrypt)

## Step 1: Server Preparation

```bash
# Update system packages
sudo apt update && sudo apt upgrade -y

# Install Docker
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER

# Install Docker Compose
sudo apt install docker-compose-plugin
```

## Step 2: Clone and Configure

```bash
# Clone repository
git clone https://github.com/goa-gel/license-authority.git
cd license-authority

# Copy environment template
cp .env.example .env
```

Edit `.env` with required values:

```bash
# Database
DB_HOST=postgres
DB_PORT=5432
DB_USER=license_app
DB_PASSWORD=<secure-password>
DB_NAME=license_db

# JWT
JWT_SECRET=<64-character-random-string>

# Blockchain
BESU_RPC_URL=http://besu:8545
CONTRACT_ADDRESS=<deployed-contract-address>

# External Services
DIGILOCKER_CLIENT_ID=<your-client-id>
DIGILOCKER_CLIENT_SECRET=<your-secret>
```

## Step 3: Initialize Database

```bash
# Start database only
docker-compose up -d postgres

# Run migrations
docker-compose exec api npm run migration:run

# Seed initial data
docker-compose exec api npm run seed
```

## Step 4: Deploy Blockchain

```bash
# Start Besu node
docker-compose up -d besu

# Wait for node sync
docker-compose logs -f besu

# Deploy smart contract
docker-compose exec api npm run deploy:contract
```

## Step 5: Start Application

```bash
# Start all services
docker-compose up -d

# Verify health
docker-compose ps
curl http://localhost:3000/api/health
```

## Step 6: Configure SSL

```bash
# Using Certbot with Nginx
sudo certbot --nginx -d your-domain.gov.in
```

## Verification Checklist

- [ ] All containers running (`docker-compose ps`)
- [ ] API health check returns 200
- [ ] Frontend loads in browser
- [ ] Database connections working
- [ ] Blockchain node synced
- [ ] SSL certificate valid
