sailfork / t3code-github / .repos/ alchemy-effect/ website/ src/ pages/ compare.astro

---
import Marketing from "../layouts/Marketing.astro";
import Button from "../components/marketing/Button.astro";
import AlchemicalDivider from "../components/marketing/AlchemicalDivider.astro";
import Yantra from "../brand/Yantra.astro";
import TestLoop from "../components/compare/TestLoop.astro";
import OneLine from "../components/compare/OneLine.astro";
import CodeBlock from "../components/marketing/CodeBlock.astro";

const TOOLS = ["Alchemy", "SST", "Pulumi", "Terraform", "AWS CDK"] as const;

// ---------- more than IaC: the same app, split vs together ----------
const IAC_INFRA_SRC = `export const Uploads = Cloudflare.R2.Bucket("Uploads");

export const Api = Cloudflare.Worker("Api", {
  main: "./src/api.ts",
  env: { Uploads },
});`;

const IAC_HANDLER_SRC = `export default {
  async fetch(request: Request, env: Env) {
    const obj = await env.Uploads.get("hello.txt");
    return obj
      ? new Response(await obj.text())
      : new Response("Not found", { status: 404 });
  },
};`;

const IAE_SRC = `export const Uploads = Cloudflare.R2.Bucket("Uploads");

export default Cloudflare.Worker(
  "Api",
  { main: import.meta.url },
  Effect.gen(function* () {
    const bucket = yield* Cloudflare.R2.ReadWriteBucket(Uploads);

    return {
      fetch: Effect.gen(function* () {
        const obj = yield* bucket.get("hello.txt");
        return obj
          ? HttpServerResponse.text(yield* obj.text())
          : HttpServerResponse.text("Not found", { status: 404 });
      }),
    };
  }).pipe(Effect.provide(Cloudflare.R2.ReadWriteBucketBinding)),
);`;

// One row per dimension; the first cell is Alchemy.
const ROWS: {
    label: string;
    cells: [string, string, string, string, string];
}[] = [
    {
        label: "Language",
        cells: [
            "TypeScript + Effect",
            "TypeScript + Go",
            "TypeScript, Python, Go, C#, Java",
            "HCL",
            "TypeScript, Python, Java, C#, Go",
        ],
    },
    {
        label: "Built on",
        cells: [
            "Pure TypeScript, end to end",
            "Pulumi, mostly bridged Terraform providers",
            "A Go engine, many providers bridged from Terraform",
            "A Go engine and Go provider plugins",
            "CloudFormation, a managed engine inside AWS",
        ],
    },
    {
        label: "Infrastructure and app code together",
        cells: ["Yes, as typed Effects and Layers", "No", "No", "No", "No"],
    },
    {
        label: "Permissions",
        cells: [
            "Derived from the bindings your code uses",
            "Granted by link",
            "Unenforced",
            "Unenforced",
            "Granted by grant\u2060*\u2060() calls",
        ],
    },
    {
        label: "Runs locally",
        cells: [
            "Emulated on your machine",
            "No, it deploys to the cloud",
            "No",
            "No",
            "No",
        ],
    },
    {
        label: "Tests against real infrastructure",
        cells: [
            "Deploy, assert, destroy from bun test or Vitest",
            "No",
            "No",
            "No",
            "No",
        ],
    },
];

// ---------- engine: what sits between your code and the cloud ----------
type Layer = { name: string; sub: string };
const ENGINES: {
    tool: string;
    file: string;
    layers: Layer[];
    note: string;
    ours?: boolean;
}[] = [
    {
        tool: "Alchemy",
        file: "alchemy.run.ts",
        ours: true,
        note: "1 runtime · TypeScript",
        layers: [{ name: "Alchemy", sub: "TypeScript + Effect" }],
    },
    {
        tool: "SST",
        file: "sst.config.ts",
        note: "3 layers · TypeScript → Go",
        layers: [
            { name: "SST", sub: "Go CLI" },
            { name: "Pulumi engine", sub: "Go" },
            { name: "Terraform provider", sub: "Go, through a bridge" },
        ],
    },
    {
        tool: "Pulumi",
        file: "index.ts",
        note: "2 layers · gRPC between them",
        layers: [
            { name: "Pulumi engine", sub: "Go" },
            {
                name: "Provider plugin",
                sub: "often a bridged Terraform provider",
            },
        ],
    },
    {
        tool: "Terraform",
        file: "main.tf",
        note: "2 layers · HCL → Go",
        layers: [
            { name: "Terraform core", sub: "Go" },
            { name: "Provider plugin", sub: "Go" },
        ],
    },
];
// Nested boxes, outermost first (built as HTML because Astro templates
// can't recurse inline). All strings are constants above.
const nest = (layers: Layer[]): string =>
    layers.reduceRight(
        (inner, l, i) =>
            `<div class="dg-layer" style="--depth:${i}"><span class="dg-layer__name">${l.name}<small>${l.sub}</small></span>${inner}</div>`,
        "",
    );

