# DBIS Services - Complete Task List

**Date**: 2026-01-02  
**Status**: ⏳ **PENDING IMPLEMENTATION**

---

## Overview

This document lists all tasks required to bring all DBIS services to full operational status after IP address changes.

---

## ✅ Completed Tasks

1. ✅ All container IP addresses updated
2. ✅ DATABASE_URL updated in API containers (VMIDs 10150, 10151)
3. ✅ Nginx configuration updated (VMID 10130)
4. ✅ Comprehensive service status check completed

---

## Priority 1: Database Services (Foundation)

### PostgreSQL Primary (VMID 10100)

**Container IP**: 192.168.11.105/24  
**Status**: Container running, PostgreSQL not installed

#### Installation Tasks

- [ ] **Task 1.1**: Install PostgreSQL 15
  - Update package repository
  - Install `postgresql-15` and `postgresql-contrib-15`
  - Verify installation

- [ ] **Task 1.2**: Initialize PostgreSQL database
  - Run `postgresql-setup` or manual initialization
  - Set data directory (`/var/lib/postgresql/15/main`)
  - Configure authentication

- [ ] **Task 1.3**: Configure PostgreSQL
  - Edit `/etc/postgresql/15/main/postgresql.conf`
    - Set `listen_addresses = '*'` or specific IP
    - Configure port (5432)
    - Set memory settings
    - Configure logging
  - Edit `/etc/postgresql/15/main/pg_hba.conf`
    - Configure host-based authentication
    - Allow connections from API containers (192.168.11.155, 192.168.11.156)

- [ ] **Task 1.4**: Create database and user
  - Create database: `dbis_core`
  - Create user: `dbis`
  - Set password (match `.env` file: `8cba649443f97436db43b34ab2c0e75b5cf15611bef9c099cee6fb22cc3d7771`)
  - Grant privileges

- [ ] **Task 1.5**: Create systemd service (if not auto-created)
  - Enable PostgreSQL service
  - Start PostgreSQL service
  - Verify service status
  - Set to start on boot

- [ ] **Task 1.6**: Verify PostgreSQL is running
  - Check service status: `systemctl status postgresql`
  - Check port listening: `ss -tln | grep 5432`
  - Test local connection: `psql -U dbis -d dbis_core -h localhost`
  - Test external connection from API container

- [ ] **Task 1.7**: Run database migrations (if needed)
  - Connect to database
  - Run Prisma migrations or schema setup
  - Verify tables/collections created

---

### PostgreSQL Replica (VMID 10101) - Optional

**Container IP**: 192.168.11.106/24  
**Status**: Container running, PostgreSQL not installed  
**Note**: Replica is optional, can be deferred if not immediately needed

#### Installation Tasks

- [ ] **Task 2.1**: Install PostgreSQL 15 (same version as primary)
  - Update package repository
  - Install `postgresql-15` and `postgresql-contrib-15`
  - Verify installation

- [ ] **Task 2.2**: Configure replication from primary
  - Set up replication user on primary
  - Configure `postgresql.conf` for replication
  - Configure `pg_hba.conf` for replication connections
  - Set up streaming replication
  - Initialize replica from primary backup

- [ ] **Task 2.3**: Create systemd service
  - Enable PostgreSQL service
  - Start PostgreSQL service
  - Verify replication status
  - Set to start on boot

- [ ] **Task 2.4**: Verify replication
  - Check replication lag
  - Verify data synchronization
  - Test read-only connections

---

## Priority 2: API Services (Application Layer)

### API Primary (VMID 10150)

**Container IP**: 192.168.11.155/24  
**Status**: Container running, Node.js not installed, application not deployed  
**Configuration**: ✅ DATABASE_URL updated

#### Installation Tasks

- [ ] **Task 3.1**: Install Node.js
  - Install Node.js 18+ (LTS recommended)
  - Options: NodeSource repository, nvm, or package manager
  - Verify installation: `node --version`, `npm --version`

- [ ] **Task 3.2**: Install system dependencies
  - Install build tools: `build-essential`, `python3`
  - Install PostgreSQL client libraries (if needed)
  - Install other system dependencies

