Environment Configuration
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Environment configuration is a critical aspect of the Analog project, enabling developers to run the application locally and deploy it to different environments. Configuration is managed through environment variables defined in a .env file at the root of the project. This file is not committed to version control and must be created locally by copying the provided .env.example template.
These variables control essential settings, including database connections, authentication provider credentials (Google, Microsoft), and keys for various third-party services like Google Maps, Sentry, and Upstash Redis. The build system, powered by Turborepo, is configured to inject these variables into the appropriate application or package during the development and build processes.
Configuration Loading Mechanism
The Analog monorepo uses a combination of dotenv-cli and Turborepo to manage environment variables.
-
Loading
.env: The rootpackage.jsondefines scripts (build,dev,db:migrate, etc.) that are prefixed withdotenv --. This command loads the variables from the.envfile into the environment of the script being run.
Sources: package.json:5-14 -
Task-specific Injection: The
turbo.jsonfile specifies which environment variables are required for each task (e.g.,build,dev). This ensures that each part of the monorepo only has access to the environment variables it needs, improving security and predictability.
Sources: turbo.json:4-81
This diagram illustrates the flow of how environment variables are loaded and used in a development script.
Sources: package.json:6, turbo.json:4-81
Setup Process
To configure the local environment, a developer must follow these steps, as outlined in the project's documentation.
This flowchart shows the step-by-step process for a new developer to get the application running locally.
Sources: README.md, CONTRIBUTING.md
Environment Variables
The application relies on a comprehensive set of environment variables. The following table details the variables defined across turbo.json and described in the setup guides.
| Variable | Description | Source Files |
|---|---|---|
DATABASE_URL | The connection string for the PostgreSQL database. | README.md, turbo.json:7 |
BETTER_AUTH_SECRET | A secure secret for Better Auth, generated using openssl rand -hex 32. | README.md, turbo.json:8 |
BETTER_AUTH_URL | The base URL for the Better Auth service. | README.md, turbo.json:9 |
GOOGLE_CLIENT_ID | The client ID for Google OAuth, obtained from the Google Cloud Console. | README.md, turbo.json:11 |
GOOGLE_CLIENT_SECRET | The client secret for Google OAuth. | README.md, turbo.json:12 |
GOOGLE_MAPS_API_KEY | API key for Google Places API, used for location features. | README.md, turbo.json:13 |
NEXT_PUBLIC_GOOGLE_MAPS_API_KEY | The public version of the Google Maps API key for client-side usage. | turbo.json:14 |
MICROSOFT_CLIENT_ID | The client ID for Microsoft OAuth, from the Azure Portal. | README.md, turbo.json:20 |
MICROSOFT_CLIENT_SECRET | The client secret for Microsoft OAuth. | README.md, turbo.json:21 |
UPSTASH_REDIS_REST_URL | The REST URL for the Upstash Redis instance, used for rate limiting and caching. | turbo.json:16 |
UPSTASH_REDIS_REST_TOKEN | The REST token for the Upstash Redis instance. | turbo.json:17 |
NEXT_PUBLIC_SENTRY_DSN | The public DSN for Sentry, used for client-side error tracking. | turbo.json:24 |
SENTRY_AUTH_TOKEN | Auth token for Sentry to upload source maps. | turbo.json:25 |
SENTRY_DSN | The DSN for Sentry for server-side error tracking. | turbo.json:26 |
VERCEL_URL | The URL of the deployment on Vercel. | turbo.json:15 |
NEXT_RUNTIME | Specifies the Next.js runtime environment (e.g., 'nodejs'). | turbo.json:33 |
ZOOM_CLIENT_ID | Client ID for Zoom integration. | turbo.json:22 |
ZOOM_CLIENT_SECRET | Client secret for Zoom integration. | turbo.json:23 |
MARBLE_WORKSPACE_KEY | Workspace key for Marble CMS. | turbo.json:29 |
MARBLE_API_URL | API URL for Marble CMS. | turbo.json:30 |
UNKEY_ROOT_KEY | Root key for the Unkey service. | turbo.json:31 |
SIMPLE_ANALYTICS_HOSTNAME | Hostname for Simple Analytics integration. | turbo.json:18 |
Sources: README.md, CONTRIBUTING.md, turbo.json:5-34
Sentry Configuration
Sentry is integrated for error monitoring and is configured in apps/web/next.config.ts. The configuration is wrapped around the main Next.js config using withSentryConfig. It uses the CI environment variable to control logging verbosity and sets up a tunnel route at /monitoring to avoid ad-blockers.
// File: apps/web/next.config.ts
export default withSentryConfig(withSimpleAnalytics(nextConfig), {
// ...
// Only print logs for uploading source maps in CI
silent: !process.env.CI,
// ...
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
tunnelRoute: "/monitoring",
// ...
});
Sources: apps/web/next.config.ts:111-125
Conclusion
The environment configuration of Analog is robust and well-defined, leveraging standard tools like .env files and dotenv-cli. The integration with Turborepo ensures that build and development tasks are hermetic and receive only the necessary configuration, which is a best practice for monorepo development. A clear setup process documented in the README.md allows new contributors to get started quickly, while the comprehensive set of variables provides the flexibility to connect to all required external and internal services.