// ---------- local dev: where one request goes ----------
// Each trace is a request's path, one hop per node, on one of two lanes.
// Every hop across the network line is marked; Alchemy's never leaves the
// machine.
// `hold` pauses the dot on that hop for that many seconds and shows a
// progress bar on its box (e.g. a deploy the request has to wait for).
// Lanes: "m" your machine, "c" cloud, "b" on the network boundary (a step
// that runs locally but pushes to the cloud, like a deploy).
// `key` identifies the same box across Alchemy's dev modes so it can animate.
type Hop = {
    label: string;
    lane: "m" | "c" | "b";
    hold?: number;
    key?: string;
};
const TRACE_H = 170;
const NET_Y_ = 85;
const LANE_Y = { m: 46, c: 124, b: NET_Y_ };
const NET_Y = NET_Y_;
const STEP = 128;
const X0 = 70;
type DevMode = {
    id: string;
    headline: string;
    sub: string;
    hops: Hop[];
};
// Alchemy's row is interactive: drag Lambda or DynamoDB across the network
// line (`remote()` in `alchemy dev`). Both in the cloud means every edit is a
// deploy. Boxes are matched across modes by `key`.
const ALCHEMY_MODES: DevMode[] = [
    {
        id: "local",
        headline: "0 round trips",
        sub: "Runs offline. Edits reload in place.",
        hops: [
            { label: "browser", lane: "m", key: "src" },
            { label: "Lambda · Docker", lane: "m", key: "fn" },
            { label: "DynamoDB · floci", lane: "m", key: "db" },
        ],
    },
    {
        id: "remote-data",
        headline: "1 round trip",
        sub: "remote() puts DynamoDB in the real cloud. Your Lambda still runs locally.",
        hops: [
            { label: "browser", lane: "m", key: "src" },
            { label: "Lambda · Docker", lane: "m", key: "fn" },
            { label: "DynamoDB", lane: "c", key: "db" },
        ],
    },
    {
        id: "remote-fn",
        headline: "2 round trips",
        sub: "remote() deploys the Lambda for real. It still reads and writes your local DynamoDB.",
        hops: [
            { label: "browser", lane: "m", key: "src" },
            { label: "Lambda", lane: "c", key: "fn" },
            { label: "DynamoDB · floci", lane: "m", key: "db" },
        ],
    },
    {
        id: "deploy",
        headline: "Deploy each edit",
        sub: "With the whole stack in remote(), dev redeploys it for real as you edit.",
        hops: [
            { label: "edit", lane: "m", key: "src" },
            // Half the Terraform row's hold: no engine or provider plugins to start.
            { label: "deploy", lane: "b", hold: 2.4, key: "deploy" },
            { label: "Lambda", lane: "c", key: "fn" },
            { label: "DynamoDB", lane: "c", key: "db" },
        ],
    },
];
const TRACES: {
    tool: string;
    ours?: boolean;
    headline: string;
    sub: string;
    hops: Hop[];
    modes?: DevMode[];
}[] = [
    { tool: "Alchemy", ours: true, ...ALCHEMY_MODES[0]!, modes: ALCHEMY_MODES },
    {
        tool: "SST",
        headline: "3 round trips",
        sub: "Per request, through a deployed stage. Needs a connection.",
        hops: [
            { label: "browser", lane: "m" },
            { label: "API Gateway", lane: "c" },
            { label: "Lambda stub", lane: "c" },
            { label: "your code", lane: "m" },
            { label: "DynamoDB", lane: "c" },
        ],
    },
    {
        tool: "Pulumi & Terraform",
        headline: "Deploy first",
        sub: "No local runtime. Every change is a redeploy.",
        hops: [
            { label: "edit", lane: "m" },
            { label: "deploy", lane: "b", hold: 4.8 },
            { label: "Lambda", lane: "c" },
            { label: "DynamoDB", lane: "c" },
        ],
    },
];
const SPAN = 520;
const traceGeom = (hops: Hop[], opts: { fullSpan?: boolean } = {}) => {
    // Short traces spread out; long ones use the default step. Alchemy's
    // modes always span the full width so their paths share start and end.
    const step = opts.fullSpan
        ? SPAN / Math.max(1, hops.length - 1)
        : Math.max(STEP, Math.min(190, SPAN / Math.max(1, hops.length - 1)));
    const pts = hops.map((h, i) => ({
        ...h,
        x: X0 + i * step,
        y: LANE_Y[h.lane],
        w: Math.max(h.label.length * 6.9 + 24, h.hold ? 96 : 0),
    }));
    const segs = pts.slice(1).map((b, i) => {
        const a = pts[i]!;
        return a.lane === b.lane
            ? `M ${a.x} ${a.y} L ${b.x} ${b.y}`
            : `M ${a.x} ${a.y} C ${a.x + step / 2} ${a.y}, ${b.x - step / 2} ${b.y}, ${b.x} ${b.y}`;
    });
    const crosses = (a: Hop, b: Hop) =>
        a.lane !== b.lane && a.lane !== "b" && b.lane !== "b";
    const crossings = pts
        .slice(1)
        .flatMap((b, i) =>
            crosses(pts[i]!, b) ? [{ x: (pts[i]!.x + b.x) / 2, y: NET_Y }] : [],
        );

    // Motion timing for the traveling dot: constant speed, except it slows
    // to a crawl for CROSS_WINDOW px either side of each network crossing.
    const bezierLength = (a: (typeof pts)[number], b: (typeof pts)[number]) => {
        const p = [
            [a.x, a.y],
            [a.x + step / 2, a.y],
            [b.x - step / 2, b.y],
            [b.x, b.y],
        ] as const;
        let len = 0;
        let prev = p[0];
        for (let k = 1; k <= 32; k++) {
            const t = k / 32,
                u = 1 - t;
            const q = [0, 1].map(
                (d) =>
                    u * u * u * p[0][d]! +
                    3 * u * u * t * p[1][d]! +
                    3 * u * t * t * p[2][d]! +
                    t * t * t * p[3][d]!,
            ) as [number, number];
            len += Math.hypot(q[0] - prev[0], q[1] - prev[1]);
            prev = q;
        }
        return len;
    };
    let total = 0;
    const crossAt: number[] = [];
    const nodeAt = [0];
    pts.slice(1).forEach((b, i) => {
        const a = pts[i]!;
        const len =
            a.lane === b.lane
                ? Math.hypot(b.x - a.x, b.y - a.y)
                : bezierLength(a, b);
        // Lane changes are symmetric, so the crossing is at half their length.
        if (crosses(a, b)) crossAt.push(total + len / 2);
        total += len;
        nodeAt.push(total);
    });
    const CROSS_WINDOW = 16;
    const SLOW = 6;
    const SPEED = 170; // px/s away from crossings
    // Breakpoints along the path, each with how the dot covers the span that
    // ends there: "slow" through a crossing, "hold" (zero distance) at a hop.
    type Mark = { at: number; kind: "move" | "slow" | "hold"; secs?: number };
    const marks: Mark[] = [
        ...crossAt.flatMap((d): Mark[] => [
            { at: d - CROSS_WINDOW, kind: "move" },
            { at: d + CROSS_WINDOW, kind: "slow" },
        ]),
        ...pts.flatMap((p, i): Mark[] =>
            p.hold
                ? [
                      { at: nodeAt[i]!, kind: "move" },
                      { at: nodeAt[i]!, kind: "hold", secs: p.hold },
                  ]
                : [],
        ),
        { at: total, kind: "move" },
    ].sort((a, b) => a.at - b.at || (a.kind === "hold" ? 1 : -1));
    const points = [0];
    const times = [0];
    const holds: { hop: number; start: number; secs: number }[] = [];
    for (const m of marks) {
        const prevAt = points[points.length - 1]!;
        const prevT = times[times.length - 1]!;
        const dt =
            m.kind === "hold"
                ? m.secs!
                : ((m.at - prevAt) / SPEED) * (m.kind === "slow" ? SLOW : 1);
        if (m.kind === "hold") {
            holds.push({
                hop: nodeAt.indexOf(m.at),
                start: prevT,
                secs: m.secs!,
            });
        }
        points.push(m.at);
        times.push(prevT + dt);
    }
    const dur = times[times.length - 1]!;
    const motion = {
        dur: `${dur.toFixed(2)}s`,
        keyPoints: points.map((m) => (m / total).toFixed(4)).join(";"),
        keyTimes: times.map((t) => (t / dur).toFixed(4)).join(";"),
    };
    // A progress bar on each held hop fills while the dot waits there, stays
    // full until the loop restarts, then resets.
    const bars = holds.map((h) => ({
        hop: h.hop,
        values: "0;0;1;1",
        keyTimes: [0, h.start / dur, (h.start + h.secs) / dur, 1]
            .map((t) => t.toFixed(4))
            .join(";"),
    }));
    return { pts, path: segs.join(" "), crossings, motion, bars };
};
const laneName = (l: Hop["lane"]) =>
    l === "m"
        ? "your machine"
        : l === "c"
          ? "cloud"
          : "on the network boundary";
