How to Use Watt with Multiple Repository Applications
Problem
You need to build a microservices application where:
- Applications are developed and maintained in separate Git repositories or npm packages in public or private registries
- Different teams work on different applications independently
- You want to combine applications from multiple repos into a single Watt application
- You need flexible application resolution for local development vs. production
When to use this solution:
- Large organizations with multiple development teams
- Microapplications architectures with independent application deployment
- Need to combine applications from different repositories for integration testing
- Want to maintain application independence while enabling orchestration
Solution Overview
Watt's multi-repository application resolution allows you to:
- Define applications from different Git repositories or npm packages in your main application
- Automatically resolve and integrate applications from remote repositories or npm packages
- Override application locations for local development
- Build and deploy unified applications from distributed applications
This guide shows you how to set up and manage a Watt application with multi-repository applications.
Prerequisites
Before starting, ensure you have:
- Node.js (v22.19.0+)
- npm (comes with Node.js)
- Git access to your application repositories
- A code editor (e.g., Visual Studio Code)
Step 1: Create Your Project
1. Prepare your project:
mkdir my-microapplications-app
cd my-microapplications-app
2. Configure application resolution in package.json:
{
"name": "my-microapplications-app",
"private": true,
"scripts": {
"dev": "wattpm dev",
"resolve": "wattpm-utils resolve",
"build": "wattpm build",
"start": "wattpm start"
},
"dependencies": {
"@platformatic/runtime": ">=3.0.0",
"@platformatic/next": ">=3.0.0",
"@platformatic/node": ">=3.0.0",
"wattpm": ">=3.0.0"
},
"workspaces": ["web/*", "external/*"]
}
3. Create directory structure for applications:
mkdir -p web/ external/
What this setup provides:
web/- Directory for resolved web applicationsexternal/- Directory for resolved external applicationswattpm-utils resolvecommand for application resolution- Workspace configuration for multi-application management
Step 2: Configure Multi-Repository Applications
Define Applications in watt.json
Configure your watt.json to include applications from multiple repositories:
{
"$schema": "https://schemas.platformatic.dev/@platformatic/runtime/3.0.0.json",
"web": [
{
"id": "gateway",
"path": "web/gateway"
},
{
"id": "user-application",
"path": "{PLT_USER_APPLICATION_PATH}",
"url": "https://github.com/your-org/user-application.git"
},
{
"id": "product-application",
"path": "{PLT_PRODUCT_APPLICATION_PATH}",
"url": "https://github.com/your-org/product-application.git"
},
{
"id": "frontend",
"path": "{PLT_FRONTEND_PATH}",
"url": "npm:@your-org/frontend"
}
]
}
Configuration explanation:
- Local applications (like
composer) use direct paths - Remote applications use environment variables for paths + Git URLs
- Environment variables allow flexible local vs. remote resolution
- Git URLs define where to fetch applications when not available locally
Repository Architecture Example
Organization Structure:
├── my-microapplications-app/ # Main orchestration app
│ ├── watt.json # Application definitions
│ ├── package.json # Workspace configuration
│ └── web/ # Resolved applications appear here
├── user-application/ # Separate repository
│ ├── package.json
│ └── platformatic.json
├── product-application/ # Separate repository
│ ├── package.json
│ └── platformatic.json
└── nextjs-frontend/ # Separate repository
├── package.json
└── next.config.js
Step 3: Configure Environment Variables
Local Development Configuration
Create a .env file for local development:
# Local application paths (when developing locally)
PLT_USER_APPLICATION_PATH=../user-application
PLT_PRODUCT_APPLICATION_PATH=../product-application
PLT_FRONTEND_PATH=../nextjs-frontend
# Production paths (when applications are resolved from Git)
# PLT_USER_APPLICATION_PATH=web/user-application
# PLT_PRODUCT_APPLICATION_PATH=web/product-application
# PLT_FRONTEND_PATH=web/frontend
Production Configuration
For production deployments, applications are resolved from Git repositories:
# Production environment - applications resolved from Git
PLT_USER_APPLICATION_PATH=web/user-application
PLT_PRODUCT_APPLICATION_PATH=web/product-application
PLT_FRONTEND_PATH=web/frontend
Git Configuration
Update your main repository's .gitignore:
# Ignore resolved applications - they come from other repos
web/*
external/*
!web/.gitkeep
!external/.gitkeep
# Standard Node.js ignores
node_modules/
.env
.env.local
dist/
build/
Why ignore resolved applications:
- Applications are pulled from their own repositories or npm packages
- Prevents committing resolved application code to main repo
- Keeps main repo focused on orchestration configuration