- [ ] **Task 3.3**: Deploy DBIS Core application
  - Clone/copy application code to `/opt/dbis-core`
  - Verify `.env` file exists and is configured
  - Install npm dependencies: `npm install`
  - Build application (if needed): `npm run build`

- [ ] **Task 3.4**: Configure application
  - Verify `.env` file has correct DATABASE_URL (192.168.11.105:5432)
  - Set other required environment variables
  - Configure JWT secrets, API keys, etc.

- [ ] **Task 3.5**: Set up process manager (choose one)
  - **Option A**: systemd service
    - Create service file: `/etc/systemd/system/dbis-api.service`
    - Configure service (user, working directory, environment, etc.)
    - Enable and start service
  - **Option B**: PM2
    - Install PM2 globally: `npm install -g pm2`
    - Create PM2 ecosystem file
    - Start application with PM2
    - Set up PM2 startup script

- [ ] **Task 3.6**: Verify API service
  - Check service/process is running
  - Check port 3000 is listening
  - Test health endpoint: `curl http://localhost:3000/health`
  - Test from external: `curl http://192.168.11.155:3000/health`
  - Verify database connectivity

- [ ] **Task 3.7**: Set up logging
  - Configure log rotation
  - Verify logs are being written
  - Set up log monitoring (optional)

---

### API Secondary (VMID 10151)

**Container IP**: 192.168.11.156/24  
**Status**: Container running, Node.js not installed, application not deployed  
**Configuration**: ✅ DATABASE_URL updated

#### Installation Tasks

- [ ] **Task 4.1**: Install Node.js
  - Install Node.js 18+ (same version as primary)
  - Verify installation: `node --version`, `npm --version`

- [ ] **Task 4.2**: Install system dependencies
  - Install build tools and dependencies
  - Install PostgreSQL client libraries (if needed)

- [ ] **Task 4.3**: Deploy DBIS Core application
  - Clone/copy application code to `/opt/dbis-core`
  - Verify `.env` file exists and is configured
  - Install npm dependencies: `npm install`
  - Build application (if needed): `npm run build`

- [ ] **Task 4.4**: Configure application
  - Verify `.env` file has correct DATABASE_URL (192.168.11.105:5432)
  - Set other required environment variables
  - Configure for HA/secondary role (if needed)

- [ ] **Task 4.5**: Set up process manager
  - Create systemd service or PM2 configuration (same as primary)
  - Enable and start service

- [ ] **Task 4.6**: Verify API service
  - Check service/process is running
  - Check port 3000 is listening
  - Test health endpoint: `curl http://localhost:3000/health`
  - Test from external: `curl http://192.168.11.156:3000/health`
  - Verify database connectivity

- [ ] **Task 4.7**: Set up logging
  - Configure log rotation
  - Verify logs are being written

---

## Priority 3: Frontend Service (Verification)

### Frontend/Nginx (VMID 10130)

**Container IP**: 192.168.11.130/24  
**Status**: ✅ Running, ✅ Configuration updated

#### Verification Tasks

- [ ] **Task 5.1**: Verify Nginx configuration
  - Verify proxy_pass uses correct API IP (192.168.11.155:3000)
  - Check for any other hardcoded IP references
  - Test Nginx configuration: `nginx -t`

- [ ] **Task 5.2**: Test API connectivity from Frontend
  - Test proxy to API Primary: `curl http://localhost/api/health`
  - Verify requests are forwarded correctly
  - Check Nginx access/error logs

- [ ] **Task 5.3**: Verify frontend application (if deployed)
  - Check if frontend files are deployed
  - Verify Nginx serves frontend correctly
  - Test frontend → API connectivity

- [ ] **Task 5.4**: SSL/HTTPS configuration (if needed)
  - Configure SSL certificates
  - Set up HTTPS redirect
  - Verify SSL configuration

---

## Priority 4: Integration & Testing

### End-to-End Verification

- [ ] **Task 6.1**: Test database connectivity
  - From API Primary (10150): Test connection to PostgreSQL (192.168.11.105:5432)
  - From API Secondary (10151): Test connection to PostgreSQL (192.168.11.105:5432)
  - Verify authentication works
  - Test database queries