const traceLabel = (tool: string, hops: Hop[], crossings: number) =>
    `${tool}: ${hops.map((h) => `${h.label} (${laneName(h.lane)})`).join(", then ")}. ${crossings} crossings of the network.`;
// Everything the client script needs to redraw Alchemy's row per mode.
// Every mode has a box for every slot; a slot a mode doesn't use becomes a
// hidden "ghost" sitting on that mode's path, so it can grow out of it.
const ALCHEMY_SLOTS = ["src", "deploy", "fn", "db"];
type Slot = {
    x: number;
    y: number;
    w: number;
    label: string;
    shown: boolean;
    bar: string | null;
};
const ALCHEMY_MODE_DATA = ALCHEMY_MODES.map((m) => {
    const g = traceGeom(m.hops, { fullSpan: true });
    const shown = ALCHEMY_SLOTS.map((key) => {
        const i = m.hops.findIndex((h) => h.key === key);
        if (i < 0) return null;
        const p = g.pts[i]!;
        const bar = g.bars.find((b) => b.hop === i);
        return {
            x: p.x,
            y: p.y,
            w: p.w,
            label: p.label,
            shown: true,
            bar: bar?.keyTimes ?? null,
        };
    });
    const slots: Slot[] = shown.map((s, i) => {
        if (s) return s;
        const prev = shown.slice(0, i).reverse().find(Boolean)!;
        const next = shown.slice(i + 1).find(Boolean)!;
        // The midpoint of a symmetric curve between its neighbors.
        return {
            x: (prev.x + next.x) / 2,
            y: (prev.y + next.y) / 2,
            w: 24,
            label: "",
            shown: false,
            bar: null,
        };
    });
    // The route as one cubic per slot gap (same count in every mode), so a
    // mode switch can morph control points instead of re-deriving curves. A
    // hidden slot splits its neighbors' curve exactly at t = 0.5, which keeps
    // the drawn shape identical to the mode's real path.
    type Cubic = number[]; // x0 y0 c1x c1y c2x c2y x1 y1
    const cubic = (a: Slot, b: Slot): Cubic => {
        const h = (b.x - a.x) / 2;
        return [a.x, a.y, a.x + h, a.y, b.x - h, b.y, b.x, b.y];
    };
    const split = ([x0, y0, ax, ay, bx, by, x1, y1]: Cubic): [Cubic, Cubic] => {
        const mid = (p: number, q: number) => (p + q) / 2;
        const [m1x, m1y] = [mid(x0, ax), mid(y0, ay)];
        const [m2x, m2y] = [mid(ax, bx), mid(ay, by)];
        const [m3x, m3y] = [mid(bx, x1), mid(by, y1)];
        const [n1x, n1y] = [mid(m1x, m2x), mid(m1y, m2y)];
        const [n2x, n2y] = [mid(m2x, m3x), mid(m2y, m3y)];
        const [px, py] = [mid(n1x, n2x), mid(n1y, n2y)];
        return [
            [x0, y0, m1x, m1y, n1x, n1y, px, py],
            [px, py, n2x, n2y, m3x, m3y, x1, y1],
        ];
    };
    const segs: Cubic[] = [];
    for (let i = 0; i < slots.length - 1;) {
        const a = slots[i]!;
        const b = slots[i + 1]!;
        if (b.shown) {
            segs.push(cubic(a, b));
            i += 1;
        } else {
            segs.push(...split(cubic(a, slots[i + 2]!)));
            i += 2;
        }
    }
    return {
        headline: m.headline,
        sub: m.sub,
        local: m.hops.every((h) => h.lane === "m"),
        lanes: Object.fromEntries(
            m.hops.flatMap((h) => (h.key ? [[h.key, h.lane]] : [])),
        ),
        aria: traceLabel("Alchemy", m.hops, g.crossings.length),
        path: g.path,
        segs: segs.map((c) => c.map((n) => +n.toFixed(2))),
        crossings: g.crossings,
        motion: g.motion,
        slots,
    };
});

---

<Marketing
    title="Alchemy vs SST, Pulumi & Terraform"
    description="How Alchemy compares to SST, Pulumi, and Terraform: pure TypeScript and Effect instead of wrapped Go engines, infrastructure and app code built together with Effects and Layers, true local emulation, and deploy-test-destroy loops built for agents."
