| 1 | --- |
| 2 | title: Getting started |
| 3 | description: Install Alchemy and create your first Stack in under two minutes. |
| 4 | next: |
| 5 | link: /what-is-alchemy |
| 6 | label: What is Alchemy? |
| 7 | --- |
| 8 | |
| 9 | import Terminal from "../../components/Terminal.astro"; |
| 10 | import { Code, Tabs, TabItem } from "@astrojs/starlight/components"; |
| 11 | import { effectVersion } from "../../versions"; |
| 12 | |
| 13 | export const pkgs = `"alchemy@latest" "effect@${effectVersion}" "@effect/platform-bun@${effectVersion}" "@effect/platform-node@${effectVersion}"`; |
| 14 | |
| 15 | :::tip |
| 16 | Want the idea before the install? [What is Alchemy?](/what-is-alchemy) |
| 17 | explains the model in a few minutes. Otherwise, read on and it's the |
| 18 | next page. |
| 19 | ::: |
| 20 | |
| 21 | ## Prerequisites |
| 22 | |
| 23 | - [Bun](https://bun.sh) or Node.js 22+ |
| 24 | - A [Cloudflare](https://dash.cloudflare.com/sign-up) account |
| 25 | |
| 26 | ## Create a project |
| 27 | |
| 28 | <Tabs syncKey="pkgManager"> |
| 29 | <TabItem label="bun" icon="bun"> |
| 30 | <Code code="mkdir my-app && cd my-app && bun init -y" lang="sh" /> |
| 31 | </TabItem> |
| 32 | <TabItem label="npm" icon="npm"> |
| 33 | <Code code="mkdir my-app && cd my-app && npm init -y" lang="sh" /> |
| 34 | </TabItem> |
| 35 | <TabItem label="pnpm" icon="pnpm"> |
| 36 | <Code code="mkdir my-app && cd my-app && pnpm init" lang="sh" /> |
| 37 | </TabItem> |
| 38 | <TabItem label="yarn" icon="seti:yarn"> |
| 39 | <Code code="mkdir my-app && cd my-app && yarn init -y" lang="sh" /> |
| 40 | </TabItem> |
| 41 | </Tabs> |
| 42 | |
| 43 | ## Install |
| 44 | |
| 45 | <Tabs syncKey="pkgManager"> |
| 46 | <TabItem label="bun" icon="bun"> |
| 47 | <Code code={`bun add ${pkgs}`} lang="sh" /> |
| 48 | </TabItem> |
| 49 | <TabItem label="npm" icon="npm"> |
| 50 | <Code code={`npm install ${pkgs}`} lang="sh" /> |
| 51 | </TabItem> |
| 52 | <TabItem label="pnpm" icon="pnpm"> |
| 53 | <Code code={`pnpm add ${pkgs}`} lang="sh" /> |
| 54 | </TabItem> |
| 55 | <TabItem label="yarn" icon="seti:yarn"> |
| 56 | <Code code={`yarn add ${pkgs}`} lang="sh" /> |
| 57 | </TabItem> |
| 58 | </Tabs> |
| 59 | |
| 60 | ## Create your Stack |
| 61 | |
| 62 | Every Alchemy program starts with a Stack — create `alchemy.run.ts`: |
| 63 | |
| 64 | ```typescript |
| 65 | // alchemy.run.ts |
| 66 | import * as Alchemy from "alchemy"; |
| 67 | import * as Cloudflare from "alchemy/Cloudflare"; |
| 68 | import * as Effect from "effect/Effect"; |
| 69 | |
| 70 | export default Alchemy.Stack( |
| 71 | "MyApp", |
| 72 | { |
| 73 | providers: Cloudflare.providers(), |
| 74 | state: Cloudflare.state(), |
| 75 | }, |
| 76 | Effect.gen(function* () { |
| 77 | const bucket = yield* Cloudflare.R2.Bucket("Bucket"); |
| 78 | |
| 79 | return { |
| 80 | bucketName: bucket.bucketName, |
| 81 | }; |
| 82 | }), |
| 83 | ); |
| 84 | ``` |
| 85 | |
| 86 | ## Deploy |
| 87 | |
| 88 | Run `alchemy deploy` to create the Bucket on Cloudflare: |
| 89 | |
| 90 | <Tabs syncKey="pkgManager"> |
| 91 | <TabItem label="bun" icon="bun"> |
| 92 | <Code code="bun alchemy deploy" lang="sh" /> |
| 93 | </TabItem> |
| 94 | <TabItem label="npm" icon="npm"> |
| 95 | <Code code="npx alchemy deploy" lang="sh" /> |
| 96 | </TabItem> |
| 97 | <TabItem label="pnpm" icon="pnpm"> |
| 98 | <Code code="pnpm alchemy deploy" lang="sh" /> |
| 99 | </TabItem> |
| 100 | <TabItem label="yarn" icon="seti:yarn"> |
| 101 | <Code code="yarn alchemy deploy" lang="sh" /> |
| 102 | </TabItem> |
| 103 | </Tabs> |
| 104 | |
| 105 | Connect Cloudflare first with `alchemy profile edit --add Cloudflare`. |
| 106 | Sign in with OAuth in the browser or paste an API token. The |
| 107 | credentials are saved to your **`default`** |
| 108 | [profile](/environments/profiles) at `~/.alchemy/profiles.json`. No |
| 109 | environment variables required. Logging in only ever happens through the |
| 110 | `profile` command; a deploy with nothing configured fails with the exact |
| 111 | command to run. |
| 112 | |
| 113 | Once you're authenticated, Alchemy shows a plan, asks for |
| 114 | confirmation, and provisions the resource: |
| 115 | |
| 116 | <Terminal content={`[u]Plan[/u]: [g]1 to create[/g] |
| 117 | [g]+[/g] [b]Bucket[/b] [d](Cloudflare.R2.Bucket)[/d] |
| 118 | |
| 119 | Proceed? |
| 120 | ◉ Yes ○ No |
| 121 | [g]✓[/g] [b]Bucket[/b] [d](Cloudflare.R2.Bucket)[/d] [g]created[/g] |
| 122 | { |
| 123 | [s2]bucketName: "myapp-bucket-a1b2c3d4e5", |
| 124 | }`} /> |
| 125 | |
| 126 | That's it — you have a live R2 Bucket on Cloudflare. |
| 127 | |
| 128 | Full command reference: [CLI](/cli). |
| 129 | |
| 130 | :::tip |
| 131 | To re-run the credential prompt later (e.g. to switch from OAuth to |
| 132 | an API token), use `alchemy profile edit --reconfigure Cloudflare`. |
| 133 | For a separate profile, run `alchemy profile create prod` followed by |
| 134 | `alchemy profile edit --profile prod`. |
| 135 | See [Profiles](/environments/profiles) for the full picture. |
| 136 | ::: |
| 137 | |
| 138 | ## Where next |
| 139 | |
| 140 | You have a live Stack. [What is Alchemy?](/what-is-alchemy) explains |
| 141 | what just happened and the model the rest of the docs build on. The |
| 142 | [tutorial](/cloudflare/tutorial/part-1) then builds a full app on |
| 143 | Cloudflare, starting from this exact Stack. |
| 144 | |
| 145 | <div class="next-steps"> |
| 146 | |
| 147 | <a href="/what-is-alchemy" class="next-card next-card--recommended"> |
| 148 | <strong>What is Alchemy?</strong> |
| 149 | <span>Infrastructure as Code built in Effect, with Infrastructure as Effects on top.</span> |
| 150 | </a> |
| 151 | |
| 152 | <a href="/cloudflare/tutorial/part-1" class="next-card"> |
| 153 | <strong>Tutorial</strong> |
| 154 | <span>Build a full app on Cloudflare starting from this Stack: a Worker, bindings, tests, local dev, CI, and telemetry.</span> |
| 155 | </a> |
| 156 | |
| 157 | <a href="/infrastructure-as-effects/runtime" class="next-card"> |
| 158 | <strong>Infrastructure as Effects</strong> |
| 159 | <span>The model the rest of the docs build on: Runtimes, Bindings, Layers, and the Construction and Runtime phases.</span> |
| 160 | </a> |
| 161 | |
| 162 | <a href="/cloudflare" class="next-card"> |
| 163 | <strong>Cloudflare</strong> |
| 164 | <span>Workers, Durable Objects, R2, KV, D1, Queues, Workflows, and Containers, with a tutorial and a guide for each.</span> |
| 165 | </a> |
| 166 | |
| 167 | <a href="/aws" class="next-card"> |
| 168 | <strong>AWS</strong> |
| 169 | <span>Lambda, S3, SQS, DynamoDB, EC2, ECS, and EKS, with a tutorial and a guide for each.</span> |
| 170 | </a> |
| 171 | |
| 172 | <a href="/cli" class="next-card"> |
| 173 | <strong>CLI</strong> |
| 174 | <span>Every command and its flags: deploy, plan, destroy, dev, tail, logs, and state.</span> |
| 175 | </a> |
| 176 | |
| 177 | </div> |