DEV Community

Cover image for Bridge: Write Logic Once, Compile Everywhere | Cahyanudien Blogs
Cahyanudien Aziz Saputra
Cahyanudien Aziz Saputra

Posted on • Originally published at blog.cahyanudien.site

Bridge: Write Logic Once, Compile Everywhere | Cahyanudien Blogs

Sometimes the problem isn’t complexity.

It’s repetition.


The Problem I Keep Hitting

In almost every project, I end up writing the same logic twice.

  • Validation rules
  • Price calculations
  • Data transformations

Once in backend (PHP),
and again in frontend (TypeScript).

It’s not hard.
But it’s fragile.

One change → forget to sync → subtle bug.

And over time, that duplication becomes technical debt.


The Idea

What if the logic itself was the source of truth?

Not PHP. Not TypeScript.

Just logic.

So I started experimenting with a small language:

function calculateTax(price: float, rate: float): float {
  let tax = price * rate
  return tax
}
Enter fullscreen mode Exit fullscreen mode

Then compile it into:

  • PHP (for backend)
  • TypeScript (for frontend)
  • Node.js (for shared tooling)

That became Bridge.


What Bridge Actually Is

Bridge is not a framework.

It’s a CLI compiler.

  • Input: .bridge file
  • Output: real code (PHP / TS / Node)

No runtime.
No magic.

Just transformation.


Why Not Just Use JSON / Schema?

I asked myself the same thing.

Schemas are good for structure.
But logic is more than structure.

You can’t express:

  • calculations
  • conditional logic
  • transformations

…cleanly in JSON.

Bridge sits in that gap:

structured logic, not just structured data


What I Built

I kept it intentionally small.

  • Lexer → tokenize input
  • Parser → build AST
  • Compiler → generate target code

Each target has its own emitter:

  • PHP
  • TypeScript
  • Node.js

Nothing fancy. Just predictable output.


Example Output

Bridge:

function calculateTax(price: float, rate: float): float {
  let tax = price * rate
  return tax
}
Enter fullscreen mode Exit fullscreen mode

TypeScript:

export function calculateTax(price: number, rate: number): number {
  const tax = price * rate;
  return tax;
}
Enter fullscreen mode Exit fullscreen mode

PHP:

function calculateTax(float $price, float $rate): float {
  $tax = $price * $rate;
  return $tax;
}
Enter fullscreen mode Exit fullscreen mode

Same logic.
Different runtimes.


Tooling (Important Part)

A language without tooling is painful.

So I built a simple VS Code extension:

  • syntax highlighting
  • snippets

👉 https://marketplace.visualstudio.com/items?itemName=FlagoDNA.bridge-vscode

And the CLI:
👉 https://www.npmjs.com/package/@cas8398/bridge-cli

Source code:


Limitations (on purpose)

Bridge is not trying to replace real languages.

Right now:

  • No classes
  • No async
  • No complex types

It focuses on:

small, deterministic business logic

That constraint is intentional.


What I Learned

1. Small tools are easier to reason about

The moment it tries to do everything, it becomes another language problem.

2. Determinism matters more than features

Same input → same output builds trust.

3. Most logic duplication is boring, not complex

And boring problems are perfect for automation.


Where This Might Go

  • Better type system
  • More targets (Python, Go)
  • Watch mode (bridge watch)
  • Real-world integrations

Or maybe it stays small.

That’s fine too.


Closing

Bridge is just an attempt to reduce friction.

Not a big framework.
Not a new ecosystem.

Just a small layer between logic and implementation.


If this resonates with you, try it.
Or break it. Both are useful.

Top comments (0)