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