Monorepo Structure
Relevant source files
The following files were used as context for generating this wiki page:The Inbox Zero repository is a monorepo that houses multiple applications and shared packages. This structure facilitates code sharing, centralized dependency management, and streamlined development workflows. The monorepo is managed using pnpm workspaces and optimized for build and task execution with Turborepo.
The architecture is centered around two primary applications: a main web application and a specialized unsubscriber service. These are supported by a collection of reusable packages for concerns like configuration, analytics, and email services. The project also includes dedicated directories for database management, content management, state management, and containerization.
Sources: ARCHITECTURE.md, README.md:39-42
High-Level Overview
The repository is organized into several key top-level directories, each with a distinct responsibility. The apps directory contains deployable applications, while packages holds shared code. Other directories support concerns like database schemas, state management, and configuration.
The following diagram illustrates the main components of the monorepo structure.
Sources: ARCHITECTURE.md:5-18
Core Components
Applications (apps)
The apps directory contains the main, user-facing applications of the project.
Sources: ARCHITECTURE.md:5-8
| Application | Framework(s) | Description |
|---|---|---|
web | Next.js (App Router) | The primary user-facing web application. It handles the frontend, user authentication, and API routes for backend logic. It is the main application in production. |
unsubscriber | Fastify, Playwright | A lightweight, separate service for handling automated email unsubscriptions using browser automation and AI. |
Sources: ARCHITECTURE.md:19-49
Shared Packages (packages)
The packages directory contains reusable libraries, configurations, and utilities that are shared across the different applications in the monorepo. This promotes code reuse and consistency.
The main web application consumes these packages as workspace dependencies.
// apps/web/package.json
"dependencies": {
"@inboxzero/loops": "workspace:*",
"@inboxzero/resend": "workspace:*",
"@inboxzero/tinybird": "workspace:*",
"@inboxzero/tinybird-ai-analytics": "workspace:*",
// ...
}
Sources: apps/web/package.json:28-32, ARCHITECTURE.md:51-53
The following diagram shows how applications depend on the shared packages.
Key packages include:
| Package | Description |
|---|---|
eslint-config | Shared ESLint configurations for consistent code style. |
loops | Related to marketing email automation. |
resend | Integration with Resend for sending transactional emails, such as digests. |
tinybird | Integration with Tinybird for real-time analytics. |
tinybird-ai-analytics | Integration with Tinybird specifically for AI usage analytics. |
tsconfig | Shared TypeScript configurations. |
Sources: ARCHITECTURE.md:54-62, packages/resend/emails/digest.tsx
Supporting Directories
Several other top-level directories provide critical functionality for the applications.
| Directory | Purpose |
|---|---|
prisma/ | Manages the PostgreSQL database schema and migrations using Prisma. |
sanity/ | Contains configuration for integrating with Sanity.io as a headless CMS for blog content. |
store/ | Implements client-side state management using Jotai and defines queues for background tasks. |
utils/ | Houses shared utility functions, Next.js Server Actions, and core logic for AI and Gmail API interactions. |
docker/ | Contains Docker configurations for containerizing the applications. |
Sources: ARCHITECTURE.md:64-101
Build and Development
The monorepo uses pnpm for package management and Turborepo to manage and optimize scripts across the workspaces.
Development
To run the application in development mode, the turbo dev command is used from the project root. This command, as configured in README.md, executes the dev script within each application package.
# From project root
turbo dev
Sources: README.md:209-212
The dev script in the apps/web package starts the Next.js development server with Turbopack enabled.
// apps/web/package.json
"scripts": {
"dev": "cross-env NODE_OPTIONS=--max_old_space_size=16384 next dev --turbopack",
"build": "cross-env NODE_OPTIONS=--max_old_space_size=16384 prisma migrate deploy && next build",
"start": "next start",
"lint": "next lint",
"test": "cross-env RUN_AI_TESTS=false vitest",
"test-ai": "cross-env RUN_AI_TESTS=true vitest"
}
Sources: apps/web/package.json:5-12
Containerization
The project uses Docker for creating reproducible development and production environments.
- Development: A
docker-compose.ymlfile is provided to run Postgres and Redis services locally. - Production: A
Dockerfile.prod(referenced indocker/DOCKER_BUILD_GUIDE.md) is used to build a production-ready image of thewebapplication.
A key aspect of building the Docker image is the handling of NEXT_PUBLIC_ environment variables. Since these are embedded at build time by Next.js, they must be passed as build arguments to the docker build command.
# Example build command for production
docker build \
--build-arg NEXT_PUBLIC_BASE_URL="https://your-domain.com" \
-t inbox-zero \
-f docker/Dockerfile.prod .
Sources: README.md:195-197, 240-249, docker/DOCKER_BUILD_GUIDE.md:19-23
Configuration
Environment Variables
The project relies heavily on environment variables for configuration. The apps/web/env.ts file uses @t3-oss/env-nextjs to validate and type-check environment variables for both server and client. This ensures that all required variables are present at runtime.
Key configured areas include:
- Database and Redis connections (
DATABASE_URL,UPSTASH_REDIS_URL) - Authentication providers (
GOOGLE_CLIENT_ID,MICROSOFT_CLIENT_ID) - LLM providers and API keys (
OPENAI_API_KEY,ANTHROPIC_API_KEY, etc.) - Payment and analytics services (
LEMON_SQUEEZY_API_KEY,TINYBIRD_TOKEN) - Internal and external API keys (
INTERNAL_API_KEY,RESEND_API_KEY)
Sources: apps/web/env.ts:8-144
Next.js Configuration
The apps/web/next.config.ts file configures the main web application. It includes settings for:
- Redirects and Rewrites: Manages URL paths for marketing links, proxies, and legacy routes.
- Security Headers: Sets strict Content Security Policy (CSP),
X-Frame-Options, and other security-related HTTP headers. - Service Workers: Configured with
@serwist/nextto enable PWA capabilities. - Integrations: Wrapped with Sentry and Axiom for error tracking and logging.
Sources: apps/web/next.config.ts
Conclusion
The Inbox Zero monorepo is a well-structured project that leverages modern tools like pnpm and Turborepo to manage its complexity. By separating concerns into distinct applications (apps) and reusable modules (packages), the architecture promotes code sharing, maintainability, and a consistent development experience. The clear separation of concerns in directories like prisma, sanity, and docker further enhances the project's organization and scalability.
Sources: ARCHITECTURE.md, README.md