Environment Configuration
Relevant source files
The following files were used as context for generating this wiki page:
ThinkEx requires a specific set of environment variables and infrastructure components to function as a visual thinking environment. The configuration encompasses database connectivity, authentication secrets, AI model provider keys, and storage backend selection. This system ensures that the Next.js framework can communicate securely with PostgreSQL, external AI providers (like Google AI and Anthropic), and storage services.
The environment is primarily managed via a .env file, which is initialized from a template during the setup process. This configuration supports both local development—often utilizing Docker for infrastructure—and production-ready cloud deployments.
Infrastructure Setup
The project provides an automated setup script, setup.sh, which handles the initial environment configuration. This script performs prerequisite checks, generates required secrets, and configures the database connection.
Automated Setup Flow
The setup script follows a specific logic to ensure the environment is ready for the development server.
The script automates the creation of the BETTER_AUTH_SECRET using openssl rand -base64 32 and configures the DATABASE_URL based on the detected environment.
Sources: setup.sh:35-155, README.md:105-130
Core Environment Variables
The application relies on several categories of environment variables defined in the .env file. These are grouped by functional area:
Database and Authentication
These variables define the backbone of the application's persistence and security layers.
| Variable | Description | Source |
|---|---|---|
DATABASE_URL | PostgreSQL connection string (e.g., postgresql://user:pass@localhost:5432/db) | README.md:148-154 |
BETTER_AUTH_SECRET | 32-byte random string for session signing | setup.sh:75-84 |
BETTER_AUTH_URL | The base URL for authentication callbacks | README.md:156 |
NEXT_PUBLIC_APP_URL | The public origin of the application | README.md:156 |
AI Provider Configuration
ThinkEx is a multi-model platform and requires API keys for different reasoning engines.
- Google AI (Required):
GOOGLE_GENERATIVE_AI_API_KEYis mandatory for core features like distillation and autogen. Sources: README.md:120-123, src/app/api/chat/route.ts:167-170 - Google OAuth (Optional):
GOOGLE_CLIENT_IDandGOOGLE_CLIENT_SECRETenable social login. Source: README.md:125-128 - Other Providers: Support for
FIRECRAWL_API_KEY,MISTRAL_API_KEY, andAI_GATEWAY_API_KEYfor specialized tasks like web scraping and AI gateway routing. Sources: README.md:133-136, src/app/api/chat/route.ts:171
Storage Configuration
ThinkEx supports two distinct storage backends for handling user-uploaded assets like PDFs and images. This is controlled by the STORAGE_TYPE variable.
Storage Options
- Local Storage:
STORAGE_TYPE=local- Files are stored in the
./uploadsdirectory. - Recommended for simple self-hosting and local development.
- Supabase Storage:
STORAGE_TYPE=supabase- Requires
NEXT_PUBLIC_SUPABASE_URL,NEXT_PUBLIC_SUPABASE_ANON_KEY, andSUPABASE_SERVICE_ROLE_KEY. - Requires a public storage bucket named
file-upload.
Sources: README.md:173-195, setup.sh:88-100
Application Runtime Configuration
The Next.js runtime uses these variables to adjust behavior between development and production environments.
Environment-Specific Logic
In src/app/layout.tsx, the application checks the NODE_ENV to determine which assets to load:
const isDev = process.env.NODE_ENV === "development";
// Used to switch favicons and load development scripts like react-grab
Sources: src/app/layout.tsx:11-60
AI Gateway and Routing
The chat system utilizes an AI Gateway, which can be configured to route requests between different providers (e.g., Anthropic via Bedrock).
The gateway configuration uses AI_GATEWAY_API_KEY and allows for provider ordering, such as preferring bedrock over anthropic for Claude models.
Sources: src/app/api/chat/route.ts:258-285
Conclusion
Environment configuration in ThinkEx is designed to be flexible, supporting a "Quick Start" via setup.sh while allowing for deep customization of AI models and storage backends. Proper configuration of the DATABASE_URL and GOOGLE_GENERATIVE_AI_API_KEY is the minimum requirement for a functional instance. For production environments, setting NEXT_PUBLIC_APP_URL and BETTER_AUTH_SECRET is critical for secure authentication flows.