# Goa GEL Backend **Blockchain Document Verification Platform for Government of Goa** A production-ready NestJS backend for managing multi-department approval workflows with blockchain-backed verification using Hyperledger Besu and ERC-721 Soulbound NFTs. ## ๐Ÿš€ Quick Start ### Prerequisites - Node.js 18+ - Docker & Docker Compose - PostgreSQL 15+ (or use Docker) - Redis 7+ (or use Docker) ### Installation ```bash # Clone and install cd backend npm install # Copy environment file cp .env.example .env # Start infrastructure (PostgreSQL, Redis, MinIO, Besu) docker-compose up -d postgres redis minio besu-node-1 # Run migrations npm run migrate:latest # Seed sample data npm run seed:run # Start development server npm run start:dev ``` ### Access Points | Service | URL | Description | |---------|-----|-------------| | API | http://localhost:3001 | REST API | | Swagger Docs | http://localhost:3001/api/docs | API Documentation | | Health Check | http://localhost:3001/health | Service Health | | MinIO Console | http://localhost:9001 | Object Storage UI | | Besu RPC | http://localhost:8545 | Blockchain RPC | ## ๐Ÿ“ Project Structure ``` backend/ โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ main.ts # Application entry point โ”‚ โ”œโ”€โ”€ app.module.ts # Root module โ”‚ โ”œโ”€โ”€ config/ # Configuration files โ”‚ โ”‚ โ”œโ”€โ”€ app.config.ts โ”‚ โ”‚ โ”œโ”€โ”€ database.config.ts โ”‚ โ”‚ โ”œโ”€โ”€ blockchain.config.ts โ”‚ โ”‚ โ”œโ”€โ”€ storage.config.ts โ”‚ โ”‚ โ””โ”€โ”€ redis.config.ts โ”‚ โ”œโ”€โ”€ common/ # Shared utilities โ”‚ โ”‚ โ”œโ”€โ”€ constants/ โ”‚ โ”‚ โ”œโ”€โ”€ decorators/ โ”‚ โ”‚ โ”œโ”€โ”€ enums/ โ”‚ โ”‚ โ”œโ”€โ”€ filters/ โ”‚ โ”‚ โ”œโ”€โ”€ guards/ โ”‚ โ”‚ โ”œโ”€โ”€ interceptors/ โ”‚ โ”‚ โ”œโ”€โ”€ interfaces/ โ”‚ โ”‚ โ”œโ”€โ”€ pipes/ โ”‚ โ”‚ โ””โ”€โ”€ utils/ โ”‚ โ”œโ”€โ”€ database/ # Database layer (Knex + Objection.js) โ”‚ โ”‚ โ”œโ”€โ”€ models/ # Objection.js models โ”‚ โ”‚ โ”œโ”€โ”€ migrations/ # Knex migrations โ”‚ โ”‚ โ”œโ”€โ”€ seeds/ # Seed data โ”‚ โ”‚ โ””โ”€โ”€ knexfile.ts โ”‚ โ””โ”€โ”€ modules/ # Feature modules โ”‚ โ”œโ”€โ”€ auth/ # Authentication โ”‚ โ”œโ”€โ”€ applicants/ # Applicant management โ”‚ โ”œโ”€โ”€ departments/ # Department management โ”‚ โ”œโ”€โ”€ requests/ # License requests โ”‚ โ”œโ”€โ”€ documents/ # Document management โ”‚ โ”œโ”€โ”€ approvals/ # Approval workflow โ”‚ โ”œโ”€โ”€ workflows/ # Workflow engine โ”‚ โ”œโ”€โ”€ webhooks/ # Webhook delivery โ”‚ โ”œโ”€โ”€ blockchain/ # Blockchain integration โ”‚ โ”œโ”€โ”€ admin/ # Admin operations โ”‚ โ””โ”€โ”€ audit/ # Audit logging โ”œโ”€โ”€ test/ # Test suites โ”œโ”€โ”€ docker-compose.yml # Docker services โ”œโ”€โ”€ Dockerfile # Production image โ””โ”€โ”€ package.json ``` ## ๐Ÿ”ง Configuration ### Environment Variables ```bash # Application NODE_ENV=development PORT=3001 API_VERSION=v1 # Database (PostgreSQL) DATABASE_HOST=localhost DATABASE_PORT=5432 DATABASE_NAME=goa_gel_platform DATABASE_USER=postgres DATABASE_PASSWORD=your_password # Blockchain (Hyperledger Besu) BESU_RPC_URL=http://localhost:8545 BESU_CHAIN_ID=1337 CONTRACT_ADDRESS_LICENSE_NFT=0x... PLATFORM_WALLET_PRIVATE_KEY=0x... # Storage (MinIO) MINIO_ENDPOINT=localhost MINIO_PORT=9000 MINIO_ACCESS_KEY=minioadmin MINIO_SECRET_KEY=minioadmin # Redis REDIS_HOST=localhost REDIS_PORT=6379 # Security JWT_SECRET=your-32-char-secret-key ``` ## ๐Ÿ“š API Documentation ### Authentication **Department Login:** ```bash curl -X POST http://localhost:3001/api/v1/auth/department/login \ -H "Content-Type: application/json" \ -d '{"apiKey": "fire_api_key_123", "departmentCode": "FIRE_DEPT"}' ``` **DigiLocker Login (Mock):** ```bash curl -X POST http://localhost:3001/api/v1/auth/digilocker/login \ -H "Content-Type: application/json" \ -d '{"digilockerId": "DL-GOA-123456789", "name": "John Doe", "email": "john@example.com"}' ``` ### Core Endpoints | Method | Endpoint | Description | |--------|----------|-------------| | POST | `/api/v1/requests` | Create license request | | POST | `/api/v1/requests/:id/submit` | Submit for approval | | GET | `/api/v1/requests/:id` | Get request details | | GET | `/api/v1/requests/pending` | Get pending requests | | POST | `/api/v1/requests/:id/documents` | Upload document | | POST | `/api/v1/requests/:id/approve` | Approve request | | POST | `/api/v1/requests/:id/reject` | Reject request | | GET | `/api/v1/workflows` | List workflows | | POST | `/api/v1/webhooks` | Register webhook | ## ๐Ÿ—„๏ธ Database ### Using Knex Migrations ```bash # Create new migration npm run migrate:make -- create_new_table # Run migrations npm run migrate:latest # Rollback last migration npm run migrate:rollback # Check migration status npm run migrate:status # Run seeds npm run seed:run ``` ### Models (Objection.js) - `Applicant` - User profiles linked to DigiLocker - `Department` - Government departments with API keys - `LicenseRequest` - License/permit applications - `Document` - Uploaded documents with versioning - `Approval` - Department approval records - `Workflow` - Approval workflow definitions - `WorkflowState` - Workflow execution state - `Webhook` - Webhook configurations - `AuditLog` - Immutable audit trail - `BlockchainTransaction` - Blockchain transaction records ## ๐Ÿ”— Blockchain Integration ### Smart Contracts | Contract | Purpose | |----------|---------| | LicenseRequestNFT | ERC-721 Soulbound NFTs for licenses | | ApprovalManager | Records approvals on-chain | | DepartmentRegistry | Department registration | | WorkflowRegistry | Workflow definitions | ### Transaction Flow 1. Request created โ†’ Draft NFT minted 2. Document uploaded โ†’ Hash recorded on-chain 3. Department approves โ†’ Approval recorded on-chain 4. All approvals complete โ†’ NFT finalized ## ๐Ÿงช Testing ```bash # Run unit tests npm test # Run with coverage npm run test:cov # Run e2e tests npm run test:e2e # Watch mode npm run test:watch ``` ## ๐Ÿณ Docker Deployment ### Development ```bash # Start all services docker-compose up -d # View logs docker-compose logs -f api # Stop services docker-compose down ``` ### Production ```bash # Build production image docker build -t goa-gel-api:latest . # Run with production compose docker-compose -f docker-compose.prod.yml up -d ``` ## ๐Ÿ“Š Monitoring ### Health Check ```bash curl http://localhost:3001/health ``` Response: ```json { "status": "ok", "timestamp": "2024-01-15T10:30:00.000Z", "uptime": 3600, "checks": { "database": "ok", "redis": "ok", "blockchain": "ok", "storage": "ok" } } ``` ## ๐Ÿ” Security - API Key authentication for departments - JWT tokens for applicants - RBAC (Role-Based Access Control) - Rate limiting (100 req/min global) - Input validation with class-validator - SQL injection prevention (parameterized queries) - Helmet security headers - CORS configuration ## ๐Ÿ“ License Proprietary - Government of Goa ## ๐Ÿค Support For technical support, contact: support@goagel.gov.in