Skip to main content

Configuration Guide

Detailed configuration options for AI content reporpuser.

Table of Contents

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:

  1. Open the app
  2. Click Settings (gear icon)
  3. 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

  1. Create Account: platform.openai.com
  2. Get API Key: Go to API Keys section
  3. Set Usage Limits: Optional but recommended
  4. 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 expensive
  • gpt-4: High quality, good balance
  • gpt-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

VariableDescriptionExampleRequired
OPENAI_API_KEYOpenAI API keysk-proj-xxxxx✅ Yes
PORTServer port3000❌ No (default: 3000)

Optional Variables

VariableDescriptionExampleDefault
AI_PROVIDERAI provider nameopenaiopenai
AI_MODELModel to usegpt-4-turbo-previewgpt-3.5-turbo
NODE_ENVEnvironmentproductiondevelopment
FIREBASE_SERVICE_ACCOUNT_PATHFirebase key pathserviceAccountKey.json-
FIREBASE_DATABASE_URLFirebase DB URLhttps://...firebaseio.com-
FIREBASE_STORAGE_BUCKETFirebase bucketproject.appspot.com-
ALLOWED_ORIGINSCORS originshttp://localhost:**
LOG_LEVELLogging levelinfoinfo
RATE_LIMIT_MAXRate limit100No limit
MAX_CONTENT_LENGTHMax content chars50000100000
URL_FETCH_TIMEOUTURL timeout (ms)1000030000

Loading Order

Environment variables are loaded in this order (later overrides earlier):

  1. System environment variables
  2. .env file in backend directory
  3. .env.local file (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 .env files

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

  1. Check .env file exists
  2. Verify OPENAI_API_KEY is set
  3. Check port availability: lsof -i :3000
  4. Review logs for specific errors

Firebase Not Working

  1. Verify serviceAccountKey.json exists
  2. Check file permissions
  3. Validate JSON format
  4. Confirm Firebase project is active

Frontend Can't Connect

  1. Verify backend is running
  2. Check API URL in Settings
  3. Test connection button
  4. Check CORS settings in backend

API Key Invalid

  1. Regenerate key from provider
  2. Check for extra spaces in .env
  3. Verify key has correct permissions
  4. Check billing/quota status

Next Steps


Need Help? Check the Troubleshooting Guide