| 1 | --- |
| 2 | title: "Part 1: Your First Project" |
| 3 | description: Install Alchemy, configure Prisma credentials, and deploy your first Project. |
| 4 | sidebar: |
| 5 | order: 1 |
| 6 | --- |
| 7 | |
| 8 | import { Code, Tabs, TabItem } from "@astrojs/starlight/components"; |
| 9 | import { effectVersion } from "../../../../versions"; |
| 10 | |
| 11 | export const pkgs = `"alchemy@next" "effect@${effectVersion}" "@effect/platform-node@${effectVersion}"`; |
| 12 | |
| 13 | Build a full-stack application on Prisma in four parts: a Project, an |
| 14 | Effect-native Compute API, a Postgres database, and a Vite frontend. |
| 15 | The [complete example](https://github.com/alchemy-run/alchemy/tree/main/examples/prisma-tutorial) |
| 16 | contains the final application and its deployment test. |
| 17 | |
| 18 | ## Prerequisites |
| 19 | |
| 20 | - [Bun](https://bun.sh) or Node.js 22+ installed locally. |
| 21 | - A Prisma workspace with access to Compute and Postgres. |
| 22 | - A workspace service token from the [Prisma Console](https://console.prisma.io). |
| 23 | |
| 24 | :::caution[Cloud costs] |
| 25 | This tutorial deploys real infrastructure. Compute and Postgres may incur |
| 26 | charges. Part 4 ends with `alchemy destroy`; you can also run it after any |
| 27 | part to remove the resources created so far. |
| 28 | ::: |
| 29 | |
| 30 | ## Create a directory |
| 31 | |
| 32 | ```sh |
| 33 | mkdir prisma-tutorial |
| 34 | cd prisma-tutorial |
| 35 | ``` |
| 36 | |
| 37 | Keep all of the following files in this directory. |
| 38 | |
| 39 | ## Initialize the package |
| 40 | |
| 41 | <Tabs syncKey="pkgManager"> |
| 42 | <TabItem label="bun" icon="bun"><Code code="bun init -y" lang="sh" /></TabItem> |
| 43 | <TabItem label="npm" icon="npm"><Code code="npm init -y" lang="sh" /></TabItem> |
| 44 | <TabItem label="pnpm" icon="pnpm"><Code code="pnpm init" lang="sh" /></TabItem> |
| 45 | <TabItem label="yarn" icon="seti:yarn"><Code code="yarn init -y" lang="sh" /></TabItem> |
| 46 | </Tabs> |
| 47 | |
| 48 | This creates the `package.json` that records your dependencies. |
| 49 | |
| 50 | ## Install Alchemy |
| 51 | |
| 52 | <Tabs syncKey="pkgManager"> |
| 53 | <TabItem label="bun" icon="bun"><Code code={`bun add ${pkgs}`} lang="sh" /></TabItem> |
| 54 | <TabItem label="npm" icon="npm"><Code code={`npm install ${pkgs}`} lang="sh" /></TabItem> |
| 55 | <TabItem label="pnpm" icon="pnpm"><Code code={`pnpm add ${pkgs}`} lang="sh" /></TabItem> |
| 56 | <TabItem label="yarn" icon="seti:yarn"><Code code={`yarn add ${pkgs}`} lang="sh" /></TabItem> |
| 57 | </Tabs> |
| 58 | |
| 59 | Use matching Effect versions for Alchemy and the platform packages. |
| 60 | |
| 61 | ## Configure credentials |
| 62 | |
| 63 | <Tabs syncKey="pkgManager"> |
| 64 | <TabItem label="bun" icon="bun"><Code code="bun alchemy profile edit --add Prisma" lang="sh" /></TabItem> |
| 65 | <TabItem label="npm" icon="npm"><Code code="npx alchemy profile edit --add Prisma" lang="sh" /></TabItem> |
| 66 | <TabItem label="pnpm" icon="pnpm"><Code code="pnpm exec alchemy profile edit --add Prisma" lang="sh" /></TabItem> |
| 67 | <TabItem label="yarn" icon="seti:yarn"><Code code="yarn alchemy profile edit --add Prisma" lang="sh" /></TabItem> |
| 68 | </Tabs> |
| 69 | |
| 70 | Enter your service token when prompted. [Setup](/prisma/setup) explains |
| 71 | profiles and the `PRISMA_SERVICE_TOKEN` environment variable used in CI. |
| 72 | |
| 73 | ## Ignore local state |
| 74 | |
| 75 | Create `.gitignore`: |
| 76 | |
| 77 | ```text |
| 78 | node_modules/ |
| 79 | .alchemy/ |
| 80 | dist/ |
| 81 | .env |
| 82 | ``` |
| 83 | |
| 84 | Alchemy's local state contains resource identifiers and potentially sensitive |
| 85 | outputs. Keep it out of source control, but retain it between deployments. |
| 86 | |
| 87 | ## Create the Stack |
| 88 | |
| 89 | Create `alchemy.run.ts`: |
| 90 | |
| 91 | ```typescript |
| 92 | import * as Alchemy from "alchemy"; |
| 93 | import * as Prisma from "alchemy/Prisma"; |
| 94 | import * as Effect from "effect/Effect"; |
| 95 | |
| 96 | export default Alchemy.Stack( |
| 97 | "PrismaTutorial", |
| 98 | { providers: Prisma.providers(), state: Alchemy.localState() }, |
| 99 | Effect.gen(function* () {}), |
| 100 | ); |
| 101 | ``` |
| 102 | |
| 103 | A Stack groups resources. The Prisma providers manage them, and local state |
| 104 | records what this Stack owns. For shared deployments, use a |
| 105 | [shared state store](/state-store) instead. |
| 106 | |
| 107 | ## Define a Project |
| 108 | |
| 109 | Create `src/Database.ts`: |
| 110 | |
| 111 | ```typescript |
| 112 | import * as Prisma from "alchemy/Prisma"; |
| 113 | |
| 114 | export const Project = Prisma.Project("Project", { |
| 115 | createDatabase: false, |
| 116 | region: "eu-west-3", |
| 117 | }); |
| 118 | ``` |
| 119 | |
| 120 | The Project will contain both Compute services and Postgres. Disable the |
| 121 | implicit default database because Part 3 creates an explicit database resource. |
| 122 | Alchemy generates a physical name from the Stack, stage, and logical ID. |
| 123 | |
| 124 | ## Add the Project to the Stack |
| 125 | |
| 126 | ```diff lang="typescript" |
| 127 | // alchemy.run.ts |
| 128 | +import { Project } from "./src/Database.ts"; |
| 129 | |
| 130 | - Effect.gen(function* () {}), |
| 131 | + Effect.gen(function* () { |
| 132 | + const project = yield* Project; |
| 133 | + return { projectId: project.projectId }; |
| 134 | + }), |
| 135 | ``` |
| 136 | |
| 137 | Yielding the resource registers it in the Stack. Returning its ID makes that |
| 138 | value visible in the deployment output. |
| 139 | |
| 140 | ## Deploy |
| 141 | |
| 142 | <Tabs syncKey="pkgManager"> |
| 143 | <TabItem label="bun" icon="bun"><Code code="bun alchemy deploy" lang="sh" /></TabItem> |
| 144 | <TabItem label="npm" icon="npm"><Code code="npx alchemy deploy" lang="sh" /></TabItem> |
| 145 | <TabItem label="pnpm" icon="pnpm"><Code code="pnpm exec alchemy deploy" lang="sh" /></TabItem> |
| 146 | <TabItem label="yarn" icon="seti:yarn"><Code code="yarn alchemy deploy" lang="sh" /></TabItem> |
| 147 | </Tabs> |
| 148 | |
| 149 | Alchemy creates the Project and prints `projectId`. Use the same profile and |
| 150 | stage throughout the tutorial so each deployment updates this Stack. |
| 151 | |
| 152 | ## Next |
| 153 | |
| 154 | [Part 2: An HTTP API](/prisma/tutorial/part-2) adds an Effect-native Compute |
| 155 | service to the Project. |