# Quick Start - Complete Setup

## 🚀 One-Command Setup

Run the complete setup script to:
1. ✅ Verify all files
2. ✅ Test database connection
3. ✅ Run database migrations
4. ✅ Verify migrations
5. ✅ Check for admin users
6. ✅ Verify service files

```bash
cd smom-dbis-138/services/token-aggregation
./scripts/complete-setup.sh
```

## 📋 Step-by-Step Manual Setup

### 1. Configure Environment

```bash
cd smom-dbis-138/services/token-aggregation
cp .env.example .env
nano .env  # Edit with your database URL and settings
```

### 2. Run Database Migrations

```bash
./scripts/run-migrations.sh
```

Or manually:
```bash
psql $DATABASE_URL -f ~/projects/explorer-monorepo/backend/database/migrations/0011_token_aggregation_schema.up.sql
psql $DATABASE_URL -f ~/projects/explorer-monorepo/backend/database/migrations/0012_admin_config_schema.up.sql
```

### 3. Create Admin User

```bash
./scripts/create-admin-user.sh
```

Enter:
- Username
- Password
- Email (optional)
- Role (admin/super_admin/operator/viewer)

### 4. Install Dependencies

```bash
# Backend
npm install

# Frontend
cd frontend
npm install
cd ..
```

### 5. Build

```bash
# Backend
npm run build

# Frontend
cd frontend
npm run build
cd ..
```

### 6. Start Service

**Option A: Local Development**
```bash
# Terminal 1: Backend
npm run dev

# Terminal 2: Frontend
cd frontend
npm run dev
```

**Option B: Production**
```bash
npm start
# Frontend served via nginx (after Proxmox deployment)
```

**Option C: Proxmox Deployment**
```bash
./scripts/deploy-to-proxmox.sh
```

## ✅ Verification Checklist

After setup, verify:

- [ ] Database migrations applied
- [ ] Admin user created
- [ ] Service starts without errors
- [ ] Can access control panel
- [ ] Can login with admin credentials
- [ ] Can add API keys via UI
- [ ] Can add endpoints via UI
- [ ] Dashboard shows statistics

## 🔍 Quick Tests

### Test Database Connection
```bash
psql $DATABASE_URL -c "SELECT COUNT(*) FROM admin_users;"
```

### Test API
```bash
curl http://localhost:3000/health
```

### Test Admin API (after login)
```bash
# Get token from login
TOKEN="your-jwt-token"
curl -H "Authorization: Bearer $TOKEN" http://localhost:3000/api/v1/admin/status
```

## 📊 Expected Results

After complete setup:

- **Database**: 13+ tables created (token aggregation + admin config)
- **Backend**: Service running on port 3000
- **Frontend**: Control panel accessible
- **Admin**: At least 1 admin user created

## 🎯 Next Actions

1. **Login** to control panel
2. **Add API Keys** for external services
3. **Configure Endpoints** for chains 138 and 651940
4. **Add DEX Factories** for pool discovery
5. **Monitor** service via dashboard

## 📚 Documentation

- `README.md` - Service overview
- `CONTROL_PANEL.md` - Control panel features
- `PROXMOX_DEPLOYMENT.md` - Deployment guide
- `SETUP_COMPLETE.md` - This file
