Self-Hosting & Docker Setup
Relevant source files
The following files were used as context for generating this wiki page:
- README.md
- setup.sh
- CONTRIBUTING.md
- src/app/api/workspaces/autogen/route.ts
- src/lib/exportToGoogleDocs.ts
- docker-compose.yml (referenced via documentation)
ThinkEx is designed to be self-hosted for local development and personal use. The architecture leverages a hybrid approach where the Next.js application runs locally to facilitate hot-reloading and active development, while infrastructure components like PostgreSQL are containerized using Docker to ensure environment consistency and simplified dependency management.
The self-hosting process is primarily driven by an interactive automation script that handles environment validation, database provisioning, and dependency installation. This setup allows developers to maintain full control over their data, choosing between local file storage or cloud-based providers.
Sources: README.md:104-106, setup.sh:1-10
Prerequisites & Environment Requirements
Before initiating the setup, the local environment must meet specific version requirements for runtime and package management.
System Requirements
- Node.js: version 20 or higher is required.
- pnpm: Used for dependency management.
- Docker & Docker Compose: Recommended for running the PostgreSQL database, though a local PostgreSQL (v12+) installation is supported.
Sources: README.md:108-113, setup.sh:91-105, CONTRIBUTING.md:27-31
Core Configuration Variables
The application requires a .env file containing specific API keys and database credentials to function correctly.
| Variable | Type | Description |
|---|---|---|
GOOGLE_GENERATIVE_AI_API_KEY | Required | API key from Google AI Studio for LLM features. |
DATABASE_URL | Required | PostgreSQL connection string (Docker or Local). |
BETTER_AUTH_SECRET | Required | Random 32-character base64 string for authentication. |
STORAGE_TYPE | Optional | local (default for self-hosting) or supabase. |
GOOGLE_CLIENT_ID | Optional | For enabling Google OAuth login. |
Sources: README.md:114-135, setup.sh:65-85
Automated Setup Workflow
The project provides a setup.sh script to automate the initialization of the development environment. This script executes a series of checks and configuration steps to ensure the system is ready for the development server.
Setup Logic Flow
The following diagram illustrates the sequence of operations performed by the automated setup script.
The script validates prerequisites, provisions the database via Docker (if available), generates authentication secrets, installs dependencies, and synchronizes the database schema before launching the Next.js development server.
Sources: setup.sh:111-300, CONTRIBUTING.md:33-41
Database Architecture & Initialization
ThinkEx utilizes PostgreSQL as its primary data store, managed through Drizzle ORM. During self-hosting, the database must be prepared with specific roles and schemas to support Row-Level Security (RLS) and application-level authentication.
Database Components
- Containerized PostgreSQL: Orchestrated via
docker-compose.yml. - Authenticated Role: A specific database role named
authenticatedmust be created to support secure data access. - Auth Schema: A mock
authschema andjwt()function are created during setup to satisfy RLS policies that the application migrations expect.
Sources: setup.sh:227-260, README.md:99-100
Initialization Commands
The setup script applies the initial schema using SQL migrations and then uses drizzle-kit to push any incremental changes.
# Push schema changes to the database
pnpm db:push
# Generate and apply migrations manually (if not using setup.sh)
pnpm drizzle-kit push --force
Sources: setup.sh:285-295, README.md:183-185
Storage Configuration
ThinkEx supports flexible storage backends for user-uploaded files like PDFs and images.
Storage Options
- Local File Storage: The recommended option for self-hosting. Files are stored in the
./uploadsdirectory. This is enabled by settingSTORAGE_TYPE=localin the.envfile. - Supabase Storage: A cloud-based alternative. Requires
NEXT_PUBLIC_SUPABASE_URL,NEXT_PUBLIC_SUPABASE_ANON_KEY, andSUPABASE_SERVICE_ROLE_KEY.
Sources: README.md:189-204, setup.sh:77-85
API & Service Integration
For a fully functional self-hosted instance, several external service integrations are required or optional.
AI Integration
The core reasoning and distillation features (like the autogen route) rely on Google's Gemini models.
- Gemini 2.5 Flash Lite: Used for content distillation and metadata generation.
- Gemini 2.5 Flash: Used for high-quality document and quiz generation.
Sources: src/app/api/workspaces/autogen/route.ts:114-118, src/app/api/workspaces/autogen/route.ts:515-520
External Tools
| Tool | Source File | Functionality |
|---|---|---|
| Web Search | autogen/route.ts | Fetches real-time data to ground AI responses. |
| YouTube API | autogen/route.ts | Searches for relevant educational videos based on workspace topics. |
| Google Docs API | exportToGoogleDocs.ts | Facilitates exporting markdown content to native Google Docs. |
Sources: src/app/api/workspaces/autogen/route.ts:122-135, src/lib/exportToGoogleDocs.ts:114-142
Conclusion
Self-hosting ThinkEx involves a standard Next.js deployment backed by a PostgreSQL database. While the project simplifies the process through its setup.sh script and Docker integration, users must provide their own API keys for Google AI services to enable the platform's core synthesis and content generation features. This architecture ensures that sensitive user data and workspace context remain under the host's direct control while leveraging powerful remote LLMs for intelligence.