Configuration Guide
Detailed configuration options for AI content reporpuser.
Table of Contents
- Backend Configuration
- Frontend Configuration
- AI Provider Setup
- Firebase Configuration
- Environment Variables Reference
Backend Configuration
Environment File (.env)
The backend uses environment variables for configuration. Create a .env file in the backend/ directory:
# ==============================================
# AI PROVIDER CONFIGURATION
# ==============================================
# Your OpenAI API Key (required)
# Get it from: https://platform.openai.com/api-keys
OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxxxxxxx
# AI Provider to use (default: openai)
# Options: openai, anthropic, gemini
AI_PROVIDER=openai
# AI Model to use
# OpenAI options: gpt-4-turbo-preview, gpt-4, gpt-3.5-turbo
# Anthropic options: claude-3-opus, claude-3-sonnet
AI_MODEL=gpt-4-turbo-preview
# ==============================================
# SERVER CONFIGURATION
# ==============================================
# Port for backend server (default: 3000)
PORT=3000
# Node environment
# Options: development, production
NODE_ENV=development
# ==============================================
# FIREBASE CONFIGURATION (Optional)
# ==============================================
# Path to Firebase service account JSON file
FIREBASE_SERVICE_ACCOUNT_PATH=serviceAccountKey.json
# Firebase Database URL
# Format: https://YOUR-PROJECT-ID.firebaseio.com
FIREBASE_DATABASE_URL=https://your-project.firebaseio.com
# Firebase Storage Bucket
# Format: YOUR-PROJECT-ID.appspot.com
FIREBASE_STORAGE_BUCKET=your-project.appspot.com
# ==============================================
# CORS CONFIGURATION
# ==============================================
# Allowed origins for CORS (comma-separated)
# Use * for development, specific URLs for production
ALLOWED_ORIGINS=http://localhost:*,http://127.0.0.1:*
# ==============================================
# LOGGING CONFIGURATION
# ==============================================
# Log level: error, warn, info, debug
LOG_LEVEL=info
# Enable file logging (true/false)
LOG_TO_FILE=false
# ==============================================
# RATE LIMITING (Optional)
# ==============================================
# Maximum requests per 15 minutes per IP
RATE_LIMIT_MAX=100
# Rate limit window in milliseconds
RATE_LIMIT_WINDOW=900000
# ==============================================
# CONTENT INGESTION
# ==============================================
# Maximum content length for URL ingestion (characters)
MAX_CONTENT_LENGTH=50000
# Timeout for URL fetching (milliseconds)
URL_FETCH_TIMEOUT=10000
Configuration Validation
The backend validates configuration on startup. Check logs for:
✓ OpenAI API key configured
✓ Admin SDK initialized successfully
✓ Server running on port 3000
If you see warnings:
⚠ Service account not configured. Firebase features disabled.
This is normal if you haven't set up Firebase yet.
Frontend Configuration
Application Settings
The frontend uses SharedPreferences for persistent settings. Configure these in-app:
- Open the app
- Click Settings (gear icon)
- Configure options:
Backend Configuration
- API URL:
http://localhost:3000(or your server URL) - Click Test Connection to verify
Default Settings
- Default Tone: Professional, Casual, Friendly, etc.
- Default Platforms: Pre-select platforms for quick generation
Content Rules
- Show character limit warnings: Enable/disable warnings
- Enable hashtags: Include hashtags in generated content
History & Privacy
- Save generation history: Store generations locally
Appearance
- Dark mode: Toggle light/dark theme
Manual Configuration (Advanced)
Edit configuration in code if needed:
lib/constants/app_constants.dart
class AppConstants {
static const String defaultApiUrl = 'http://localhost:3000';
static const int requestTimeout = 60; // seconds
// Add custom platforms
static final List<PlatformInfo> platforms = [
// ... existing platforms
];
}
AI Provider Setup
OpenAI Setup
- Create Account: platform.openai.com
- Get API Key: Go to API Keys section
- Set Usage Limits: Optional but recommended
- Configure in .env:
OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxxxxxxx
AI_PROVIDER=openai
AI_MODEL=gpt-4-turbo-preview
Model Options
gpt-4-turbo-preview: Best quality, slower, more expensivegpt-4: High quality, good balancegpt-3.5-turbo: Fast, cost-effective, good quality
Alternative Providers (Future)
The system is designed to support multiple providers:
Anthropic (Claude)
ANTHROPIC_API_KEY=your_key
AI_PROVIDER=anthropic
AI_MODEL=claude-3-opus
Google Gemini
GOOGLE_API_KEY=your_key
AI_PROVIDER=gemini
AI_MODEL=gemini-pro
Note: Provider implementations may require code updates.
Firebase Configuration
Firestore Collections Structure
The app uses these collections:
firestore/
├── settings/
│ └── preferences (doc)
│ ├── defaultTone: string
│ ├── defaultPlatforms: array
│ └── updatedAt: timestamp
│
├── generations/
│ └── [auto-id] (doc)
│ ├── content: string
│ ├── platforms: array
│ ├── results: map
│ ├── parameters: map
│ └── createdAt: timestamp
│
└── analytics/
└── usage (doc)
├── totalGenerations: number
├── platformCounts: map
└── updatedAt: timestamp
Security Rules
For production, use server-side only access:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Block all client access
match /{document=**} {
allow read, write: if false;
}
}
}
The backend uses Firebase Admin SDK with full privileges.
Indexes
For optimal performance, create these indexes:
generations collection:
- Field:
createdAt(Descending) - Used for: History queries
Create via Firebase Console → Firestore → Indexes
Environment Variables Reference
Required Variables
| Variable | Description | Example | Required |
|---|---|---|---|
OPENAI_API_KEY | OpenAI API key | sk-proj-xxxxx | ✅ Yes |
PORT | Server port | 3000 | ❌ No (default: 3000) |
Optional Variables
| Variable | Description | Example | Default |
|---|---|---|---|
AI_PROVIDER | AI provider name | openai | openai |
AI_MODEL | Model to use | gpt-4-turbo-preview | gpt-3.5-turbo |
NODE_ENV | Environment | production | development |
FIREBASE_SERVICE_ACCOUNT_PATH | Firebase key path | serviceAccountKey.json | - |
FIREBASE_DATABASE_URL | Firebase DB URL | https://...firebaseio.com | - |
FIREBASE_STORAGE_BUCKET | Firebase bucket | project.appspot.com | - |
ALLOWED_ORIGINS | CORS origins | http://localhost:* | * |
LOG_LEVEL | Logging level | info | info |
RATE_LIMIT_MAX | Rate limit | 100 | No limit |
MAX_CONTENT_LENGTH | Max content chars | 50000 | 100000 |
URL_FETCH_TIMEOUT | URL timeout (ms) | 10000 | 30000 |
Loading Order
Environment variables are loaded in this order (later overrides earlier):
- System environment variables
.envfile in backend directory.env.localfile (if exists, git-ignored)
Validation
Required variables are validated on startup. The app will log warnings or exit if critical variables are missing.
Check validation with:
npm start
Look for:
✓ All required environment variables configured
Production Configuration
Security Checklist
- Remove development origins from
ALLOWED_ORIGINS - Set
NODE_ENV=production - Use strong API keys (regenerate from provider)
- Set appropriate rate limits
- Enable HTTPS on frontend
- Restrict Firebase rules
- Set up monitoring/logging
- Configure backup for Firebase
- Use environment-specific
.envfiles
Production .env Example
# Production Configuration
OPENAI_API_KEY=sk-proj-production-key-xxxxx
AI_PROVIDER=openai
AI_MODEL=gpt-4-turbo-preview
PORT=3000
NODE_ENV=production
# Firebase
FIREBASE_SERVICE_ACCOUNT_PATH=/secure/path/serviceAccount.json
FIREBASE_DATABASE_URL=https://prod-project.firebaseio.com
FIREBASE_STORAGE_BUCKET=prod-project.appspot.com
# Security
ALLOWED_ORIGINS=https://yourdomain.com,https://app.yourdomain.com
# Performance
RATE_LIMIT_MAX=1000
LOG_LEVEL=warn
LOG_TO_FILE=true
Environment-Specific Files
Use different files for different environments:
.env # Default configuration
.env.development # Development overrides
.env.production # Production overrides
.env.local # Local overrides (git-ignored)
Load with:
NODE_ENV=production node dist/index.js
Troubleshooting Configuration
Backend Won't Start
- Check
.envfile exists - Verify
OPENAI_API_KEYis set - Check port availability:
lsof -i :3000 - Review logs for specific errors
Firebase Not Working
- Verify
serviceAccountKey.jsonexists - Check file permissions
- Validate JSON format
- Confirm Firebase project is active
Frontend Can't Connect
- Verify backend is running
- Check API URL in Settings
- Test connection button
- Check CORS settings in backend
API Key Invalid
- Regenerate key from provider
- Check for extra spaces in
.env - Verify key has correct permissions
- Check billing/quota status
Next Steps
- ✅ Configuration complete
- 📖 Continue to User Guide
- 🚀 Or see Deployment Guide
Need Help? Check the Troubleshooting Guide