Overview
The Gima AI Chatbot uses environment variables for configuration, with validation powered by Zod to ensure type-safety and fail-fast behavior if critical configuration is missing. All environment variables are validated at startup inapp/config/env.ts:51.
Environment File Setup
Creating Your Configuration
-
Copy the example environment file:
- Update the values with your actual API keys and settings
-
Never commit
.env.localto version control
Required Configuration
API Keys
GROQ API Key
Required for: Text generation, chat responses, AI tools- Format: Must start with
gsk_ - Obtain from: https://console.groq.com/keys
- Validation: Checked at
app/config/env.ts:12-18
Google Generative AI API Key
Required for: Voice transcription, image analysis, PDF processing- Format: Must start with
AIza - Obtain from: https://makersuite.google.com/app/apikey
- Validation: Checked at
app/config/env.ts:19-25
Optional Configuration
Application URL
- Default: Not set (optional)
- Used for: Absolute URLs, redirects, metadata
- Production example:
https://your-domain.com - Development example:
http://localhost:3000
The
NEXT_PUBLIC_ prefix makes this variable accessible on the client side.Node Environment
- Allowed values:
development,production,test - Default:
development - Validation: Enforced by Zod enum at
app/config/env.ts:28
Feature Flags
Chat Persistence
- Default:
false - Purpose: Enables local storage of chat messages in the browser
- Storage location: Browser localStorage
- Limit: Up to 100 messages (see
app/config/limits.ts:94)
Voice Commands
- Default:
false - Purpose: Enables voice-activated work order creation
- Requirements: Google Generative AI API key must be configured
PDF Reader & Analysis
- Default:
false - Purpose: Enables PDF document upload and AI analysis
- Max file size: 10MB (see
app/config/limits.ts:59) - Requirements: Google Generative AI API key must be configured
Backend Integration
Backend API URL
- Format: Must be a valid URL
- Purpose: Base URL for Laravel backend API (GIMA)
- Validation: URL format checked at
app/config/env.ts:31 - Used by:
BackendAPIService(seeapp/lib/services/backend-api-service.ts:300)
Backend API Key
- Purpose: Authentication key for backend API requests
- Optional: Can be empty if using other auth methods
Demo Mode
- Default:
false - Purpose: Enables demo mode with mock data (no real backend required)
- Transform: String “true”/“false” converted to boolean
Configuration Limits
The application enforces various size limits for uploads and messages:File Upload Limits
| Type | Max Size | Configuration |
|---|---|---|
| Audio files | 5MB | MAX_AUDIO_SIZE_BYTES |
| Images | 5MB | MAX_IMAGE_SIZE_BYTES |
| PDF documents | 10MB | MAX_PDF_SIZE_BYTES |
| Server actions | 5MB | SERVER_ACTION_BODY_SIZE_BYTES |
app/config/limits.ts
Message Limits
- Max message text size: 10KB (~5000 words)
- Max stored messages: 100 messages in localStorage
Environment Validation
The application uses Zod for runtime validation of environment variables:Common Validation Errors
GROQ_API_KEY must start with 'gsk_'
GROQ_API_KEY must start with 'gsk_'
Solution: Verify your GROQ API key begins with the correct prefix. Get a new key from console.groq.com if needed.
Google API Key must start with 'AIza'
Google API Key must start with 'AIza'
Solution: Verify your Google API key begins with the correct prefix. Get a new key from Google AI Studio.
Invalid NODE_ENV
Invalid NODE_ENV
Solution: Use only
development, production, or test. Remove any custom environment names.TypeScript Types
All environment variables are fully typed:Best Practices
Use .env.local
Always store secrets in
.env.local, never in .env or committed files.Validate Early
The app validates all config at startup - fix issues before deployment.
Separate Environments
Use different API keys for development and production environments.
Monitor Limits
Be aware of file size limits when enabling PDF and image features.
Next Steps
AI Models
Learn about available AI models and how to configure them
Backend Integration
Set up the Laravel backend API integration