2025-08-21 15:24:40 +09:00
|
|
|
# 🚀 Getting Started with Customer Portal
|
|
|
|
|
|
|
|
|
|
## ✅ **Environment File Options**
|
|
|
|
|
|
|
|
|
|
We provide **environment-specific templates** for easy setup:
|
|
|
|
|
|
|
|
|
|
### 📁 **Available Templates:**
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-27 20:01:46 +09:00
|
|
|
- 🔸 **`.env.example`** - Standard environment template for all environments
|
|
|
|
|
- 🔸 **Environment-specific values** - Adjust settings based on development vs production needs
|
2025-08-21 15:24:40 +09:00
|
|
|
|
|
|
|
|
### 🎯 **Benefits:**
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
- ✅ **Environment-specific**: Clear separation of dev vs prod
|
|
|
|
|
- ✅ **Secure defaults**: Production uses strong security settings
|
|
|
|
|
- ✅ **Easy setup**: Copy the right template for your needs
|
|
|
|
|
- ✅ **No confusion**: Clear instructions for each environment
|
|
|
|
|
|
|
|
|
|
## 🔧 **Environment File Structure**
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
📦 Customer Portal
|
2025-08-27 20:01:46 +09:00
|
|
|
├── .env.example # 🔸 Environment template
|
2025-08-21 15:24:40 +09:00
|
|
|
├── .env # ✅ Your actual config (gitignored)
|
|
|
|
|
├── apps/
|
|
|
|
|
│ ├── bff/ # 🚀 Backend reads from root .env
|
|
|
|
|
│ └── portal/ # 🚀 Frontend reads from root .env
|
|
|
|
|
└── ...
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**How it works:**
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
- **Frontend (Next.js)**: Automatically reads `.env` from project root
|
2025-08-22 17:02:49 +09:00
|
|
|
- **Backend (NestJS)**: Automatically reads `.env` from project root
|
2025-08-21 15:24:40 +09:00
|
|
|
- **Docker**: We pass env vars from root `.env` to containers
|
|
|
|
|
|
|
|
|
|
## 🚀 **Quick Start (2 minutes)**
|
|
|
|
|
|
|
|
|
|
### 1. Setup Environment
|
|
|
|
|
|
|
|
|
|
**🔸 For Development:**
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
```bash
|
2025-08-28 16:57:57 +09:00
|
|
|
# Copy development environment template
|
|
|
|
|
cp .env.dev.example .env
|
2025-08-21 15:24:40 +09:00
|
|
|
|
|
|
|
|
# Edit with your dev values (most defaults work!)
|
2025-08-27 20:01:46 +09:00
|
|
|
nano .env # Configure for local development
|
2025-08-21 15:24:40 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**🔸 For Production:**
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
```bash
|
2025-08-28 16:57:57 +09:00
|
|
|
# Copy production environment template
|
|
|
|
|
cp .env.production.example .env
|
2025-08-21 15:24:40 +09:00
|
|
|
|
|
|
|
|
# Edit with your production values (REQUIRED!)
|
2025-08-27 20:01:46 +09:00
|
|
|
nano .env # Replace with secure production values
|
2025-08-21 15:24:40 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 2. Start Development
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
```bash
|
|
|
|
|
# Start database and Redis services
|
|
|
|
|
pnpm dev:start
|
|
|
|
|
|
|
|
|
|
# In another terminal, start the applications
|
|
|
|
|
pnpm dev
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**That's it!** Both frontend and backend will use the same `.env` file.
|
|
|
|
|
|
|
|
|
|
## 📋 **What Each App Reads**
|
|
|
|
|
|
|
|
|
|
### **Backend (apps/bff/)**
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
Reads these variables from root `.env`:
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
```bash
|
|
|
|
|
DATABASE_URL # Database connection
|
|
|
|
|
REDIS_URL # Cache connection
|
|
|
|
|
JWT_SECRET # Authentication
|
|
|
|
|
WHMCS_BASE_URL # External API
|
|
|
|
|
SF_LOGIN_URL # Salesforce API
|
2025-08-27 20:01:46 +09:00
|
|
|
PORTAL_PRICEBOOK_ID # Salesforce pricing pricebook
|
2025-08-21 15:24:40 +09:00
|
|
|
LOG_LEVEL # Logging level
|
|
|
|
|
# ... and all backend variables
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### **Frontend (apps/portal/)**
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
Reads these variables from root `.env`:
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
```bash
|
|
|
|
|
NEXT_PUBLIC_API_BASE # Backend API URL
|
|
|
|
|
NEXT_PUBLIC_APP_NAME # App branding
|
|
|
|
|
NEXT_PUBLIC_APP_VERSION # Version display
|
|
|
|
|
NEXT_PUBLIC_ENABLE_DEVTOOLS # Development tools
|
|
|
|
|
# ... only NEXT_PUBLIC_ variables are exposed to browser
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 🛠️ **Development Workflow**
|
|
|
|
|
|
|
|
|
|
### Daily Development
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
```bash
|
|
|
|
|
# 1. Start services (run once)
|
|
|
|
|
pnpm dev:start
|
|
|
|
|
|
|
|
|
|
# 2. Start apps (with hot reload)
|
|
|
|
|
pnpm dev
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Environment Changes
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
```bash
|
|
|
|
|
# Edit the single .env file
|
|
|
|
|
nano .env
|
|
|
|
|
|
|
|
|
|
# Restart apps to pick up changes
|
|
|
|
|
# (Services like database don't need restart)
|
|
|
|
|
pnpm dev
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Database Management
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
```bash
|
|
|
|
|
# Run migrations
|
|
|
|
|
pnpm dev:migrate
|
|
|
|
|
|
|
|
|
|
# Open database admin tool
|
|
|
|
|
pnpm dev:tools
|
|
|
|
|
# Visit http://localhost:8080 for Adminer
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 🚀 **Production Deployment**
|
|
|
|
|
|
|
|
|
|
### For Production
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
```bash
|
|
|
|
|
# 1. Copy template
|
|
|
|
|
cp .env.example .env
|
|
|
|
|
|
|
|
|
|
# 2. Edit for production values
|
|
|
|
|
nano .env
|
|
|
|
|
# Set strong passwords, production URLs, etc.
|
|
|
|
|
|
|
|
|
|
# 3. Deploy
|
|
|
|
|
pnpm prod:deploy
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 🔍 **Key Benefits**
|
|
|
|
|
|
|
|
|
|
### **Single Source of Truth**
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
- ✅ One file to rule them all
|
|
|
|
|
- ✅ No confusion about which file to edit
|
|
|
|
|
- ✅ No duplicate values to maintain
|
|
|
|
|
- ✅ Consistent configuration across apps
|
|
|
|
|
|
|
|
|
|
### **Standard Approach**
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
- ✅ Follows Next.js conventions
|
2025-08-22 17:02:49 +09:00
|
|
|
- ✅ Follows NestJS conventions
|
2025-08-21 15:24:40 +09:00
|
|
|
- ✅ Follows Docker conventions
|
|
|
|
|
- ✅ Industry best practice
|
|
|
|
|
|
|
|
|
|
### **Developer Friendly**
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
- ✅ Simple setup: copy one file
|
|
|
|
|
- ✅ Easy to understand structure
|
|
|
|
|
- ✅ No app-specific configuration needed
|
|
|
|
|
- ✅ Works with all tools (VS Code, Docker, etc.)
|
|
|
|
|
|
|
|
|
|
## 🚨 **Important Notes**
|
|
|
|
|
|
|
|
|
|
### **Security**
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
- ✅ `.env.example` is committed (safe template)
|
|
|
|
|
- ✅ `.env` is gitignored (contains secrets)
|
|
|
|
|
- ✅ Never commit actual `.env` file to git
|
|
|
|
|
- ✅ Use strong values for production
|
|
|
|
|
|
|
|
|
|
### **Variable Naming**
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
- ✅ `NEXT_PUBLIC_*` = Exposed to browser (frontend)
|
|
|
|
|
- ✅ Everything else = Server-side only (backend)
|
|
|
|
|
- ✅ Clear naming convention
|
|
|
|
|
|
|
|
|
|
### **Environment Separation**
|
2025-08-22 17:02:49 +09:00
|
|
|
|
2025-08-21 15:24:40 +09:00
|
|
|
- ✅ Development: Use local services (localhost)
|
|
|
|
|
- ✅ Production: Use container services (service names)
|
|
|
|
|
- ✅ Same file structure, different values
|
|
|
|
|
|
|
|
|
|
This approach is **simple, standard, and scalable**! 🎉
|