- [ ] **Task 6.2**: Test API services
  - Test API Primary health endpoint
  - Test API Secondary health endpoint
  - Test API functionality (CRUD operations, etc.)
  - Verify database operations work

- [ ] **Task 6.3**: Test Frontend → API connectivity
  - Test frontend can reach API Primary
  - Test API responses are correct
  - Verify end-to-end request flow

- [ ] **Task 6.4**: Load balancing / High Availability (if configured)
  - Test failover scenarios
  - Verify load distribution
  - Test health checks

- [ ] **Task 6.5**: Monitoring and logging
  - Verify all services are logging correctly
  - Set up monitoring/alerts (optional)
  - Verify log aggregation (if applicable)

---

## Priority 5: Documentation & Maintenance

### Documentation Updates

- [ ] **Task 7.1**: Update deployment documentation
  - Document PostgreSQL installation steps
  - Document API deployment steps
  - Update IP addresses in all documentation
  - Document service startup procedures

- [ ] **Task 7.2**: Update configuration documentation
  - Document all configuration files
  - Document environment variables
  - Document service dependencies

- [ ] **Task 7.3**: Create runbooks
  - Service startup procedures
  - Troubleshooting guide
  - Backup/restore procedures

---

## Task Summary by Service

### PostgreSQL Primary (10100)
- **Total Tasks**: 7 tasks
- **Status**: 0/7 completed
- **Priority**: 🔴 Critical (blocks API services)

### PostgreSQL Replica (10101)
- **Total Tasks**: 4 tasks
- **Status**: 0/4 completed
- **Priority**: 🟡 Medium (optional, can be deferred)

### API Primary (10150)
- **Total Tasks**: 7 tasks
- **Status**: 0/7 completed (config updated separately)
- **Priority**: 🔴 Critical

### API Secondary (10151)
- **Total Tasks**: 7 tasks
- **Status**: 0/7 completed (config updated separately)
- **Priority**: 🔴 Critical (for HA)

### Frontend/Nginx (10130)
- **Total Tasks**: 4 tasks (mostly verification)
- **Status**: 1/4 completed (config updated)
- **Priority**: 🟢 Low (mostly verification)

### Integration & Testing
- **Total Tasks**: 5 tasks
- **Status**: 0/5 completed
- **Priority**: 🟡 Medium (after services are running)

### Documentation
- **Total Tasks**: 3 tasks
- **Status**: 0/3 completed
- **Priority**: 🟢 Low

---

## Recommended Task Order

### Phase 1: Foundation (Critical Path)
1. PostgreSQL Primary installation and configuration (Tasks 1.1 - 1.7)
2. Database setup (Task 1.4, 1.7)

### Phase 2: Application Layer
3. API Primary installation and deployment (Tasks 3.1 - 3.7)
4. API Secondary installation and deployment (Tasks 4.1 - 4.7)

### Phase 3: Verification
5. Frontend verification (Tasks 5.1 - 5.4)
6. End-to-end testing (Tasks 6.1 - 6.5)

### Phase 4: Optional
7. PostgreSQL Replica (Tasks 2.1 - 2.4) - if needed
8. Documentation updates (Tasks 7.1 - 7.3)

---

## Estimated Effort

- **PostgreSQL Primary**: 2-4 hours
- **PostgreSQL Replica**: 1-2 hours (optional)
- **API Primary**: 2-3 hours
- **API Secondary**: 1-2 hours (after primary)
- **Frontend Verification**: 30 minutes
- **Testing**: 1-2 hours
- **Documentation**: 1-2 hours

**Total Estimated Time**: 8-16 hours (excluding optional replica)

---

## Dependencies

```
PostgreSQL Primary (10100)
  └── API Primary (10150) ──┐
  └── API Secondary (10151) ─┼── Frontend (10130)
                             │
PostgreSQL Replica (10101) ──┘ (optional)
```

---

**Last Updated**: 2026-01-02  
**Status**: ⏳ **TASKS DEFINED** - Ready for implementation
