An orders service in TypeScript takes POST /v1/orders, and publishes an order.placed event to Kafka. A notifications service in Go receives it. Neither service knows the other's language: both are generated from one contract, contracts/orders.weft.
flowchart LR
C["curl"] -- "POST /v1/orders" --> O["<b>orders</b><br>TypeScript · Express"]
O -- "order.placed" --> K[("Kafka")]
K -- "order.placed" --> N["<b>notifications</b><br>Go · franz-go"]
| Folder | What it is |
|---|---|
contracts/ |
The shared contract: types, the order.placed event and the HTTP routes |
typescript-orders/ |
The orders service: weft.http on Express, weft.kafka on KafkaJS |
go-notifications/ |
The notifications service: weft.kafka on franz-go |
docker-compose.yaml |
A single Kafka broker |
You need Node 22 or later, Go 1.26 or later, and Docker. Start Kafka:
docker compose up -d --wait
export KAFKA_BROKERS=127.0.0.1:9092In one terminal, the Go service:
cd go-notifications
go run .In another, the TypeScript service:
cd typescript-orders
npm install
npm startPlace an order:
curl -X POST localhost:3000/v1/orders \
-H 'content-type: application/json' \
-d '{"customerId":"c-42","items":[{"sku":"apple","qty":3},{"sku":"pear","qty":1}]}'The Go service prints the order, with the same typed fields the TypeScript service sent:
order 3b311adf-a4d3-49f3-9301-fad5262c4bae from c-42: 2 items, total 2000 EUR
- A wrong body is rejected before your code runs. Send
{"customerId": 1}and you get a400with a problem details body that namesbody.customerId. - A missing order is a 404 without code.
GET /v1/orders/{id}returnsOrder?in the contract, so returningundefinedanswers404. - A wrong payload does not compile. In
typescript-orders/src/main.ts, publishorder.placedwith a field missing, andnpm run checkpoints at it. - Change the contract. Add a field to
Orderincontracts/orders.weft, runweft genin both folders, and both services get it.
The generated files, typescript-orders/src/weft.gen.ts and go-notifications/weft.gen.go, are checked in. To regenerate them, install the CLI and run weft gen in each folder:
cargo install --git https://github.com/weft-sdk/weft weft-cli --locked
(cd typescript-orders && weft gen)
(cd go-notifications && weft gen)