Skip to content

Production Setup

This guide walks through deploying Dharini on AWS infrastructure for production use.

  • AWS Account with appropriate permissions
  • Domain name for your deployment
  • SSH key pair for EC2 access
  1. Go to AWS RDS Console

  2. Click Create database

  3. Choose the following settings:

    • Engine: PostgreSQL 16.x
    • Template: Production
    • DB instance identifier: dharini-prod-db
    • Master username: postgres (or your choice)
    • Master password: Set a strong password
    • Instance class: db.t3.micro (or larger based on needs)
    • Storage: 20 GB GP3
    • Enable storage autoscaling: Yes
    • Multi-AZ: Optional (recommended for high availability)
  4. Connectivity:

    • VPC: Choose your VPC
    • Public access: No (unless needed)
    • VPC security group: Create new or use existing
    • Availability Zone: No preference
  5. Additional configuration:

    • Initial database name: postgres
    • Enable automated backups: Yes
    • Backup retention: 7 days (or more)
    • Enable encryption: Yes
  6. Click Create database

Add inbound rule to the RDS security group:

  • Type: PostgreSQL
  • Port: 5432
  • Source: Your EC2 instance’s security group or private IP

Connect to your RDS instance:

Terminal window
psql -h dharini-prod-db.xxxxxxxxx.region.rds.amazonaws.com -U postgres -d postgres

Run the following SQL:

CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
  1. Go to AWS S3 Console

  2. Click Create bucket

  3. Configure:

    • Bucket name: dharini-prod-storage (must be globally unique)
    • Region: Same as your EC2 instance
    • Block Public Access: Enable (keep bucket private)
    • Versioning: Optional
    • Encryption: Enable (SSE-S3 or SSE-KMS)
  4. Create IAM user with S3 access:

    • Go to IAM Console
    • Create user dharini-s3-access
    • Attach policy with S3 bucket access
    • Generate access keys
    • Save Access Key ID and Secret Access Key
  1. Go to EC2 Console
  2. Click Launch Instance
  3. Configure:
    • Name: dharini-prod
    • AMI: Ubuntu Server 24.04 LTS
    • Instance type: t3.medium (or larger)
    • Key pair: Select or create new
    • VPC: Same VPC as RDS
    • Security group: Create new with rules below

Add the following inbound rules:

TypePortSourceDescription
SSH22Your IPSSH access
HTTP800.0.0.0/0Web traffic
HTTPS4430.0.0.0/0Secure web

SSH into your EC2 instance:

Terminal window
ssh -i your-key.pem ubuntu@your-ec2-ip

Install Docker:

Terminal window
# Update package index
sudo apt-get update
# Install prerequisites
sudo apt-get install -y ca-certificates curl gnupg lsb-release
# Add Docker's official GPG key
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Set up the repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Update package index again
sudo apt-get update
# Install Docker Engine and plugins
sudo apt-get install -y docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin
# Add ubuntu user to docker group
sudo usermod -aG docker ubuntu
# Enable and start Docker
sudo systemctl enable docker
sudo systemctl start docker

Log out and back in for group changes to take effect:

Terminal window
exit
ssh -i your-key.pem ubuntu@your-ec2-ip

Verify Docker installation:

Terminal window
docker --version
docker compose version
Terminal window
git clone https://github.com/dsih-artpark/dharini.git
cd dharini

Create a .env file in the repository root. See Environment Variables for complete reference.

Minimum required configuration:

Terminal window
# Application
NODE_ENV=production
PORT=4000
# Database - RDS
DB_HOST=dharini-prod-db.xxxxxxxxx.region.rds.amazonaws.com
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=your-rds-password
DB_DATABASE=postgres
# Redis (Docker)
REDIS_HOST=redis
REDIS_PORT=6379
# AWS S3
S3_REGION=ap-south-1
S3_BUCKET=dharini-prod-storage
S3_ACCESSKEYID=your-access-key-id
S3_SECRETACCESSKEY=your-secret-access-key
S3_ENDPOINT=https://s3.ap-south-1.amazonaws.com
S3_FOLDER=dharini-prod
# Security
JWT_SECRET=generate-a-strong-random-secret
# Email (optional - configure based on provider)
SENDGRID_API_KEY=
GMAIL_USER=
GMAIL_PASS=
EMAIL_FROM=
# Frontend
NEXT_PUBLIC_API_URL=https://your-domain.com/api
NEXT_PUBLIC_APP_ENV=production
Terminal window
docker compose --profile production up -d --build

Check service status:

Terminal window
docker ps

You should see:

  • backend (running)
  • frontend (running)
  • apk-server (running)
  • redis (running)
Terminal window
docker exec -it backend npm run migration:run

Verify tables were created:

Terminal window
PGSSLMODE=require psql -h your-rds-endpoint -U postgres -d postgres -c "\dt"

Install Nginx:

Terminal window
sudo apt-get install -y nginx

Create Nginx configuration. See Nginx Configuration for complete setup.

Install Certbot:

Terminal window
sudo apt-get install -y certbot python3-certbot-nginx

Generate SSL certificate:

Terminal window
sudo certbot --nginx -d your-domain.com

Follow the prompts to complete SSL setup.

Point your domain to your EC2 instance:

  1. Go to your DNS provider
  2. Add an A record:
    • Name: @ (or subdomain like in)
    • Type: A
    • Value: Your EC2 public IP
    • TTL: 300
  1. Visit https://your-domain.com - should load the frontend
  2. Visit https://your-domain.com/api/docs - should load API documentation
  3. Check logs for errors:
Terminal window
docker logs backend -f
docker logs frontend -f
  • Set up monitoring (CloudWatch, Datadog, etc.)
  • Configure automated backups
  • Set up log aggregation
  • Create admin user account
  • Test all functionality