>
    <!-- ───────────────── HERO ───────────────── -->
    <section class="cmp-hero cmp-pat-1">
        <div class="cmp-container">
            <Yantra class="cmp-hero__mark" size={40} />
            <p class="cmp-eyebrow">Compare</p>
            <h1 class="cmp-hero__title" data-copy>
                More than just Infrastructure as Code
            </h1>
            <p class="cmp-hero__lede" data-copy>
                Terraform, Pulumi, SST, and the CDK deploy your infrastructure and stop there. Alchemy is built on its own Infrastructure as Code engine in TypeScript, and builds your application on top of it with Effects and Layers. That opens the door to fully integrated features: <a href="#app-code">app code</a>, <a href="#testing">testing</a>, <a href="#engine">engine</a>, <a href="#bindings">bindings</a>, <a href="#permissions">permissions</a>, and <a href="#local">local dev</a>.
            </p>
        </div>
    </section>

    <!-- ───────────────── AT A GLANCE ───────────────── -->
    <section class="cmp-section cmp-pat-2" aria-labelledby="glance">
        <div class="cmp-container">
            <h2 class="cmp-h2" id="glance" data-copy>
                At a glance
            </h2>
            <div
                class="cmp-table-wrap"
                tabindex="0"
                role="region"
                aria-label="Comparison table"
            >
                <table class="cmp-table">
                    <thead>
                        <tr>
                            <td></td>
                            {TOOLS.map((t, i) => (
                                <th
                                    scope="col"
                                    class:list={[i === 0 && "is-ours"]}
                                >
                                    {i === 0 ? <Yantra size={18} /> : null}
                                    {t}
                                </th>
                            ))}
                        </tr>
                    </thead>
                    <tbody>
                        {ROWS.map((row) => (
                            <tr>
                                <th scope="row">{row.label}</th>
                                {row.cells.map((c, i) => (
                                    <td
                                        class:list={[
                                            i === 0 && "is-ours",
                                            (c.startsWith("No") ||
                                                c === "Unenforced") &&
                                                "is-no",
                                        ]}
                                    >
                                        {c}
                                    </td>
                                ))}
                            </tr>
                        ))}
                    </tbody>
                </table>
            </div>
        </div>
    </section>

    <AlchemicalDivider variant="dot" class="cmp-divider" />

    <!-- ───────────────── APP CODE ───────────────── -->
    <section
        class="cmp-section cmp-pat-3"
        id="app-code"
        aria-labelledby="app-code-h"
    >
        <div class="cmp-container">
            <h2 class="cmp-h2" id="app-code-h" data-copy>
                Infrastructure and app code, together
            </h2>
            <p class="cmp-lede" data-copy>
                Other IaC tools only cover your infrastructure. The code that runs on it is a separate program that finds the Bucket through an environment variable, so the two halves meet at one name and every feature has to change in both. In Alchemy the Worker is an Effect that asks for the Bucket itself: one line gives it access when you deploy and a typed client while it runs. Layers then let a service bring its own infrastructure. <a href="/what-is-alchemy">What is Alchemy?</a>
            </p>
            <div class="cmp-vs">
                <div class="cmp-vs__side">
                    <h3 class="cmp-vs__label" data-copy>Other IaC tools: two programs</h3>
                    <CodeBlock filename="infra.ts" code={IAC_INFRA_SRC} compact />
                    <CodeBlock filename="src/api.ts" code={IAC_HANDLER_SRC} compact />
                </div>
                <div class="cmp-vs__side is-ours">
                    <h3 class="cmp-vs__label" data-copy>Alchemy: Effects and Layers</h3>
                    <CodeBlock filename="src/api.ts" code={IAE_SRC} compact highlight={[[7, 7]]} />
                </div>
            </div>
        </div>
    </section>

    <AlchemicalDivider variant="triangle" class="cmp-divider" />

    <!-- ───────────────── TESTING ───────────────── -->
    <section
        class="cmp-section cmp-pat-1"
        id="testing"
        aria-labelledby="testing-h"
    >
        <div class="cmp-container">
            <h2 class="cmp-h2" id="testing-h" data-copy>
                A complete iteration loop for agents
            </h2>
            <p class="cmp-lede" data-copy>
                Alchemy Test deploys a real stack, runs tests on that deployment, then tears it down all from the test runner you already use. All agent's have to do to test against real infrastructure is make a code change, then run a test file; this keeps the loop extremely tight and lets ai agents move fast without breaking. Our <a href="https://github.com/alchemy-run/alchemy/tree/main/examples/cloudflare-preview-benchmark"> preview benchmark </a> takes 17 seconds for 1 full loop, <strong>no competitor even has a full loop</strong>.
            </p>
            <TestLoop />
        </div>
    </section>

    <AlchemicalDivider variant="square" class="cmp-divider" />

    <!-- ───────────────── ENGINE ───────────────── -->
    <section
        class="cmp-section cmp-pat-3"
        id="engine"
        aria-labelledby="engine-h"
    >
        <div class="cmp-container">
            <h2 class="cmp-h2" id="engine-h" data-copy>
                Its own engine, not a wrapper
            </h2>
            <p class="cmp-lede" data-copy>
                Every competitor has a core and providers have to talk to that
                core over a bridge, in some cases even 2. Alchemy just imports
                providers as typescript and runs them directly, this means
                alchemy can just deploy resources instead of waiting on events.
            </p>
            <div class="dg-engine">
                {ENGINES.map((e) => (
                    <figure
                        class:list={["dg-engine__tool", e.ours && "is-ours"]}
                    >
                        <figcaption>{e.tool}</figcaption>
                        <span class="dg-pill">{e.file}</span>
                        <span class="dg-down" aria-hidden="true" />
                        <div class="dg-nest" set:html={nest(e.layers)} />
                        <span class="dg-down" aria-hidden="true" />
                        <span class="dg-pill dg-pill--cloud">Cloud API</span>
                        <p class="dg-note">{e.note}</p>
                    </figure>
                ))}
            </div>
        </div>
    </section>

    <AlchemicalDivider variant="pentagon" class="cmp-divider" />

    <!-- ───────────────── BINDINGS ───────────────── -->
    <section
        class="cmp-section cmp-pat-4"
        id="bindings"
        aria-labelledby="bindings-h"
    >
        <div class="cmp-container">
            <h2 class="cmp-h2" id="bindings-h" data-copy>
                One line does three jobs
            </h2>
            <p class="cmp-lede" data-copy>
                To read a table, a function needs three things that usually
                live in three different places: a permission, the table's
                name, and a client. In Alchemy the function's code asks for
                the capability, and that one line produces all three: its
                statement in the IAM policy, the table's name, and a typed
                client.
            </p>
            <OneLine />
        </div>
    </section>

    <AlchemicalDivider variant="hexagon" class="cmp-divider" />

    <!-- ───────────────── PERMISSIONS ───────────────── -->
    <section
        class="cmp-section cmp-pat-5"
        id="permissions"
        aria-labelledby="permissions-h"
    >
        <div class="cmp-container">
            <h2 class="cmp-h2" id="permissions-h" data-copy>
                Principle of least privilege
            </h2>
            <p class="cmp-lede" data-copy>
                In Alchemy permission policies are created from your code. This allows least privilege security policies to be inferred on the type level. SST provides link to automate common policy usecases, but are one size fits all, not lease privilege. Pulumi &amp; terraform offer no enforcement, so you have to manually maintain permission policies yourself.
            </p>
            <div class="dg-perm">
                {[
                    {
                        tool: "Alchemy",
                        ours: true,
                        needed: 42,
                        granted: 42,
                        dashed: false,
                        code: "DynamoDB.GetItem(table)",
                        grant: "dynamodb:GetItem on table",
                        verdict: "Exact",
                    },
                    {
                        tool: "SST",
                        needed: 42,
                        granted: 60,
                        dashed: false,
                        code: "link: [table]",
                        grant: "dynamodb:* on table",
                        verdict: "Close",
                    },
                    {
                        tool: "Pulumi & Terraform",
                        needed: 42,
                        granted: 78,
                        dashed: true,
                        code: "a policy you write",
                        grant: "often dynamodb:* on *",
                        verdict: "Unenforced",
                    },
                ].map((d) => (
                    <figure class:list={["dg-perm__tool", d.ours && "is-ours"]}>
                        <figcaption>{d.tool}</figcaption>
                        <svg
                            viewBox="0 0 180 180"
                            class="dg-perm__rings"
                            role="img"
                            aria-label={`${d.tool}: grants ${d.grant}`}
                        >
                            <circle
                                class:list={[
                                    "dg-perm__granted",
                                    d.dashed && "is-dashed",
                                ]}
                                cx="90"
                                cy="90"
                                r={d.granted}
                            />
                            <circle
                                class="dg-perm__needed"
                                cx="90"
                                cy="90"
                                r={d.needed}
                            />
                            <text
                                x="90"
                                y="94"
                                text-anchor="middle"
                                class="dg-perm__label"
                            >
                                needed
                            </text>
                        </svg>
                        <code class="dg-perm__code">{d.code}</code>
                        <p class="dg-perm__grant">
                            grants <code>{d.grant}</code>
                        </p>
                        <p
                            class:list={[
                                "dg-verdict",
                                d.ours && "dg-verdict--yes",
                            ]}
                        >
                            {d.verdict}
                        </p>
                    </figure>
                ))}
            </div>
            <ul class="dg-legend" aria-label="Legend">
                <li><span class="dg-legend__needed" aria-hidden="true"></span>what the code needs</li>
                <li><span class="dg-legend__granted" aria-hidden="true"></span>granted, scoped by the tool</li>
                <li><span class="dg-legend__manual" aria-hidden="true"></span>granted by a policy you maintain</li>
            </ul>
        </div>
    </section>

    <AlchemicalDivider variant="heptagon" class="cmp-divider" />

    <!-- ───────────────── LOCAL DEV ───────────────── -->
    <section class="cmp-section cmp-pat-6" id="local" aria-labelledby="local-h">
        <div class="cmp-container">
            <h2 class="cmp-h2" id="local-h" data-copy>
                True emulation for faster dev loops
            </h2>
            <p class="cmp-lede" data-copy>
                <code>alchemy dev</code> runs your stack on your machine, in
                the cloud, or a mix of both, and you choose. Other tools pick
                one model for you, and some have no dev mode at all, so every
                change waits on a deploy.
            </p>
            <div class="dg-traces">
                {TRACES.map((t, ti) => {
                    const g = traceGeom(t.hops, { fullSpan: !!t.modes });
                    const mode0 = t.modes ? ALCHEMY_MODE_DATA[0]! : null;
                    const last = g.pts[g.pts.length - 1]!;
                    return (
                        <figure
                            class:list={["dg-trace", t.ours && "is-ours"]}
                            data-modes={
                                t.modes
                                    ? JSON.stringify(ALCHEMY_MODE_DATA)
                                    : undefined
                            }
                        >
                            <figcaption class="dg-trace__meta">
                                <span class="dg-trace__tool">{t.tool}</span>
                                {/* Alchemy's text changes with the drag: every variant sits
                                    in the same grid cell (hidden) so the column is always
                                    sized to the longest and never shifts. */}
                                <span class="dg-trace__headline dg-stack">
                                    <span data-headline>{t.headline}</span>
                                    {t.modes?.map((m) => (
                                        <span class="dg-sizer" aria-hidden="true">
                                            {m.headline}
                                        </span>
                                    ))}
                                </span>
                                <span class="dg-trace__sub dg-stack">
                                    <span data-sub aria-live="polite">
                                        {t.sub}
                                    </span>
                                    {t.modes?.map((m) => (
                                        <span class="dg-sizer" aria-hidden="true">
                                            {m.sub}
                                        </span>
                                    ))}
                                </span>
                            </figcaption>
                            <div
                                class="dg-trace__scroll"
                                tabindex="0"
                                role="region"
                                aria-label={`${t.tool} request path`}
                            >
                                <svg
                                    viewBox={`0 0 660 ${TRACE_H}`}
                                    role={t.modes ? "group" : "img"}
                                    aria-label={traceLabel(
                                        t.tool,
                                        t.hops,
                                        g.crossings.length,
                                    )}
                                >
                                    <rect
                                        class="dg-lane dg-lane--m"
                                        x="0"
                                        y="0"
                                        width="660"
                                        height={NET_Y}
                                    />
                                    <rect
                                        class="dg-lane dg-lane--c"
                                        x="0"
                                        y={NET_Y}
                                        width="660"
                                        height={TRACE_H - NET_Y}
                                    />
                                    <line
                                        class="dg-net"
                                        x1="0"
                                        y1={NET_Y}
                                        x2="660"
                                        y2={NET_Y}
                                    />
                                    <text
                                        class="dg-lane__label"
                                        x="10"
                                        y={NET_Y - 7}
                                    >
                                        YOUR MACHINE
                                    </text>
                                    <text
                                        class="dg-lane__label"
                                        x="10"
                                        y={NET_Y + 15}
                                    >
                                        CLOUD
                                    </text>
                                    <text
                                        class="dg-net__label"
                                        x="650"
                                        y={NET_Y - 6}
                                        text-anchor="end"
                                    >
                                        network
                                    </text>
                                    <path
                                        class="dg-trace__path"
                                        d={g.path}
                                        id={`dg-trace-${ti}`}
                                    />
                                    {t.modes && (
                                        <circle
                                            class="dg-trace__cross"
                                            data-cross-template
                                            r="6"
                                            cx="-20"
                                            cy="-20"
                                            hidden
                                        />
                                    )}
                                    <g data-crosses>
                                        {g.crossings.map((c) => (
                                            <circle
                                                class="dg-trace__cross"
                                                cx={c.x}
                                                cy={c.y}
                                                r="6"
                                            />
                                        ))}
                                    </g>
                                    {mode0
                                        ? mode0.slots.map((p, si) => (
                                              <g
                                                  class:list={[
                                                      "dg-hop",
                                                      "is-slot",
                                                      ALCHEMY_SLOTS[si] ===
                                                          "deploy" &&
                                                          "is-boundary",
                                                      !p.shown && "is-ghost",
                                                  ]}
                                                  data-hop={si}
                                                  {...(ALCHEMY_SLOTS[si] === "fn" ||
                                                  ALCHEMY_SLOTS[si] === "db"
                                                      ? {
                                                            "data-drag":
                                                                ALCHEMY_SLOTS[si],
                                                            tabindex: "0",
                                                            role: "button",
                                                        }
                                                      : {})}
                                                  style={`transform: translate(${p.x}px, ${p.y}px)`}
                                              >
                                                  <rect
                                                      x={-p.w / 2}
                                                      y={
                                                          ALCHEMY_SLOTS[si] ===
                                                          "deploy"
                                                              ? -24
                                                              : -15
                                                      }
                                                      width={p.w}
                                                      height={
                                                          ALCHEMY_SLOTS[si] ===
                                                          "deploy"
                                                              ? 40
                                                              : 30
                                                      }
                                                      rx="8"
                                                  />
                                                  <text
                                                      y={
                                                          ALCHEMY_SLOTS[si] ===
                                                          "deploy"
                                                              ? -8
                                                              : 4.5
                                                      }
                                                      text-anchor="middle"
                                                  >
                                                      {p.label}
                                                  </text>
                                                  {ALCHEMY_SLOTS[si] ===
                                                      "deploy" && (
                                                      <g
                                                          class="dg-hop__bar"
                                                          transform="translate(-38 -2)"
                                                      >
                                                          <rect
                                                              class="dg-hop__track"
                                                              width="76"
                                                              height="4"
                                                              rx="2"
                                                          />
                                                          <rect
                                                              class="dg-hop__fill"
                                                              width="76"
                                                              height="4"
                                                              rx="2"
                                                          >
                                                              <animateTransform
                                                                  attributeName="transform"
                                                                  type="scale"
                                                                  dur={
                                                                      g.motion
                                                                          .dur
                                                                  }
                                                                  repeatCount="indefinite"
                                                                  calcMode="linear"
                                                                  values="0 1;0 1;1 1;1 1"
                                                                  keyTimes={
                                                                      ALCHEMY_MODE_DATA.find(
                                                                          (m) =>
                                                                              m
                                                                                  .slots[
                                                                                  si
                                                                              ]!
                                                                                  .bar,
                                                                      )?.slots[
                                                                          si
                                                                      ]!.bar ??
                                                                      "0;0;1;1"
                                                                  }
                                                                  data-bar
                                                              />
                                                          </rect>
                                                      </g>
                                                  )}
                                              </g>
                                          ))
                                        : g.pts.map((p, pi) => {
                                              const bar = g.bars.find(
                                                  (b) => b.hop === pi,
                                              );
                                              return (
                                                  <g
                                                      class:list={[
                                                          "dg-hop",
                                                          p.lane === "b" &&
                                                              "is-boundary",
                                                      ]}
                                                      data-hop={pi}
                                                      style={`transform: translate(${p.x}px, ${p.y}px)`}
                                                  >
                                                      <rect
                                                          x={-p.w / 2}
                                                          y={bar ? -24 : -15}
                                                          width={p.w}
                                                          height={bar ? 40 : 30}
                                                          rx="8"
                                                      />
                                                      <text
                                                          y={bar ? -8 : 4.5}
                                                          text-anchor="middle"
                                                      >
                                                          {p.label}
                                                      </text>
                                                      {bar && (
                                                          <g
                                                              class="dg-hop__bar"
                                                              transform={`translate(${-p.w / 2 + 10} -2)`}
                                                          >
                                                              <rect
                                                                  class="dg-hop__track"
                                                                  width={
                                                                      p.w - 20
                                                                  }
                                                                  height="4"
                                                                  rx="2"
                                                              />
                                                              <rect
                                                                  class="dg-hop__fill"
                                                                  width={
                                                                      p.w - 20
                                                                  }
                                                                  height="4"
                                                                  rx="2"
                                                              >
                                                                  <animateTransform
                                                                      attributeName="transform"
                                                                      type="scale"
                                                                      dur={
                                                                          g
                                                                              .motion
                                                                              .dur
                                                                      }
                                                                      repeatCount="indefinite"
                                                                      calcMode="linear"
                                                                      values={bar.values
                                                                          .split(
                                                                              ";",
                                                                          )
                                                                          .map(
                                                                              (
                                                                                  v,
                                                                              ) =>
                                                                                  `${v} 1`,
                                                                          )
                                                                          .join(
                                                                              ";",
                                                                          )}
                                                                      keyTimes={
                                                                          bar.keyTimes
                                                                      }
                                                                  />
                                                              </rect>
                                                          </g>
                                                      )}
                                                  </g>
                                              );
                                          })}
                                    {/* Drawn after the nodes so it passes over them, never behind. */}
                                    <circle
                                        class="dg-trace__dot"
                                        r="4.5"
                                        data-dot
                                    >
                                        <animateMotion
                                            dur={g.motion.dur}
                                            repeatCount="indefinite"
                                            calcMode="linear"
                                            keyPoints={g.motion.keyPoints}
                                            keyTimes={g.motion.keyTimes}
                                        >
                                            <mpath href={`#dg-trace-${ti}`} />
                                        </animateMotion>
                                    </circle>
                                    {t.ours && (
                                        <text
                                            class="dg-trace__done"
                                            data-done
                                            x="652"
                                            y={LANE_Y.m - 26}
                                            text-anchor="end"
                                        >
                                            stays on your machine
                                        </text>
                                    )}
                                    {t.modes && (
                                        <g
                                            class="dg-hint"
                                            data-hint
                                            aria-hidden="true"
                                        >
                                            <defs>
                                                <marker
                                                    id="dg-hint-head"
                                                    viewBox="0 0 10 10"
                                                    refX="6"
                                                    refY="5"
                                                    markerWidth="9"
                                                    markerHeight="9"
                                                    orient="auto"
                                                >
                                                    <path
                                                        class="dg-hint__head"
                                                        d="M1 1.5 L7 5 L1.5 8.5"
                                                    />
                                                </marker>
                                            </defs>
                                            <path
                                                class="dg-hint__arrow"
                                                d="M 398 131 C 376 124, 344 112, 334 70"
                                                marker-end="url(#dg-hint-head)"
                                            />
                                            <text
                                                x="406"
                                                y="146"
                                                transform="rotate(-3 406 146)"
                                            >
                                                drag me to the cloud!
                                            </text>
                                            {/* A cursor that acts out the drag on Lambda, on a loop,
                                                until the reader moves something. */}
                                            {mode0 && (
                                                <g
                                                    style={`transform: translate(${mode0.slots[2]!.x}px, ${mode0.slots[2]!.y}px)`}
                                                >
                                                    <g class="dg-hint__demo">
                                                        <rect
                                                            class="dg-hint__ghost"
                                                            x={-mode0.slots[2]!.w / 2}
                                                            y="-15"
                                                            width={mode0.slots[2]!.w}
                                                            height="30"
                                                            rx="8"
                                                        />
                                                        <path
                                                            class="dg-hint__cursor"
                                                            transform="translate(2 -2)"
                                                            d="M0 0 L0 17 L4.6 12.8 L7.6 19.6 L10.4 18.4 L7.4 11.6 L13 11.6 Z"
                                                        />
                                                    </g>
                                                </g>
                                            )}
                                        </g>
                                    )}
                                    {/* Shown once Lambda has moved: the same cursor on
                                        DynamoDB. The script places it on the box. */}
                                    {t.modes && (
                                        <g
                                            class="dg-hint is-hidden"
                                            data-hint-next
                                            aria-hidden="true"
                                        >
                                            <g data-hint-at>
                                                <text data-hint-text text-anchor="end">
                                                    now me!
                                                </text>
                                                <g class="dg-hint__demo">
                                                    <rect
                                                        class="dg-hint__ghost"
                                                        y="-15"
                                                        height="30"
                                                        rx="8"
                                                    />
                                                    <path
                                                        class="dg-hint__cursor"
                                                        transform="translate(2 -2)"
                                                        d="M0 0 L0 17 L4.6 12.8 L7.6 19.6 L10.4 18.4 L7.4 11.6 L13 11.6 Z"
                                                    />
                                                </g>
                                            </g>
                                        </g>
                                    )}
                                </svg>
                            </div>
                        </figure>
                    );
                })}
            </div>
            <ul class="dg-legend" aria-label="Legend">
                <li><span class="dg-legend__cross" aria-hidden="true"></span>a trip across the network</li>
            </ul>
        </div>
    </section>

    <AlchemicalDivider variant="circle" class="cmp-divider" />

    <!-- ───────────────── MORE ───────────────── -->
    <section class="cmp-section cmp-pat-2" aria-labelledby="more">
        <div class="cmp-container">
            <h2 class="cmp-h2" id="more" data-copy>
                And a few more things
            </h2>
            <ul class="cmp-cards cmp-cards--3">
                <li class="cmp-card">
                    <h3 data-copy>Providers built from the spec</h3>
                    <p data-copy>
                        Cloudflare, AWS, Fly, PlanetScale, Prisma, Axiom, Stripe, GitHub, Docker, and more. We are constantly adding more providers.
                    </p>
                </li>
                <li class="cmp-card">
                    <h3 data-copy>Runs anywhere TypeScript runs</h3>
                    <p data-copy>
                        Alchemy is just typescript, it can run on your machine, inside a cloudflare worker, or even in a browser.
                    </p>
                </li>
                <li class="cmp-card">
                    <h3 data-copy>Bring your own provider</h3>
                    <p data-copy>
                        A provider is just TypeScript: declare the resource's
                        props, then write its create, update, and delete as
                        plain functions. No Go plugin or bridge to build.{" "}
                        <a href="/infrastructure-as-code/custom-provider">Write one</a>.
                    </p>
                </li>
            </ul>

            <div class="cmp-cta">
                <Button variant="primary" icon="arrow" href="/getting-started">
                    <span data-copy>Start your project</span>
                </Button>
                <Button variant="secondary" href="/what-is-alchemy">
                    <span data-copy>What is Alchemy?</span>
                </Button>
            </div>
        </div>
    </section>
