Monorepo Setup
Alchemy works seamlessly in monorepo setups, allowing you to manage multiple applications and shared infrastructure in a single repository. This guide shows you how to structure and deploy a monorepo with Alchemy.Monorepo Structure
A typical Alchemy monorepo looks like this:Setting Up a Monorepo
Resource Sharing Between Apps
Apps can import and use resources from other apps:Export Resources
apps/backend/alchemy.run.ts
Import and Use Resources
apps/frontend/alchemy.run.ts
Deployment
Deploy All Apps
Deploy all applications in dependency order:- Dependencies are deployed first
- Apps are deployed in parallel when possible
- Failures are handled gracefully
Deploy Specific App
Deploy with Stage
Destroying Resources
Destroy All Apps
- Frontend (destroys last)
- Backend and Analytics (can destroy in parallel)
Destroy Specific App
Environment Variables
Shared Environment Variables
Use a root.env file for shared configuration:
.env
App-Specific Environment Variables
Each app can have its own.env.local:
apps/backend/.env.local
Loading Environment Variables
Stages and Environments
Per-Stage Deployments
Deploy different stages of the monorepo:Environment-Specific Configuration
apps/backend/alchemy.run.ts
State Management
Each application maintains its own state:State is isolated per application and stage, allowing independent deployments.
Development Workflow
Local Development
Run all apps locally:Watch Mode
Each app can run in watch mode independently:Best Practices
Example: Complete Monorepo
Here’s a complete example monorepo:Troubleshooting
Circular Dependencies
Avoid circular imports between apps:Import Errors
Ensure package exports are configured:apps/backend/package.json
Deployment Order
Use Turborepo’sdependsOn to control order:
turbo.json
Next Steps
- Deployment - Deploy your monorepo to production
- Testing - Test your monorepo applications
- Creating Resources - Learn more about resource creation