# NotyoBiz Cloud Lab - Configuration Guide

## Overview
This guide will help you configure and deploy your cloud-based home lab on your resellerspanel.com hosting account for the domain `notyobiz.com`.

## Hosting Account Features
Your Large plan includes:
- **Unlimited domains/subdomains** - Perfect for creating specialized environments
- **NodeJS (1 instance)** - For API backend services
- **Unlimited MySQL & PostgreSQL** - For data engineering projects
- **Redis (16MB)** - For caching and session management
- **Memcached (16MB)** - Additional caching layer
- **Varnish (16MB)** - HTTP accelerator/cache
- **SSH Access** - For server management
- **10% CPU limit** - Requires efficient coding practices
- **Unlimited cron jobs** - For automation and scheduling

## Recommended Subdomain Structure
Configure these subdomains in your hosting control panel:

- **`portal.notyobiz.com`** → Portal dashboard (`/portal/`)
- **`api.notyobiz.com`** → NodeJS API services (`/api/`)
- **`data.notyobiz.com`** → Data engineering tools (`/data/`)
- **`docs.notyobiz.com`** → Documentation (`/docs/`)
- **`tools.notyobiz.com`** → Development tools
- **`staging.notyobiz.com`** → Staging environment

## Initial Setup Steps

### Prerequisites
Before starting, ensure you have the following installed:

#### For Local Development (Windows):
1. **Node.js** (v14 or higher):
   ```powershell
   # Install using winget (Windows Package Manager)
   winget install OpenJS.NodeJS
   
   # Or download from https://nodejs.org/
   # Verify installation:
   node --version
   npm --version
   ```

2. **Python** (v3.8 or higher):
   ```powershell
   # Install using winget
   winget install Python.Python.3
   
   # Verify installation:
   python --version
   pip --version
   ```

#### For Rocky Linux 8.x Server (Production):
1. **Node.js** (v16 LTS - recommended for Rocky Linux 8):
   ```bash
   # Enable Node.js 16 module stream
   sudo dnf module enable nodejs:16 -y
   sudo dnf install nodejs npm -y
   
   # Alternative: Install from NodeSource repository
   curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash -
   sudo dnf install nodejs -y
   
   # Verify installation
   node --version
   npm --version
   ```

2. **Python** (v3.8+ - included in Rocky Linux 8):
   ```bash
   # Python 3.8 is included by default in Rocky Linux 8
   sudo dnf install python3 python3-pip python3-venv -y
   
   # Install development tools
   sudo dnf groupinstall "Development Tools" -y
   sudo dnf install python3-devel -y
   
   # Verify installation
   python3 --version
   pip3 --version
   ```

3. **Database Servers** (if self-hosting):
   ```bash
   # MySQL 8.0
   sudo dnf install mysql-server mysql -y
   sudo systemctl enable mysqld
   sudo systemctl start mysqld
   
   # PostgreSQL 13
   sudo dnf install postgresql-server postgresql -y
   sudo postgresql-setup --initdb
   sudo systemctl enable postgresql
   sudo systemctl start postgresql
   
   # Redis
   sudo dnf install redis -y
   sudo systemctl enable redis
   sudo systemctl start redis
   ```

4. **Essential Development Tools**:
   ```bash
   # Install build tools and utilities
   sudo dnf install git curl wget unzip zip -y
   sudo dnf install gcc-c++ make -y
   
   # Install process manager for Node.js
   sudo npm install -g pm2
   ```

#### Troubleshooting "SyntaxError: Unexpected token"
If you see this error, it's likely due to one of these issues:

1. **Node.js not installed**: Install Node.js as shown above
2. **Outdated Node.js version**: Update to Node.js 14+ for modern JavaScript syntax
3. **Wrong file execution**: Make sure you're running the correct file

#### Quick Start (Minimal Setup):
```bash
# For Rocky Linux 8.x server
cd /path/to/api/

# Install minimal dependencies (just express)
npm install express

# Start the simple server (no database dependencies)
node server-simple.js

# Or use PM2 for production
pm2 start server-simple.js --name "notyobiz-api"
pm2 startup
pm2 save
```

```powershell
# For Windows local development
cd api

# Install minimal dependencies (just express)
npm install express

# Start the simple server (no database dependencies)
node server-simple.js
```