</Marketing>

<script>
    // SVG (SMIL) animations don't follow CSS, so reduced motion has to stop
    // them here: every diagram freezes on its first frame. Also re-applied
    // if the setting changes while the page is open.
    const motion = matchMedia("(prefers-reduced-motion: reduce)");
    const syncSvgMotion = () => {
        for (const svg of document.querySelectorAll<SVGSVGElement>("svg")) {
            if (!svg.querySelector("animate, animateMotion, animateTransform")) continue;
            if (motion.matches) {
                svg.pauseAnimations();
                svg.setCurrentTime(0);
            } else {
                svg.unpauseAnimations();
            }
        }
    };
    syncSvgMotion();
    motion.addEventListener("change", syncSvgMotion);
</script>

<script>
    // Alchemy's draggable row in "True emulation". On a switch the
    // boxes glide to their new spots and the dotted route bends with them
    // (redrawn every frame from the live box positions); boxes a mode doesn't
    // use shrink into the line. Then the new route, crossings, and dot land.
    type Slot = {
        x: number;
        y: number;
        w: number;
        label: string;
        shown: boolean;
        bar: string | null;
    };
    type ModeData = {
        headline: string;
        sub: string;
        local: boolean;
        lanes: Record<string, "m" | "c" | "b">;
        aria: string;
        path: string;
        segs: number[][];
        crossings: { x: number; y: number }[];
        motion: { dur: string; keyPoints: string; keyTimes: string };
        slots: Slot[];
    };
    const MOVE_MS = 520;
    const ease = (t: number) => 1 - Math.pow(1 - t, 3);
    const draw = (segs: number[][]) =>
        segs
            .map(
                ([x0, y0, ax, ay, bx, by, x1, y1]) =>
                    `M ${x0} ${y0} C ${ax} ${ay}, ${bx} ${by}, ${x1} ${y1}`,
            )
            .join(" ");

    for (const fig of document.querySelectorAll<HTMLElement>(
        "figure[data-modes]",
    )) {
        const modes = JSON.parse(fig.dataset.modes!) as ModeData[];
        const svg = fig.querySelector("svg")!;
        const path = svg.querySelector<SVGPathElement>(".dg-trace__path")!;
        const crosses = svg.querySelector<SVGGElement>("[data-crosses]")!;
        const dotAnim = svg.querySelector<SVGAnimationElement>(
            "[data-dot] animateMotion",
        )!;
        const barAnim = svg.querySelector<SVGAnimationElement>("[data-bar]");
        const done = svg.querySelector<SVGTextElement>("[data-done]");
        const headline = fig.querySelector<HTMLElement>("[data-headline]")!;
        const sub = fig.querySelector<HTMLElement>("[data-sub]")!;
        const boxes = [...svg.querySelectorAll<SVGGElement>("[data-hop]")];
        // Cloned so new crossings keep the page's scoped styles.
        const crossTemplate = svg.querySelector<SVGCircleElement>(
            "[data-cross-template]",
        )!;
        const reduced = matchMedia("(prefers-reduced-motion: reduce)").matches;
        let current = modes[0]!;
        let frame = 0;

        const place = (g: SVGGElement, s: Slot, x = s.x, y = s.y) => {
            g.style.transform = `translate(${x}px, ${y}px)`;
            const rect = g.querySelector("rect")!;
            rect.setAttribute("x", String(-s.w / 2));
            rect.setAttribute("width", String(s.w));
        };

        const land = (m: ModeData) => {
            path.setAttribute("d", m.path);
            crosses.replaceChildren(
                ...m.crossings.map((c) => {
                    const el = crossTemplate.cloneNode() as SVGCircleElement;
                    el.removeAttribute("data-cross-template");
                    el.removeAttribute("hidden");
                    el.setAttribute("cx", String(c.x));
                    el.setAttribute("cy", String(c.y));
                    return el;
                }),
            );
            dotAnim.setAttribute("dur", m.motion.dur);
            dotAnim.setAttribute("keyPoints", m.motion.keyPoints);
            dotAnim.setAttribute("keyTimes", m.motion.keyTimes);
            const bar = m.slots.find((s) => s.bar)?.bar;
            if (barAnim && bar) {
                barAnim.setAttribute("dur", m.motion.dur);
                barAnim.setAttribute("keyTimes", bar);
            }
            dotAnim.beginElement();
            barAnim?.beginElement();
            fig.classList.remove("is-switching");
        };

        // The route between the current box positions: one cubic per slot gap,
        // split in half across a hidden slot (mirrors the server-side build).
        type Cubic = number[];
        const cubic = (a: Slot, b: Slot): Cubic => {
            const h = (b.x - a.x) / 2;
            return [a.x, a.y, a.x + h, a.y, b.x - h, b.y, b.x, b.y];
        };
        const split = ([x0, y0, ax, ay, bx, by, x1, y1]: Cubic): Cubic[] => {
            const mid = (p: number, q: number) => (p + q) / 2;
            const [m1x, m1y, m2x, m2y, m3x, m3y] = [
                mid(x0!, ax!), mid(y0!, ay!), mid(ax!, bx!),
                mid(ay!, by!), mid(bx!, x1!), mid(by!, y1!),
            ];
            const [n1x, n1y, n2x, n2y] = [
                mid(m1x, m2x), mid(m1y, m2y), mid(m2x, m3x), mid(m2y, m3y),
            ];
            const [px, py] = [mid(n1x, n2x), mid(n1y, n2y)];
            return [
                [x0!, y0!, m1x, m1y, n1x, n1y, px, py],
                [px, py, n2x, n2y, m3x, m3y, x1!, y1!],
            ];
        };
        const segsFor = (slots: Slot[]) => {
            const segs: Cubic[] = [];
            for (let i = 0; i < slots.length - 1; ) {
                if (slots[i + 1]!.shown) {
                    segs.push(cubic(slots[i]!, slots[i + 1]!));
                    i += 1;
                } else {
                    segs.push(...split(cubic(slots[i]!, slots[i + 2]!)));
                    i += 2;
                }
            }
            return segs;
        };

        const hint = svg.querySelector<SVGGElement>("[data-hint]");
        const hintNext = svg.querySelector<SVGGElement>("[data-hint-next]");
        const NET_Y = 85;
        const NAMES: Record<string, string> = {
            fn: "Lambda",
            db: "DynamoDB",
        };