Getting Started (Development)
Relevant source files
The following files were used as context for generating this wiki page:
This guide provides instructions for setting up the Inbox Zero project for local development. It covers prerequisites, environment configuration, running the application, and the recommended development workflow. The project is a monorepo containing the main Next.js web application (apps/web) and several shared packages.
The primary application is apps/web, which handles the user interface, authentication, API routes, and integration with external services like Gmail, AI models, and payment processors. For a more detailed overview of the project structure, refer to the Architecture documentation.
Sources: README.md, ARCHITECTURE.md:3-9
1. Prerequisites
Before you begin, ensure you have the following software installed on your system.
| Tool | Required Version | Installation Guide |
|---|---|---|
| Node.js | >= 18.0.0 | nodejs.org |
| pnpm | >= 8.6.12 | pnpm.io |
| Docker Desktop | Recommended | docker.com |
Sources: README.md:83-87
2. Local Environment Setup
The setup process involves cloning the repository, installing dependencies, configuring environment variables, and starting the required services.
2.1. Initial Setup
First, clone the repository and install the dependencies using pnpm.
# Clone the repository (not shown in source, assumed step)
git clone https://github.com/elie222/inbox-zero.git
cd inbox-zero
# Create the .env file
cp apps/web/.env.example apps/web/.env
# Install dependencies from the web app directory
cd apps/web
pnpm install
Sources: README.md:92-95
2.2. Environment Variables
The application requires several environment variables for core functionality, authentication, and third-party service integrations. These are configured in the apps/web/.env file.
General Secrets
These variables are essential for application security and session management.
| Variable | Description | Example Generation Command |
|---|---|---|
AUTH_SECRET | A random string for session encryption. | openssl rand -hex 32 |
EMAIL_ENCRYPT_SECRET | A secret key for encrypting OAuth tokens. | openssl rand -hex 32 |
EMAIL_ENCRYPT_SALT | A salt for encrypting OAuth tokens. | openssl rand -hex 16 |
INTERNAL_API_KEY | A secret key for securing internal API calls. | openssl rand -hex 32 |
NEXT_PUBLIC_BASE_URL | The public URL of your app (e.g., http://localhost:3000). | N/A |
UPSTASH_REDIS_URL | Redis URL from Upstash (can be empty if using Docker). | N/A |
UPSTASH_REDIS_TOKEN | Redis token from Upstash (can be a random string if using Docker). | N/A |
ADMINS | Comma-separated list of admin emails (e.g., admin@example.com). | N/A |
Sources: README.md:99-114, 210-211
Google OAuth Credentials
These are required for user login and accessing the Gmail API.
The following diagram illustrates the Google OAuth setup flow.
Sources: README.md:119-158
Microsoft OAuth Credentials
These are required for users who wish to connect their Microsoft Outlook accounts.
| Variable | Description |
|---|---|
MICROSOFT_CLIENT_ID | Microsoft OAuth application (client) ID. |
MICROSOFT_CLIENT_SECRET | Microsoft OAuth client secret value. |
The setup involves creating an App Registration in the Azure Portal, configuring redirect URIs (/api/auth/callback/microsoft and /api/outlook/linking/callback), and granting the necessary API permissions (e.g., Mail.ReadWrite, User.Read).
Sources: README.md:163-203
LLM Parameters
The application supports multiple Large Language Model (LLM) providers for its AI features. You must configure at least one.
Supported providers include:
- Anthropic
- OpenAI
- AWS Bedrock Anthropic
- Google Gemini
- Groq Llama 3.3 70B
- Ollama (local)
To use a local Ollama instance, set the following variables:
OLLAMA_BASE_URL=http://localhost:11434/api
NEXT_PUBLIC_OLLAMA_MODEL=phi3
DEFAULT_LLM_PROVIDER=ollama
ECONOMY_LLM_PROVIDER=ollama # Also required if DEFAULT_LLM_PROVIDER is ollama
If running the app in Docker and Ollama on the host, use http://host.docker.internal:11434/api for OLLAMA_BASE_URL.
Sources: README.md:205-224
2.3. Local Services (Postgres & Redis)
The project uses PostgreSQL for the database and Redis for caching and queueing. You can run these services locally using Docker Compose.
The diagram below shows the local development stack managed by Docker.
Run the following command from the project root to start the services:
docker-compose up -d
This command starts PostgreSQL and Redis containers in the background.
Sources: README.md:226-233
2.4. Running the Application
Once the environment is configured, run the database migrations and start the development server.
-
Run Migrations:
pnpm prisma migrate dev -
Start the Development Server:
# From project root turbo dev # Or from apps/web directory pnpm run dev
The application will be available at http://localhost:3000.
Sources: README.md:235-245, apps/web/CLAUDE.md:4
3. Docker Build & Deployment
The application can be containerized using Docker for production-like environments.
3.1. Building the Docker Image
The NEXT_PUBLIC_BASE_URL variable must be provided as a build argument because Next.js embeds public environment variables at build time.
# For production with a custom domain
docker build \
--build-arg NEXT_PUBLIC_BASE_URL="https://your-domain.com" \
-t inbox-zero \
-f docker/Dockerfile.prod .
# For local development (uses default http://localhost:3000)
docker build -t inbox-zero -f docker/Dockerfile.prod .
Important: If you change NEXT_PUBLIC_BASE_URL, you must rebuild the Docker image.
Sources: README.md:275-290, docker/DOCKER_BUILD_GUIDE.md:3-16
3.2. Running the Docker Container
Run the built image, passing runtime environment variables.
docker run -p 3000:3000 \
-e DATABASE_URL="your-database-url" \
-e AUTH_SECRET="your-auth-secret" \
-e GOOGLE_CLIENT_ID="your-google-client-id" \
# ... other runtime environment variables
inbox-zero
Sources: README.md:292-299
4. Advanced Configuration
4.1. Real-time Email Notifications (Google Pub/Sub)
To process emails in real-time, you must configure Google Pub/Sub push notifications.
The setup flow is as follows:
For local development, ngrok is recommended to expose your local server to the internet.
Sources: README.md:213-228
4.2. Cron Jobs
Certain features rely on scheduled tasks. These should be configured to run via a cron job provider.
| Path | Schedule | Description |
|---|---|---|
/api/watch/all | 0 1 * * * | Renews the watch on all Google accounts. |
/api/resend/summary/all | 0 16 * * 1 | Sends weekly digest emails. |
/api/reply-tracker/disable-unused-auto-draft | 0 3 * * * | Disables auto-draft for inactive threads. |
Sources: README.md:261-273
5. Development Workflow
The project follows a full-stack pattern using Next.js API Routes for data fetching and Server Actions for mutations.
This diagram shows the sequence for building a new feature.
This workflow ensures type safety, clear separation of concerns, and efficient data management.
Key Guidelines
- Data Fetching (GET): Use Next.js API Routes wrapped with
withAuthorwithEmailAccountmiddleware. Export the response type for client-side type safety. - Mutations (POST/PUT/DELETE): Use Server Actions with
next-safe-action. Define validation schemas using Zod. - Client-Side State: Use SWR for data fetching and caching.
- Forms: Use React Hook Form with
@hookform/resolvers/zodfor validation. - File Organization: Structure feature files logically (API route, validation schema, server action, SWR hook, component).
Sources: apps/web/CLAUDE.md:20-170