{"id":28043667,"url":"https://github.com/imrea/cf-worker-react-router-prisma-rpc-poc","last_synced_at":"2026-04-12T12:35:55.512Z","repository":{"id":291833160,"uuid":"978917406","full_name":"imrea/cf-worker-react-router-prisma-rpc-poc","owner":"imrea","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-09T17:25:53.000Z","size":171,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-11T16:54:25.731Z","etag":null,"topics":["cloudflare","cloudflare-vite-plugin","d1","prisma","react-router","rpc","vite","worker"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imrea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-06T17:51:45.000Z","updated_at":"2025-05-09T17:25:56.000Z","dependencies_parsed_at":"2025-05-17T21:15:15.213Z","dependency_job_id":null,"html_url":"https://github.com/imrea/cf-worker-react-router-prisma-rpc-poc","commit_stats":null,"previous_names":["imrea/cf-worker-react-router-prisma-rpc-poc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/imrea/cf-worker-react-router-prisma-rpc-poc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imrea%2Fcf-worker-react-router-prisma-rpc-poc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imrea%2Fcf-worker-react-router-prisma-rpc-poc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imrea%2Fcf-worker-react-router-prisma-rpc-poc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imrea%2Fcf-worker-react-router-prisma-rpc-poc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imrea","download_url":"https://codeload.github.com/imrea/cf-worker-react-router-prisma-rpc-poc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imrea%2Fcf-worker-react-router-prisma-rpc-poc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266554139,"owners_count":23947276,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare","cloudflare-vite-plugin","d1","prisma","react-router","rpc","vite","worker"],"created_at":"2025-05-11T16:54:23.614Z","updated_at":"2026-04-12T12:35:50.493Z","avatar_url":"https://github.com/imrea.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Worker + D1 + RPC + React Router + Prisma + Vite + Cloudflare Vite Plugin + Wrangler\n\n[![architecture](architecture.png)]()\n\nA little POC setup with Vite and TurboRepo to demonstrate a decoupled architecture built with all these great tools.\n\nThe goal was to create an Object Capability Model, where instead of passing authentication info / tokens, an implicit capabability or collection of available capabilites is returned.\nThis provides typesafety, simplifies explicit permission checking, and executing processes that could throw due to lack of permissions.\n\n### Spinning up\n\nInstall dependencies in `root`:\n\n```sh\npnpm i\n```\n\nSet up and seed D1 from `workers/api`:\n\n```sh\ncd workers/api \u0026\u0026 pnpm db:reset\n```\n\nSpin up dev server from `workers/app`:\n\n```sh\ncd ../app \u0026\u0026 pnpm dev\n```\n\nOpen [http://localhost:5173/](http://localhost:5173/) and check Terminal console logs. You should see something like\n\n```\nHello from Public scope\nHello, sc9n9sdblnwv5ibcvcu0o9bf, from Private scope.\nThere are 2 Users\nIs admin: false\n```\n\n### Example\n\nConsider an authenticated User with a role of \"user\" and a functionality of deleting any user from a database for which an \"admin\" role is expected\n\nA theoretical flow with traditional API/Rest approach would look something this:\n\n```ts\ntry {\n  await fetch('/api/user/123', {\n    method: 'DELETE',\n    headers: { Authorization: 'Bearer \u003ctoken\u003e' },\n  })\n  console.log('User is deleted')\n} catch (error) {\n  if (error.status === 403)\n    console.log('You are not an admin, deleting users is not allowed')\n  else console.log('Something else went wrong')\n}\n```\n\nWith Object Capabilities, it could be solved something like this:\n\n```ts\n// A user object after authentication, which the API service\n// will use to built the capabilities\nlet user = { name: 'John', role: 'user', id: '...' }\n\n/**\n * Obtain a proper RPC Stub, implicitly representing actions\n * available as per the user's role/permissions/etc.\n * The RPC Stub might look something like this:\n *\n *  {\n *    deleteUser?: (userId: string) =\u003e Promise\u003cvoid\u003e\n *  }\n *\n */\nlet api = API.authorize(user)\n\n// `deleteUser` method might not be available, it's existence\n// in itself denotes the cabability\nawait api.deleteUser?.('123')\nconsole.log('User is deleted') // If the capability is present, otherwise failing silently\n\n// OR we can check for explicit permissions too\nif (!api.deleteUser)\n  throw new Response('You are not an admin, deleting users is not allowed', {\n    status: 403,\n  })\n\nawait api.deleteUser('123')\nconsole.log('User is deleted')\n```\n\n### Gotchas\n\n- A refined version of Prisma Migrate is still in Early Access, and `diff` lacks finegrained support for D1 (eg. when location differs from a local `.wrangler` folder). I'm symlinking the shared root-level `.wrangler` folder now.\n- The POC still uses the `prisma-client-js` generator for Prisma Client, which will be replaced by a more modular and \"bundler-friendly\" `prisma-client` in the next major version. Currently generating such client source code depends on importing the `wasm` query engine from `@prisma/client`, which is improperly resolved by Vite. There are also some improper paths/types generated. Although there might be some workarounds (hacking with `resolve` configs, handwritten custom Vite plugin, etc.), bugs are still expected, as this feature is in Early Access too.\n- A custom output path has to be provided for `@prisma/client`, the default destination has Vite resolver issues too, that's why the `@prisma/client-generated` is used. (Currently `output` is optional, but will be required indeed in further Prisma releases.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimrea%2Fcf-worker-react-router-prisma-rpc-poc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimrea%2Fcf-worker-react-router-prisma-rpc-poc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimrea%2Fcf-worker-react-router-prisma-rpc-poc/lists"}