Skip to main content
Version: 2.40.0

Using Watt for Multi-Repository Service

This guide explains how to use Watt to resolve and manage services from different git repositories, build and start your application. You'll learn how to set up, configure, and run a Watt application with multi-repository service resolution.

Prerequisites

Before beginning, ensure you have installed:

Project Setup

Creating Your Watt Application

To create a new Watt application, please refer to our Watt setup guide.

Adding Service Resolution

By default, the wattpm resolve command isn't included in your Watt application's package.json. You have two options to use it:

  1. Run directly via CLI:
npx wattpm resolve {repository name and directory path}
  1. Add it to your package.json:
{
"name": "with-resolve",
"private": true,
"scripts": {
"dev": "wattpm dev",
"resolve": "wattpm resolve",
"build": "wattpm build",
"start": "wattpm start"
},
"dependencies": {
"@platformatic/runtime": "2.21.0",
"@platformatic/next": "2.21.0",
"@platformatic/node": "2.21.0",
"wattpm": "2.21.0"
},
"devDependencies": {
"platformatic": "2.21.0"
},
"workspaces": [
"web/*",
"external/*"
]
}

Multi-Repository Structure Setup

Repository Organization

When working with multiple repositories in Watt, you'll typically have:

  1. A main application repository containing your Watt configuration
  2. One or more service repositories containing individual services

Setting Up the Main Repository

  1. Create your main application repository:
mkdir my-watt-app
cd my-watt-app
git init
  1. Initialize your Watt application:
npx wattpm@latest init
  1. Create the directory structure for external services:
mkdir -p web/
mkdir -p external/

Adding Service Repositories

  1. Update your root watt.json file to define your service repositories:
 "web": [
{
"id": "composer",
"path": "web/composer"
},
{
"id": "app",
"path": "web/app"
},
{
"id": "node",
"path": "{PLT_NODE_PATH}",
"url": "YOUR_SERVICE_GITHUB_URL"
},
{
"id": "next",
"path": "{PLT_NEXT_PATH}",
"url": "YOUR_SERVICE_GITHUB_URL"
}
],

Version Control Configuration

  1. Update your main repository's .gitignore:
# Ignore resolved services
web/*
external/*
!web/.gitkeep
!external/.gitkeep

# Node modules
node_modules/

# Environment variables
.env
  1. Update your package.json

In your root package.json file and update your workspace to include service workspaces:

{
"workspaces": [
"web/services/*",
"external/services/*"
]
}

Working with Services

Resolving Services

To resolve services located in the web folder of your Watt application, run the below command:

npm run resolve

This command fetches and unifies all required services.

Building the Application

npm run build

This command builds the application with all resolved services.

Starting the Application

Run the command below to start your application in development mode:

npm run dev

To run your application in production mode, run the command below:

npm start 

Local Development Configuration

Watt provides flexible options for service resolution during local development. You can configure services to resolve from local directories instead of Git repositories.

Environment Variables

Configure local development using these environment variables:

  • PLT_NODE_PATH: Specifies local Node.js service directories
  • PLT_NEXT_PATH: Specifies local Next.js service directories

Example configuration:

export PLT_NODE_PATH=/path/to/local/service
export PLT_NEXT_PATH=/path/to/local/nextjs/service

Additional Resources