Write your logic once. Compile it everywhere.
Bridge lets you define business logic in a clean .bridge syntax and compile it into PHP (Laravel), TypeScript, and Node.js (ESM) — all from a single source of truth.
- Installation
- Quick Start
- Commands
- The
.bridgeSyntax - Configuration
- Output Examples
- Reverse Compilation
- VS Code Extension
npm install -g @cas8398/bridge-cliVerify the install:
bridge --help# 1. Create a new project
bridge new my-app
cd my-app
# 2. Edit your logic
# src/logic.bridge is created automatically — open it and define your functions
# 3. Compile to all targets
bridge buildAfter bridge build, your outputs land in .bridge/:
my-app/
├── .bridge/
│ ├── php/ ← Laravel-ready PHP class
│ ├── ts/ ← TypeScript with typed signatures
│ └── node/ ← Node.js ESM module
├── bridge.config.json
└── src/
└── logic.bridge
| Command | Description |
|---|---|
bridge new <name> |
Scaffold a new Bridge project |
bridge build |
Compile all .bridge files in src/ to configured targets |
bridge to-bridge <file> |
Reverse-compile a PHP or TS file back into .bridge syntax |
bridge help |
Show available commands |
Bridge uses a TypeScript-like syntax with a small set of familiar types.
function calculateTotal(price: float, tax: float): float {
let total = price * (1 + tax)
return total
}
Supported types
| Bridge type | PHP | TypeScript / Node |
|---|---|---|
float |
float |
number |
int |
int |
number |
string |
string |
string |
bool |
bool |
boolean |
bridge.config.json controls what gets compiled and where:
{
"src": "src",
"outDir": ".bridge",
"targets": ["php", "ts", "node"],
"preserveName": true
}| Field | Default | Description |
|---|---|---|
src |
"src" |
Directory containing your .bridge source files |
outDir |
".bridge" |
Output directory for compiled files |
targets |
["php","ts","node"] |
Compile targets — any combination of php, ts, node |
preserveName |
true |
Keep the original filename casing in output |
Given this source:
// src/logic.bridge
function calculateTotal(price: float, tax: float): float {
let total = price * (1 + tax)
return total
}
TypeScript (.bridge/ts/logic.ts)
/**
* Generated by Bridge from logic.bridge
*/
export function calculateTotal(price: number, tax: number): number {
let total = price * (1 + tax);
return total;
}Node.js ESM (.bridge/node/logic.js)
/**
* Generated by Bridge from logic.bridge
* Target: Node.js (Bare JavaScript)
*/
export function calculateTotal(price, tax) {
let total = price * (1 + tax);
return total;
}PHP / Laravel (.bridge/php/Logic.php)
<?php
namespace App\Bridge;
/**
* Generated by Bridge
*/
class Logic
{
public function calculateTotal(float $price, float $tax): float
{
$total = $price * (1 + $tax);
return $total;
}
}You can reverse an existing PHP or TypeScript file back into .bridge syntax:
bridge to-bridge .bridge/php/Logic.phpThe reversed file lands in .bridge/to-bridge/. Move it to src/ to include it in future builds:
mv .bridge/to-bridge/Logic.bridge src/Note:
to-bridgeworks best on files that were originally compiled by Bridge. Hand-written PHP or TS with complex patterns may not reverse cleanly.
Get syntax highlighting and snippets for .bridge files:
👉 Bridge Language Support on the VS Code Marketplace