# 🚀 Easy Installation Feature Guide

## Overview

Trust Tax Advisor now includes a **complete easy installation system** with three powerful tools to get you up and running in minutes:

1. **Interactive Installer** (`install.js`) - Guided setup wizard
2. **Easy Install Script** (`easy-install.sh` / `easy-install.bat`) - Automated installation
3. **Requirements Checker** (`check-requirements.js`) - System verification

---

## ⚡ Quick Start (Choose One)

### Option 1: Super Easy (Automatic Setup)

**Windows:**
```bash
easy-install.bat
```

**Linux/Mac:**
```bash
bash easy-install.sh
```

This will automatically:
- ✅ Check system requirements
- ✅ Install all dependencies (npm install)
- ✅ Create configuration files
- ✅ Display next steps

### Option 2: Interactive Wizard (Guided Setup)

```bash
node install.js
```

This walks you through:
- 🔍 System requirements verification
- 📝 Installation type selection (full/backend/frontend)
- ⚙️ Backend configuration (database, email, WhatsApp)
- 🎨 Frontend configuration (API endpoint)
- 🗄️ Optional database setup
- ✨ Automatic port checking

### Option 3: Manual Check + Setup

```bash
# 1. Check if your system is ready
node check-requirements.js

# 2. Then run installation script
easy-install.sh    # or easy-install.bat
```

---

## 📋 What Each Tool Does

### 1. Interactive Installer (`install.js`)

**Purpose**: Guided installation with interactive prompts

**Features:**
- Interactive command-line wizard
- Step-by-step configuration
- Colored terminal output
- Input validation
- Automatic npm install
- Optional database setup
- Pre-generated secrets & keys

**When to use:**
- ✅ First-time setup
- ✅ New developers joining team
- ✅ Want to review each configuration
- ✅ Need customized setup

**Usage:**
```bash
node install.js
```

**What it configures:**
```
Backend Configuration:
  ✓ Port (default: 5000)
  ✓ Environment (dev/prod)
  ✓ Database credentials
  ✓ JWT secret
  ✓ WhatsApp API keys
  ✓ Email SMTP settings

Frontend Configuration:
  ✓ API endpoint
  ✓ Environment settings

Database Setup:
  ✓ MySQL connection test
  ✓ Schema import
```

### 2. Easy Install Script (`easy-install.sh` / `easy-install.bat`)

**Purpose**: Automated installation for quick setup

**Features:**
- Non-interactive (perfect for CI/CD)
- Colored output for clarity
- Directory verification
- Automatic dependency installation
- .env file generation from examples
- No configuration prompts (uses defaults)

**When to use:**
- ✅ Development environment setup
- ✅ Docker/container builds
- ✅ CI/CD pipelines
- ✅ Team onboarding (quick setup)
- ✅ Don't have time for questions

**Usage:**
```bash
# Windows
easy-install.bat

# Linux/Mac
bash easy-install.sh
```

**What it does:**
```
1. Verify Node.js & npm installed
2. Check backend dir structure
3. Check frontend dir structure
4. Check database dir structure
5. npm install backend dependencies
6. npm install frontend dependencies
7. Copy .env.example to .env
8. Display next steps
```

### 3. Requirements Checker (`check-requirements.js`)

**Purpose**: Verify system is ready before installing

**Features:**
- Checks Node.js version
- Checks npm version
- Verifies project directories
- Tests port availability (3000, 5000)
- Optional MySQL CLI check
- Color-coded results
- Helpful error messages

**When to use:**
- ✅ Before any installation
- ✅ Troubleshooting setup issues
- ✅ Verify environment is correct
- ✅ Check port conflicts

**Usage:**
```bash
node check-requirements.js
```

**Output example:**
```
Required Commands:
✓ Node.js: v18.16.0
✓ npm: 9.6.7

Project Directories:
✓ Backend directory: Found (45 files)
✓ Frontend directory: Found (38 files)
✓ Database directory: Found (2 files)

Port Availability:
✓ Port 5000: Available (Backend)
✓ Port 3000: Available (Frontend)

All checks passed! Ready to proceed.
```

---

## 🎯 Installation Flowchart

