Backend Installation
1. Installing the Backend (Self-Hosted, Dockerized NestJS)
Section titled “1. Installing the Backend (Self-Hosted, Dockerized NestJS)”1.1 Prerequisites
Section titled “1.1 Prerequisites”Before starting, ensure you have:
- Server: Ubuntu 22.04+ (minimum 2 vCPU, 4 GB RAM)
- Docker: v24+
- Docker Compose: v2+
- Git: v2.30+
- Domain Name: For API access (
api.irannation.example.com) - SSL Certificates: Managed via Let’s Encrypt or Cloudflare SSL
1.2 Clone the Repository
Section titled “1.2 Clone the Repository”git clone https://github.com/IranNetworkState/backend-v2.gitcd irannation-backend1.3 Environment Configuration
Section titled “1.3 Environment Configuration”Create a .env file in the root directory with the following environment variables:
# Database Configuration (MySQL)DB_NAME=iran_nationDB_USER=non-root-userDB_PASSWORD="randompassword"MYSQL_ROOT_PASSWORD=rootpassword
# Application ConfigurationNODE_ENV=productionPORT=3000SESSION_SECRET=your-super-secret-key-change-in-production
# Frontend ConfigurationFRONTEND_URL=https://your-frontend-domain.com
# Stripe ConfigurationSTRIPE_SECRET_KEY=secret_keySTRIPE_PUBLISHABLE_KEY=publishable_keySTRIPE_WEBHOOK_SECRET=whsec_xxx
# Firebase ConfigurationFIREBASE_PROJECT_ID=your_firebase_project_idFIREBASE_PRIVATE_KEY=your_firebase_private_keyFIREBASE_CLIENT_EMAIL=your_firebase_client_email
# Email Configuration (Resend)RESEND_SECRET=resend_secretFROM_EMAIL="email@mvpurr.com"
# AWS ConfigurationAWS_REGION=us-east-1AWS_ACCESS_KEY_ID=access_keyAWS_SECRET_ACCESS_KEY=secret_access_keyAWS_BUCKET_NAME=persia-net
# MonitoringSENTRY_DSN=https://123.ingest.us.sentry.io/456⚠️ Security Note: The above values are examples. Replace them with your actual production values and never commit sensitive credentials to version control.
1.4 Firebase Credentials Setup
Section titled “1.4 Firebase Credentials Setup”Place your Firebase service account credentials file as firebase-credentials.json in the project root directory. This file will be mounted into the container for Firebase authentication.
1.5 Running the Application
Section titled “1.5 Running the Application”The application uses Docker Compose with multiple services and can be run using the provided Docker scripts:
Architecture Overview
Section titled “Architecture Overview”The application consists of:
- MySQL 8.0: Primary database (exposed on port 3307)
- Redis 7: Queue management with BullMQ (exposed on port 6380)
- NestJS Backend: Main application (exposed on port 3001)
- Adminer: Database administration tool (exposed on port 8080)
Development Environment
Section titled “Development Environment”sh docker-dev.shThis will:
- Build the development Docker image
- Start all services (MySQL, Redis, NestJS app, Adminer)
- Enable hot-reload for development
- Mount local directories for uploads and logs
- Expose services on development ports
Production Environment
Section titled “Production Environment”sh docker-prod.shThis will:
- Build the optimized production Docker image
- Start all services with production configurations
- Apply production optimizations and security settings
- Set up proper health checks and restart policies
1.6 Service Access & Verification
Section titled “1.6 Service Access & Verification”After running either script, verify the installation by accessing these services:
Service Endpoints
Section titled “Service Endpoints”| Service | URL | Purpose |
|---|---|---|
| NestJS API | http://localhost:3001 | Main application API |
| API Health Check | http://localhost:3001/health | Service health status |
| API Documentation | http://localhost:3001/api | Swagger/OpenAPI docs |
| Database Admin | http://localhost:3001/adminer | Adminer database interface |
Verification Steps
Section titled “Verification Steps”- Health Check: Visit
http://localhost:3001/healthto ensure all services are running - API Documentation: Access Swagger docs at
http://localhost:3001/api - Database Admin: Use Adminer at
http://localhost:8080to verify database connection- Server:
mysql - Username: Your
DB_USERfrom .env - Password: Your
DB_PASSWORDfrom .env - Database: Your
DB_NAMEfrom .env
- Server:
- Container Status: Run
docker-compose psto check all containers are healthy - Logs: Check service logs with
docker-compose logs backendfor any errors
1.7 Post-Installation
Section titled “1.7 Post-Installation”- SSL Setup: Configure SSL certificates for production domains
- Monitoring: Verify Sentry integration for error tracking
- Queue Monitoring: Check Redis for BullMQ job processing
- Firewall: Configure firewall rules to restrict access to database ports (3307, 6380, 8080) in production