Overview
Tambo360 requires several environment variables to configure the backend API, database connections, authentication, and email services. This guide provides a comprehensive reference for all configuration options.Environment File Structure
Create a.env file in your project root and backend directory:
Backend Environment Variables
Required Variables
These variables must be set for the backend to function:.env
Optional Variables
These variables enable additional features:.env
Frontend Environment Variables
Frontend variables use theVITE_ prefix:
apps/frontend/.env
Vite only exposes environment variables that start with
VITE_ to the client-side code for security.Variable Reference
NODE_ENV
Application environment mode.Values:
development- Development mode with debuggingproduction- Production mode with optimizationstest- Testing mode
developmentExample:PORT
Port number for the backend server.Default:
3000Example:Ensure this port is not already in use by another application.
DATABASE_URL
PostgreSQL connection string used by Prisma.Format:Parameters:
schema- Database schema (default:public)connection_limit- Max connections (default: unlimited)pool_timeout- Connection timeout in secondssslmode- SSL mode (require,prefer,disable)
DIRECT_URL
Direct database connection URL, bypassing connection poolers.Use case: Required when using PgBouncer or other connection poolers that don’t support certain Prisma features.Example:
JWT_SECRET
Secret key for signing JWT authentication tokens.Requirements:Example:
- Minimum 32 characters
- Use cryptographically secure random string
- Different for each environment
FRONTEND_URL
URL where the frontend application is hosted.Use cases:
- CORS configuration
- Email verification links
- Password reset links
BACKEND_URL
URL where the backend API is accessible.Use cases:
- Email verification links
- Webhook callbacks
CORS_ORIGIN
Allowed CORS origins for API requests.Values:
- Single origin:
"http://localhost:5173" - Multiple origins:
"http://localhost:5173,https://app.tambo360.com" - All origins (dev only):
"*"
EMAIL_USER
Email account username for sending emails.Supported providers:
- Gmail
- SendGrid (via SENDGRID_API_KEY)
- Custom SMTP servers
For Gmail, you need to enable “Less secure app access” or use an App Password.
EMAIL_PASS
Email account password or app-specific password.Gmail App Password setup:
- Enable 2-factor authentication
- Go to Google Account > Security > App Passwords
- Generate a new app password
- Use the 16-character password
SENDGRID_API_KEY
SendGrid API key for transactional emails.Setup:
- Create a SendGrid account
- Generate an API key with “Mail Send” permissions
- Add to environment variables
EMAIL_FROM
Default “From” address for outgoing emails.Example:
TAMBO_AI_URL
URL for the Tambo AI analytics service (if available).Example:
VITE_API_URL
Backend API base URL for frontend requests.Examples:
This variable must be set at build time. Changing it requires rebuilding the frontend.
VITE_API_IA_URL
AI service URL for frontend analytics features.Example:
Environment-Specific Configurations
Development Environment
.env.development
Production Environment
.env.production
Docker Environment
For Docker Compose, create a root.env file:
.env
When using Docker Compose, the database host is the service name (
db) instead of localhost.Loading Environment Variables
Backend (Node.js)
The backend usesdotenv to load environment variables:
Frontend (Vite)
Vite automatically loads.env files:
Security Best Practices
Use .env.example
Commit a template file without secrets:
.env.example
Add to .gitignore
Prevent committing secrets:
.gitignore
Rotate Secrets
Regularly rotate:
- JWT secrets
- Database passwords
- API keys
- Email passwords
Use Secret Managers
For production, use:
- AWS Secrets Manager
- HashiCorp Vault
- Azure Key Vault
- Google Secret Manager
Validation
Validate required environment variables on startup:Troubleshooting
Environment variables not loading
Environment variables not loading
Check that:
.envfile is in the correct directory- File is named exactly
.env(not.env.txt) - No spaces around
=sign - Values with spaces are quoted
Frontend variables undefined
Frontend variables undefined
Ensure variables:
- Start with
VITE_prefix - Are set before running
npm run build - Are accessed with
import.meta.env.VITE_*
Database connection fails
Database connection fails
Verify DATABASE_URL format:
JWT authentication errors
JWT authentication errors
Ensure JWT_SECRET:
- Is at least 32 characters
- Is the same across all backend instances
- Hasn’t changed (would invalidate existing tokens)
Next Steps
Database Setup
Configure database with proper credentials
Docker Setup
Use environment variables with Docker
Deployment
Set up production environment variables