```
START
  ↓
[Check Requirements]
  ↓ (All good?)
  ├─→ [node install.js]     ← Interactive Wizard
  │     ↓
  │   Configure backend (.env)
  │   Configure frontend (.env)
  │   Setup database (optional)
  │     ↓
  │   READY ✓
  │
  ├─→ [easy-install.sh/.bat]  ← Automatic
  │     ↓
  │   Auto-install dependencies
  │   Auto-create .env files
  │     ↓
  │   READY ✓ (needs manual .env editing)
  │
  └─→ [Manual]
        ↓
      cd backend && npm install
      cd frontend && npm install
      (Edit .env files manually)
        ↓
      READY ✓

After Installation:
  ↓
[Configure .env files]
[Setup Database Schema]
[Start Backend: npm start]
[Start Frontend: npm run dev]
  ↓
RUNNING ON:
  Frontend: http://localhost:3000
  Backend: http://localhost:5000
```

---

## 📄 Configuration Files Generated

### Backend `.backend/.env`

These are the main configuration options:

```env
# Server
PORT=5000                          # Backend port
NODE_ENV=development               # dev or production

# Database
DB_HOST=localhost                  # MySQL host
DB_PORT=3306                       # MySQL port
DB_USER=root                       # MySQL user
DB_PASSWORD=                       # MySQL password
DB_NAME=trust_tax_advisor          # Database name

# Authentication
JWT_SECRET=<random-secret>         # JWT signing key
JWT_EXPIRY=7d                      # Token expiration

# CORS
CORS_ORIGIN=http://localhost:3000  # Frontend origin

# Twilio (WhatsApp)
TWILIO_ACCOUNT_SID=                # Get from Twilio
TWILIO_AUTH_TOKEN=                 # Get from Twilio
TWILIO_PHONE_NUMBER=               # WhatsApp number

# Email (SMTP)
SMTP_HOST=smtp.gmail.com           # SMTP server
SMTP_PORT=587                      # SMTP port
SMTP_USER=your@email.com           # Email user
SMTP_PASS=your-app-password        # Email password
SMTP_FROM=noreply@taxadvisor.com   # From address
```

### Frontend `.frontend/.env`

```env
VITE_API_URL=http://localhost:5000   # Backend API URL
```

---

## 🔧 Advanced Configuration

### For Production Deployment

After easy installation, for production:

1. **Update backend/.env:**
   ```env
   NODE_ENV=production
   CORS_ORIGIN=https://yourdomain.com
   DB_HOST=your-prod-db-host
   JWT_EXPIRY=7d
   ```

2. **Update frontend/.env.production:**
   ```env
   VITE_API_URL=https://api.yourdomain.com
   ```

3. **Build frontend:**
   ```bash
   cd frontend
   npm run build
   ```

4. **Deploy to cPanel:**
   - Follow `CPANEL_DEPLOYMENT.md`
   - Use production config files
   - Enable SSL/HTTPS

### For Docker/Container

Use the easy-install scripts in your Dockerfile:

```dockerfile
FROM node:18

WORKDIR /app
COPY . .

# Run easy installation (non-interactive)
RUN bash easy-install.sh

# Set production environment
ENV NODE_ENV=production

CMD ["npm", "start", "--prefix", "backend"]
```

### For CI/CD Pipeline

```yaml
# Example GitHub Actions
- name: Easy Install
  run: bash easy-install.sh

- name: Build Frontend
  run: cd frontend && npm run build

- name: Run Tests
  run: npm test
```

---

## 🐛 Troubleshooting

### Issue: "Node.js not found"
**Solution:**
- Install Node.js from https://nodejs.org/
- Restart terminal after installation
- Run `node --version` to verify

### Issue: "npm install fails"
**Solution:**
```bash
# Clear npm cache
npm cache clean --force

# Remove package-lock.json and node_modules
rm -rf node_modules package-lock.json

# Try again
npm install --legacy-peer-deps
```

### Issue: "Port 3000/5000 already in use"
**Solution:**
```bash
# Find process using port
lsof -i :3000          # Linux/Mac
netstat -ano | findstr :3000  # Windows

# Kill process or change port in .env
# Backend: change PORT in .env
# Frontend: change in vite.config.js
```