### 1. Upload Files via FTP/SSH
```bash
# Connect via SSH (Rocky Linux 8.x server)
ssh your_username@notyobiz.com

# Create directory structure
mkdir -p ~/public_html/{portal,api,data,docs}

# Set proper permissions for Rocky Linux
chmod 755 ~/public_html
chmod -R 644 ~/public_html/*
find ~/public_html -type d -exec chmod 755 {} \;

# Upload via SCP (from local machine)
scp -r portal/ your_username@notyobiz.com:~/public_html/
scp -r api/ your_username@notyobiz.com:~/
scp -r data/ your_username@notyobiz.com:~/
scp -r docs/ your_username@notyobiz.com:~/public_html/

# Or use rsync for better synchronization
rsync -avz --progress portal/ your_username@notyobiz.com:~/public_html/portal/
rsync -avz --progress api/ your_username@notyobiz.com:~/api/
```

### 2. Configure NodeJS Application

#### Option A: Simple Setup (Recommended for testing)
```bash
# Navigate to API directory on Rocky Linux 8.x
cd ~/api/

# Install only Express (minimal dependencies)
npm install express

# Start the simple server
node server-simple.js

# For production, use PM2 process manager
pm2 start server-simple.js --name "notyobiz-api-simple"
pm2 startup systemd -u $USER --hp $HOME
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u $USER --hp $HOME
pm2 save
```

#### Option B: Full Setup (With database support)
```bash
# Navigate to API directory on Rocky Linux 8.x
cd ~/api/

# Install all dependencies
npm install --production

# Copy environment configuration
cp .env.example .env
# Edit .env with your database credentials
vi .env

# Start the full server with PM2
pm2 start server.js --name "notyobiz-api-full"
pm2 save
```

**Rocky Linux 8.x Specific Notes**:
- Use `systemctl` commands for service management
- Configure firewall: `sudo firewall-cmd --add-port=3000/tcp --permanent && sudo firewall-cmd --reload`
- SELinux considerations: May need `setsebool -P httpd_can_network_connect 1` for network connections

### 3. Database Setup
```sql
-- Create MySQL databases through hosting control panel or CLI
CREATE DATABASE notyobiz_lab;
CREATE DATABASE notyobiz_data;
CREATE DATABASE notyobiz_analytics;

-- Create PostgreSQL databases
CREATE DATABASE notyobiz_data_eng;
CREATE DATABASE notyobiz_warehouse;
```

### 4. Environment Configuration
Create `.env` file in your API directory:
```bash
# Copy example configuration
cp .env.example .env

# Edit with your actual values
nano .env
```

### 5. Redis Configuration
Redis should be available through your hosting provider. Configure connection:
```javascript
// In your Node.js app
const redis = require('redis');
const client = redis.createClient({
    host: 'localhost',  // Or your Redis host
    port: 6379,
    // password: 'your_redis_password'
});
```

### 6. Set Up Cron Jobs
Configure through your hosting control panel:
```bash
# System monitoring (every 5 minutes)
*/5 * * * * /usr/bin/curl -s https://api.notyobiz.com/health > /dev/null

# Database backup (daily at 2 AM)
0 2 * * * /usr/bin/python3 /path/to/data/backup_script.py

# Log cleanup (weekly)
0 0 * * 0 /usr/bin/find /path/to/logs -name "*.log" -mtime +7 -delete

# Data processing (daily at 3 AM)
0 3 * * * /usr/bin/python3 /path/to/data/etl_pipeline.py
```

## Performance Optimization

### CPU Efficiency (10% limit)
- Use efficient algorithms and data structures
- Implement proper caching strategies
- Optimize database queries
- Use asynchronous operations in Node.js
- Monitor CPU usage regularly

### Memory Management
- Configure Redis memory limits
- Optimize database connection pools
- Use streaming for large data processing
- Implement garbage collection monitoring

### Caching Strategy
```javascript
// Multi-layer caching
// 1. Varnish (HTTP cache)
// 2. Redis (Application cache)
// 3. Memcached (Session cache)

// Example Redis caching
const cacheKey = `data:${userId}:${timestamp}`;
const cachedData = await redis.get(cacheKey);
if (cachedData) {
    return JSON.parse(cachedData);
}
```

## Security Configuration

### SSL/TLS Setup
Enable SSL certificates through your hosting control panel:
- Main domain: `notyobiz.com`
- All subdomains: `*.notyobiz.com`

