# IGF-EMS Staging Setup Context for LLM

## 🎯 PRIMARY AGENDA

You (LLM) are helping set up a **staging environment with CI/CD** for an existing production system.

### Key Requirements:
- DO NOT break or modify the existing production environment
- Replicate production behavior as closely as possible
- Introduce staging as a **parallel environment**
- Ensure architecture is scalable for future CI/CD on production

---

## 🧠 CURRENT PRODUCTION SYSTEM

### Infrastructure:
- AWS EC2 (Ubuntu)
- Apache (reverse proxy)
- PM2 (process manager)
- Node.js backend

### Production Details:
- Domain: erp.igfdigital.com
- Folder: /var/www/html/IGF-EMS
- Branch: feat/new/photo-tool
- Port: 3000
- PM2 Process: igf-backend

### Flow:
erp.igfdigital.com → Apache → localhost:3000 → PM2 → Node app

---

## 🚧 CURRENT DEPLOYMENT (MANUAL)

Workflow:
1. Push to feat/new/photo-tool
2. SSH into server
3. git pull
4. npm install
5. pm2 restart

⚠️ Directly impacts production (no isolation)

---

## 🎯 TARGET: STAGING ENVIRONMENT

### Requirements:
- Domain: staging-ems.igfdigital.com
- Branch: staging
- Port: 3001
- PM2 Process: igf-backend-staging
- Folder: /var/www/html/IGF-EMS-STAGING

### Flow:
staging-ems.igfdigital.com → Apache → localhost:3001 → PM2 → Node app

---

## 📁 FOLDER STRATEGY

Each environment must have a separate folder:

/var/www/html/
├── IGF-EMS (production)
└── IGF-EMS-STAGING (staging)

Both folders:
- Point to same GitHub repo
- Use different branches
- Run separate PM2 processes

---

## 🔀 GIT STRATEGY

Repo: git@github.com:seedion/igf-ems.git

Branches:
- feat/new/photo-tool → production
- staging → staging

---

## ⚙️ CURRENT PROGRESS

✔ Repo cloned to IGF-EMS-STAGING  
✔ Switched to staging branch  
✔ Installed dependencies using:
  npm install --legacy-peer-deps  

---

## ❗ CRITICAL UNKNOWN (NEEDS ANALYSIS)

Project structure is unclear.

Determine:

1. Is this a monorepo?
   - Root-level package.json controlling everything?

2. Or split structure?
   - dashboard (backend)
   - client/frontend

3. Where should dependencies be installed?
   - root?
   - dashboard?
   - both?

4. Is a frontend build required?
   - npm run build?

---

## 🚀 NEXT STEPS (FOR LLM TO GUIDE)

1. Analyze project structure
2. Identify correct install locations
3. Run staging app on port 3001
4. Start PM2 process (igf-backend-staging)
5. Configure Apache VirtualHost
6. Enable SSL
7. Set up CI/CD pipeline (GitHub Actions)

---

## ⚠️ HARD CONSTRAINTS

- DO NOT modify IGF-EMS (production folder)
- DO NOT stop existing PM2 processes
- DO NOT reuse port 3000
- DO NOT break existing domains

---

## 🧠 DESIGN PRINCIPLES

- Environment = isolated runtime
- Folder = environment (in this architecture)
- Same repo, different folders is valid
- CI/CD replaces manual deployment

---

## 🔮 FUTURE PLAN

- Add CI/CD for staging first
- Later extend CI/CD to production (main branch)
- Move away from manual SSH deployment
- Possibly evolve to Docker

---

## 🧩 SUMMARY

Goal: Build a safe, isolated staging environment that mirrors production and introduces CI/CD capabilities without impacting live users.