### Issue: "Database connection failed"
**Solution:**
```bash
# Verify MySQL is running
mysql -u root -p

# Check credentials in .env
# Create database if not exists
CREATE DATABASE trust_tax_advisor;

# Import schema
mysql -u root -p trust_tax_advisor < database/schema.sql
```

### Issue: "install.js fails"
**Solution:**
```bash
# Check Node.js version Requirements: 14.0+
node --version

# Check file permissions
chmod +x install.js

# Run with explicit node
node install.js --verbose
```

---

## ✅ Post-Installation Checklist

After running easy installation, verify:

- [ ] Backend dependencies installed (`backend/node_modules` exists)
- [ ] Frontend dependencies installed (`frontend/node_modules` exists)
- [ ] `.env` files created (backend and frontend)
- [ ] Database credentials are correct in backend/.env
- [ ] CORS_ORIGIN matches frontend URL
- [ ] All required ports (3000, 5000) are available
- [ ] MySQL server is running
- [ ] Database schema imported (`trust_tax_advisor` database created)

---

## 🚀 Next Steps After Installation

### 1. Configure Integrations

**WhatsApp OTP Setup:**
```bash
# Edit backend/.env
TWILIO_ACCOUNT_SID=your_sid
TWILIO_AUTH_TOKEN=your_token
TWILIO_PHONE_NUMBER=+1234567890

# See WHATSAPP_SETUP.md for details
```

**Email SMTP Setup:**
```bash
# Edit backend/.env
SMTP_HOST=smtp.gmail.com
SMTP_USER=your@gmail.com
SMTP_PASS=your-app-password

# See SMTP_SETUP.md for details
```

### 2. Start Development

```bash
# Terminal 1: Backend
cd backend
npm start

# Terminal 2: Frontend
cd frontend
npm run dev

# Access at http://localhost:3000
```

### 3. Test Login

- Email: `admin@trusttaxadvisor.com`
- OTP: Check console logs or email

### 4. Explore Dashboard

- Client Panel
- Connector/Agent Panel
- Admin Dashboard
- Staff Panel

---

## 🎓 Installation for Different Scenarios

### Scenario 1: Solo Developer (First Setup)

```bash
# Check system
node check-requirements.js

# Interactive setup
node install.js

# Edit configs as prompted
# Start dev servers
cd backend && npm start
```

### Scenario 2: Team Onboarding (New Developer)

```bash
# Just run automatic setup
bash easy-install.sh  # or .bat on Windows

# They'll review pre-created configs
# Ask for API keys if needed
npm start
```

### Scenario 3: Fresh Clone (After GitHub Pull)

```bash
# Already have .env files
bash easy-install.sh

# Just installs node_modules and verifies setup
```

### Scenario 4: Production Deployment

```bash
# Use non-interactive setup
bash easy-install.sh

# Configure for production
# .env updated with prod values
# Database imported to prod server
npm start (with PM2 or supervisor)
```

### Scenario 5: Docker/Container

```dockerfile
RUN bash easy-install.sh
ENV NODE_ENV=production
CMD ["node", "backend/server.js"]
```

---

## 📊 Installation Speed Summary

| Method | Speed | Configuration | Best For |
|--------|-------|---------------|----------|
| `easy-install.sh` | ⚡ 2-5 min | Automatic | Quick setup |
| `install.js` | 🚀 5-10 min | Interactive | Full control |
| Manual | 🐢 15-30 min | Complete | Learning |

---

## 🎉 Congratulations!

You now have multiple ways to install the Trust Tax Advisor platform:

✅ **For quick setup:** `easy-install.sh` or `easy-install.bat`
✅ **For guided setup:** `node install.js`
✅ **For verification:** `node check-requirements.js`

Choose the method that suits your workflow and get started! 🚀

---

## 📞 Still Need Help?

- Check **README.md** for full documentation
- See **CPANEL_DEPLOYMENT.md** for production setup
- Read **SMTP_SETUP.md** for email configuration
- Follow **WHATSAPP_SETUP.md** for WhatsApp OTP
- Review **PRODUCTION_CHECKLIST.md** before going live

**Happy installation! 🎊**

---

**Generated:** March 2026
**Version:** 1.0.0
**Status:** ✅ Production Ready
