# SolaceNet Setup Guide

Complete setup instructions for the SolaceNet Capability Platform.

## Prerequisites

- Node.js 18+
- PostgreSQL 14+
- Redis 7+
- Go 1.21+ (for gateway)
- Docker & Docker Compose (optional)

## Database Setup

1. **Run Prisma migrations:**

```bash
cd dbis_core
npx prisma generate
npx prisma migrate dev --name add_solacenet_models
```

2. **Verify schema:**

```bash
npx prisma studio
```

## Environment Configuration

Create/update `.env` file:

```env
# Database
DATABASE_URL=postgresql://user:password@localhost:5432/dbis

# Redis (for policy caching)
REDIS_URL=redis://localhost:6379
SOLACENET_REDIS_URL=redis://localhost:6379

# Kafka (for events)
KAFKA_BROKERS=localhost:9092
SOLACENET_KAFKA_BROKERS=localhost:9092

# Gateway
SOLACENET_GATEWAY_PORT=8080
POLICY_ENGINE_URL=http://localhost:3000
BACKEND_URL=http://localhost:3000
JWT_SECRET=your-secret-key

# API
PORT=3000
NODE_ENV=development
```

## Start Services

### Option 1: Docker Compose (Recommended)

```bash
docker-compose -f docker-compose.solacenet.yml up -d
```

### Option 2: Manual Start

1. **Start Redis:**
```bash
redis-server
```

2. **Start DBIS API:**
```bash
cd dbis_core
npm install
npm run dev
```

3. **Start Go Gateway:**
```bash
cd gateway/go
go mod tidy
go run main.go
```

4. **Start Operations Console:**
```bash
cd frontend/solacenet-console
npm install
npm start
```

## Seed Initial Data

Create a seed script to populate initial capabilities:

```typescript
// scripts/seed-solacenet.ts
import { capabilityRegistryService } from './src/core/solacenet/registry/capability-registry.service';

async function seed() {
  // Register core capabilities
  await capabilityRegistryService.createCapability({
    capabilityId: 'payment-gateway',
    name: 'Payment Gateway',
    version: '1.0.0',
    description: 'Payment processing gateway',
    defaultState: 'disabled',
  });

  await capabilityRegistryService.createCapability({
    capabilityId: 'wallet-accounts',
    name: 'Wallet Accounts',
    version: '1.0.0',
    description: 'Stored value wallet accounts',
    defaultState: 'disabled',
  });

  // Add more capabilities...
}

seed();
```

Run with:
```bash
npx ts-node scripts/seed-solacenet.ts
```

## Verify Installation

1. **Check API health:**
```bash
curl http://localhost:3000/health
```

2. **List capabilities:**
```bash
curl -H "Authorization: Bearer YOUR_TOKEN" \
  http://localhost:3000/api/v1/solacenet/capabilities
```

3. **Check gateway:**
```bash
curl http://localhost:8080/health
```

## Testing

Run tests:
```bash
npm test
```

## Troubleshooting

### Redis Connection Issues
- Verify Redis is running: `redis-cli ping`
- Check `REDIS_URL` in `.env`

### Database Migration Errors
- Ensure PostgreSQL is running
- Check `DATABASE_URL` format
- Run `npx prisma migrate reset` if needed

### Gateway Not Starting
- Verify Go 1.21+ is installed: `go version`
- Run `go mod tidy` in `gateway/go`
- Check port 8080 is available

## Next Steps

1. Configure entitlements for your tenants
2. Set up policy rules
3. Enable capabilities as needed
4. Monitor audit logs
