1/**
2 * Three Services connected over a private Fly network:
3 *
4 * - `Users` — private, serves `list` and `get` methods (`src/users.ts`)
5 * - `Orders` — private, binds Users (`src/orders.ts`)
6 * - `Gateway` — the only public Service, binds both (`src/gateway.ts`)
7 *
8 * Each Service is its own Fly App. All three join `Fly.stackNetwork`, a
9 * private network unique to this stack and stage, so Users and Orders are
10 * unreachable from the internet and from every other App in the org.
11 * `Fly.bindService` connects them: only a Service that binds another
12 * receives its caller token, so it can call its methods.
13 */
14import * as Alchemy from "alchemy";
15import * as Fly from "alchemy/Fly";
16import * as Effect from "effect/Effect";
17import Gateway from "./src/gateway.ts";
18import Orders from "./src/orders.ts";
19import Users from "./src/users.ts";
20
21export default Alchemy.Stack(
22 "FlyMicroservices",
23 {
24 providers: Fly.providers(),
25 state: Alchemy.localState(),
26 },
27 Effect.gen(function* () {
28 const users = yield* Users;
29 const orders = yield* Orders;
30 const gateway = yield* Gateway;
31
32 return {
33 url: gateway.url,
34 network: gateway.network,
35 usersUrl: users.url,
36 usersPrivateUrl: users.privateUrl,
37 ordersPrivateUrl: orders.privateUrl,
38 };
39 }),
40);