203 lines
4.7 KiB
Markdown
Raw Permalink Normal View History

# 🚀 Getting Started
2025-08-21 15:24:40 +09:00
## ✅ **Environment File Options**
We provide **environment-specific templates** for easy setup:
### 📁 **Available Templates:**
2025-08-22 17:02:49 +09:00
Located in the `env/` folder:
- 🔸 **`env/dev.env.sample`** - Development environment template
- 🔸 **`env/portal-backend.env.sample`** - Backend-specific variables reference
- 🔸 **`env/portal-frontend.env.sample`** - Frontend-specific variables reference
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 template for your needs
2025-08-21 15:24:40 +09:00
-**No confusion**: Clear instructions for each environment
## 🔧 **Environment File Structure**
```
📦 Customer Portal
├── env/
│ ├── dev.env.sample # 🔸 Development template
│ ├── portal-backend.env.sample # Backend variables
│ └── portal-frontend.env.sample # Frontend variables
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.env.sample .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
# Start from the development template and adjust for production
cp env/dev.env.sample .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**! 🎉