### Database Security
```sql
-- Create dedicated database users
CREATE USER 'lab_api'@'localhost' IDENTIFIED BY 'strong_password';
GRANT SELECT, INSERT, UPDATE, DELETE ON notyobiz_lab.* TO 'lab_api'@'localhost';

CREATE USER 'lab_readonly'@'localhost' IDENTIFIED BY 'another_password';
GRANT SELECT ON notyobiz_lab.* TO 'lab_readonly'@'localhost';
```

### API Security
```javascript
// Implement rate limiting
const rateLimit = require('express-rate-limit');
const limiter = rateLimit({
    windowMs: 15 * 60 * 1000, // 15 minutes
    max: 100 // limit each IP to 100 requests per windowMs
});
```

## Monitoring and Logging

### System Monitoring
Create monitoring dashboard accessible at `portal.notyobiz.com`:
- CPU usage tracking
- Memory utilization
- Database connection status
- API response times
- Error rates

### Log Management
```bash
# Log rotation configuration
/var/log/notyobiz/*.log {
    daily
    missingok
    rotate 7
    compress
    delaycompress
    notifempty
    postrotate
        systemctl reload nodejs-app
    endscript
}
```

## Data Engineering Setup

### Python Environment
```bash
# Install Python packages
pip3 install -r data/requirements.txt

# Set up Jupyter Notebook
jupyter notebook --ip=0.0.0.0 --port=8888 --no-browser
```

### ETL Pipeline Configuration
```python
# Example ETL configuration
ETL_CONFIG = {
    'source_db': 'mysql://user:pass@localhost/source',
    'target_db': 'postgresql://user:pass@localhost/warehouse',
    'redis_cache': 'redis://localhost:6379/0',
    'batch_size': 1000,
    'schedule': '0 3 * * *'  # Daily at 3 AM
}
```

## Troubleshooting

### Common Issues

1. **NodeJS App Not Starting**
   - Check hosting control panel for NodeJS configuration
   - Verify file permissions
   - Check error logs in hosting control panel

2. **Database Connection Errors**
   - Verify database credentials
   - Check if databases exist
   - Ensure user permissions are correct

3. **High CPU Usage**
   - Review code for inefficient operations
   - Implement caching
   - Optimize database queries
   - Use profiling tools

4. **Memory Issues**
   - Monitor Redis memory usage
   - Optimize data structures
   - Implement proper cleanup

### Useful Commands
```bash
# Check disk usage
df -h

# Monitor processes
top -p $(pgrep node)

# Check logs
tail -f /path/to/logs/api.log

# Test database connection
mysql -u username -p -h localhost notyobiz_lab

# Redis CLI
redis-cli info memory
```

## Backup Strategy

### Automated Backups
```bash
#!/bin/bash
# Daily backup script
DATE=$(date +%Y%m%d)
BACKUP_DIR="/path/to/backups"

# Database backup
mysqldump -u root -p notyobiz_lab > "$BACKUP_DIR/mysql_$DATE.sql"
pg_dump notyobiz_data_eng > "$BACKUP_DIR/postgres_$DATE.sql"

# File backup
tar -czf "$BACKUP_DIR/files_$DATE.tar.gz" /path/to/api /path/to/portal

# Keep only last 30 days
find "$BACKUP_DIR" -name "*.sql" -mtime +30 -delete
find "$BACKUP_DIR" -name "*.tar.gz" -mtime +30 -delete
```

## Next Steps

1. **Initial Deployment**
   - Upload files to hosting server
   - Configure databases
   - Set up environment variables
   - Test all endpoints

2. **Development Workflow**
   - Set up local development environment
   - Create staging subdomain
   - Implement CI/CD pipeline
   - Set up monitoring alerts

3. **Learning Projects**
   - Start with simple data analysis projects
   - Build REST APIs for data access
   - Create interactive dashboards
   - Implement machine learning workflows

4. **Advanced Features**
   - WebSocket connections for real-time data
   - GraphQL API endpoints
   - Microservices architecture
   - Container deployment

## Support Resources

- **Hosting Support**: Contact resellerspanel.com support
- **Documentation**: Access at `docs.notyobiz.com`
- **API Reference**: Available at `api.notyobiz.com`
- **Community**: Set up Discord/Slack for project discussions

---

**Remember**: Always test changes in staging environment first, monitor CPU usage to stay within limits, and maintain regular backups of your data and configurations.
