# Deploying MakeLeads.us on Namecheap Hosting

## Option 1: Shared Hosting (cPanel + Node.js App)

Namecheap shared hosting supports Node.js apps via cPanel. This is the easiest and cheapest option.

### Requirements
- Namecheap **Stellar Business** or higher shared hosting plan (Node.js support)
- A domain pointed to Namecheap nameservers

### Step-by-Step

1. **Log into cPanel**
   Go to your Namecheap dashboard → Hosting List → Manage → cPanel

2. **Create the Node.js App**
   - In cPanel, scroll to SOFTWARE → "Setup Node.js App"
   - Click **CREATE APPLICATION**
   - Node.js version: **18.x** or higher
   - Application mode: **Production**
   - Application root: `makeleads` (or your preferred folder name)
   - Application URL: select your domain (e.g., `makeleads.us`)
   - Application startup file: `server.js`

3. **Upload Files**
   - In cPanel → File Manager, navigate to the application root folder
   - Upload the `makeleads.zip` file
   - Extract it so the files are directly in the app root:
     ```
     makeleads/
       server.js
       package.json
       public/
       server/
       data/
     ```

4. **Set Environment Variables**
   Back in Setup Node.js App, add these environment variables:
   - `JWT_SECRET` = (a random secure string, e.g., `mL-s3cr3t-k3y-2026!`)
   - `PORT` = (leave blank, cPanel handles this)
   - `SENDGRID_API_KEY` = (your SendGrid API key, starts with `SG.`)
   - `SENDGRID_FROM_EMAIL` = `noreply@makeleads.us`
   - `TWILIO_ACCOUNT_SID` = (your Twilio SID)
   - `TWILIO_AUTH_TOKEN` = (your Twilio auth token)
   - `TWILIO_PHONE_NUMBER` = (your Twilio phone number)
   - `SLYBROADCAST_USER` = (your Slybroadcast email)
   - `SLYBROADCAST_PASS` = (your Slybroadcast password)

5. **Install Dependencies**
   - Click "Run NPM Install" in the Node.js app panel
   - (This app has zero npm dependencies, so it will complete instantly)

6. **Start the Application**
   - Click **START APP** or **RESTART**
   - Visit your domain — the site should be live!

### Important Notes for Shared Hosting
- cPanel uses **Phusion Passenger** to proxy requests to your Node.js app
- The PORT environment variable is set automatically by Passenger
- Your `data/db.json` file stores all data — back it up regularly
- If the app doesn't start, check the error log in cPanel → Errors

---

## Option 2: Namecheap VPS (More Control)

If you need more power or control, use a Namecheap VPS.

### Step-by-Step

1. **Purchase a VPS**
   - Namecheap VPS → Pulsar or higher
   - Choose Ubuntu 22.04 or 24.04

2. **SSH into your VPS**
   ```bash
   ssh root@your-vps-ip
   ```

3. **Install Node.js**
   ```bash
   curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
   apt-get install -y nodejs
   ```

4. **Upload and extract the app**
   ```bash
   mkdir -p /var/www/makeleads
   cd /var/www/makeleads
   # Upload makeleads.zip via SCP or SFTP, then:
   unzip makeleads.zip
   ```

5. **Set up environment variables**
   ```bash
   cp .env.example .env
   nano .env   # Fill in your API keys
   ```

6. **Create a systemd service for auto-start**
   ```bash
   cat > /etc/systemd/system/makeleads.service << 'EOF'
   [Unit]
   Description=MakeLeads.us
   After=network.target

   [Service]
   Type=simple
   User=www-data
   WorkingDirectory=/var/www/makeleads
   ExecStart=/usr/bin/node server.js
   Restart=on-failure
   EnvironmentFile=/var/www/makeleads/.env

   [Install]
   WantedBy=multi-user.target
   EOF

   systemctl enable makeleads
   systemctl start makeleads
   ```

7. **Set up Nginx reverse proxy**
   ```bash
   apt install nginx -y
   cat > /etc/nginx/sites-available/makeleads << 'EOF'
   server {
       listen 80;
       server_name makeleads.us www.makeleads.us;

       location / {
           proxy_pass http://127.0.0.1:3000;
           proxy_http_version 1.1;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection 'upgrade';
           proxy_set_header Host $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_cache_bypass $http_upgrade;
       }
   }
   EOF

   ln -s /etc/nginx/sites-available/makeleads /etc/nginx/sites-enabled/
   nginx -t && systemctl restart nginx
   ```

8. **Add SSL with Let's Encrypt**
   ```bash
   apt install certbot python3-certbot-nginx -y
   certbot --nginx -d makeleads.us -d www.makeleads.us
   ```

---

## File Structure
```
makeleads/
  server.js          ← Main server (startup file)
  package.json       ← App metadata
  .env.example       ← Template for environment variables
  public/            ← Frontend files (HTML, CSS, JS)
    index.html       ← Landing page
    login.html       ← Login
    register.html    ← Registration
    dashboard.html   ← User dashboard
    browse.html      ← Lead browser
    credits.html     ← Credits & billing
    marketing.html   ← Auto-marketing campaigns
    styles.css       ← Global styles
    api.js           ← Frontend API client
  server/            ← Backend modules
    auth.js          ← JWT auth & password hashing
    db.js            ← JSON database & seed data
    services/
      email.js       ← SendGrid integration
      sms.js         ← Twilio integration
      voicemail.js   ← Slybroadcast integration
  data/              ← Database storage
    db.json          ← Auto-generated on first run
```

## Connecting Your Integrations

| Service | What It Does | How to Get Keys |
|---------|-------------|-----------------|
| SendGrid | Email campaigns | https://sendgrid.com → Settings → API Keys |
| Twilio | SMS outreach | https://twilio.com → Console → Account Info |
| Slybroadcast | Ringless voicemail | https://slybroadcast.com → Account Settings |

All three services run in **simulation mode** until you add real API keys. In simulation mode, messages are logged to the console but not actually sent.
