# AS4 Settlement Quick Start Guide

**Date**: 2026-01-19  
**For**: Developers and Operators

---

## Quick Start (5 Minutes)

### Prerequisites Check

```bash
# Check Node.js
node --version  # Should be 18+

# Check PostgreSQL
psql --version  # Should be 14+

# Check Redis
redis-cli --version  # Should be 7+
```

### Step 1: Environment Setup

```bash
cd dbis_core

# Copy environment template
cp .env.example .env

# Edit .env and add:
# AS4_BASE_URL=https://as4.dbis.org
# REDIS_URL=redis://localhost:6379
# CHAIN138_RPC_URL=http://192.168.11.250:8545
```

### Step 2: Database Migration

```bash
# Generate Prisma client
npx prisma generate

# Run migration
npx prisma migrate deploy
```

### Step 3: Seed Marketplace

```bash
# Seed AS4 offering
npx ts-node scripts/seed-as4-settlement-marketplace-offering.ts
```

### Step 4: Start Server

```bash
# Start development server
npm run dev
```

### Step 5: Test Endpoint

```bash
# Health check
curl http://localhost:3000/health
```

---

## Common Commands

### Development
```bash
npm run dev          # Start dev server
npm test            # Run tests
npm run lint        # Run linter
npx prisma studio   # Open Prisma Studio
```

### Deployment
```bash
./scripts/deploy-as4-settlement.sh  # Automated deployment
./scripts/test-as4-settlement.sh    # Automated testing
```

### Database
```bash
npx prisma migrate dev              # Create migration
npx prisma migrate deploy           # Apply migration
npx prisma generate                 # Generate client
npx prisma studio                   # Database GUI
```

---

## API Quick Reference

### Register Member
```bash
POST /api/v1/as4/directory/members
```

### Submit Instruction
```bash
POST /api/v1/as4/settlement/instructions
```

### Get Instruction Status
```bash
GET /api/v1/as4/settlement/instructions/:instructionId?fromMemberId=XXX
```

### Generate Statement
```bash
GET /api/v1/as4/settlement/statements?memberId=XXX&accountId=YYY&startDate=...&endDate=...
```

---

## Troubleshooting

### Database Not Connecting
```bash
# Check connection
psql -h 192.168.11.105 -U dbis_user -d dbis_core -c "SELECT 1"
```

### Redis Not Connecting
```bash
# Check Redis
redis-cli ping
```

### Server Won't Start
```bash
# Check logs
npm run dev 2>&1 | tee server.log
```

---

**For detailed steps, see**: [DETAILED_NEXT_STEPS.md](./DETAILED_NEXT_STEPS.md)
