This repo hosts the code for the FRCDesign Onshape App, which lets users browse the FRCDesign part libraries and insert parts into their documents.
The app is a Cloudflare Worker (src/backend) serving an API and a React SPA
(src/frontend), which runs both in Onshape's element right panel and directly
in a browser. See AGENTS.md for how src is laid out.
This repo is intended to be run with VSCode on Linux using WSL Ubuntu.
The local dev environment typically needs either Google Chrome or Firefox to work correctly with Onshape.
Other browsers, such as Brave, can have default security policies that prevent the dev environment from working with Onshape.
Create a new file in the root of this project named .env and add the following contents:
# Onshape API Keys (Optional)
API_ACCESS_KEY=<Your API Access Key>
API_SECRET_KEY=<Your API Secret Key>
# OAuth
OAUTH_CLIENT_ID=<Your OAuth client id>
OAUTH_CLIENT_SECRET=<Your OAuth client secret>
# One of admin, editor, or user. Granted by the server and viewed by the client,
# so both sides agree. Ignored in production.
VITE_ACCESS_LEVEL_OVERRIDE=admin
# Signs you in as a fake user, so signed-in UI can be tested without an Onshape
# session. Onshape calls it reveals won't work, so leave it unset normally.
FORCE_SIGNED_IN=false
To test Onshape app changes, you will need to create an OAuth application in the Onshape Developer Portal. Fill out the following information:
- Name: (Arbitrary) FRC Design App Test
- Primary format: (Arbitrary) com.frc-design-app.dev
- Summary: (Arbitrary) Test for the FRC Design App.
- Redirect URLs:
https://dev.frcdesign.org/auth/callback - OAuth URL:
https://dev.frcdesign.org/auth/sign-in - Check the permissions
can read your profile information,can read your documents,can write to your documents, andcan delete your documents and workspaces.
Click Create application, then copy your OAuth app's OAuth client secret (from the popup) and OAuth client identifier into your .env file.
Next, add the necessary Extensions to your OAuth application so you can see it in documents you open:
- Open your OAuth application in the Onshape Developer Portal.
- Go to the Extensions tab.
- Create two extensions with the following properties:
- Name: (Arbitrary) FRC Design App Test
- Location: Element right panel
- Context: Inside assembly/Inside part studio
- Action URL:
- Assembly:
https://dev.frcdesign.org/init?elementType=ASSEMBLY&documentId={$documentId}&instanceType={$workspaceOrVersion}&instanceId={$workspaceOrVersionId}&elementId={$elementId} - Part Studio:
https://dev.frcdesign.org/init?elementType=PARTSTUDIO&documentId={$documentId}&instanceType={$workspaceOrVersion}&instanceId={$workspaceOrVersionId}&elementId={$elementId}
- Assembly:
- Icon: You'll need an icon. A good choice is the one at
/public/frc-design-app-dev.svg.
- Open the Onshape App Store and go to My apps. Find your App and Subscribe to it.
- If it doesn't show up, try creating a Store Entry first.
You should now be able to see your Test App in the right panel of any Part Studios or Assemblies you open.
This step is only required if you want to use the Onshape API from local Python scripts using a KeyApi instance.
- Get an API key from the Onshape developer portal.
- Add your access key and secret key to
.env.
Note that Onshape has an annual limit of 2,500 API calls per Onshape account. This amount is not very large, so you should take pains to be careful with your usage in testing in local environments.
In particular, avoid loading large documents into your local environment and only force reload the database when necessary.
Onshape loads the app over https and delivers webhooks from its own servers, so the dev server is served at https://dev.frcdesign.org through a shared Cloudflare Tunnel. The hostname never changes, so the urls in the Onshape OAuth app are set once.
- Install cloudflared 2025.4.0 or later.
- Get the tunnel's token from a maintainer (it is a secret; never commit it) and save it at the root of this project, where git ignores it:
printf '%s' '<token>' > .tunnel-token
npm run tunnel runs the tunnel next to npm run dev; the Launch servers VSCode task starts both. Open the app at https://dev.frcdesign.org.
Only one person can use the tunnel at a time: Cloudflare spreads requests across everyone running it, so stop yours when you're done.
Done once, by someone with access to the frcdesign.org Cloudflare account:
- In the Cloudflare dashboard, open Zero Trust > Networks > Tunnels and create a Cloudflared tunnel named
frc-design-app-dev. - Give it the public hostname
dev.frcdesign.orgwith the servicehttp://localhost:3000. - Copy the token from the install command the dashboard shows (the long string after
--token). To see it again later, open the tunnel's configuration, or runcloudflared tunnel token frc-design-app-devaftercloudflared tunnel login.
Refreshing the token in the dashboard revokes the old one, for when it leaks or someone leaves.
To serve your own tunnel at another hostname, set APP_URL=https://<hostname> in .env (it overrides the dev value in wrangler.jsonc), and use that hostname in your Onshape OAuth app.
Install nvm (node version manager) in your WSL container, install npm, and then install the dependencies:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash
nvm i node
npm i
You should now be able to run the Launch servers VSCode task to launch Vite and the tunnel.
You should then be able to launch the FRC Design App from the right panel of any Onshape Part Studio or Assembly and see the FRC Design App UI appear.
To see documents, add one or more documents and push a new app version to rebuild the search database. Alternatively, import a dump of the loaded cert database into local D1, and (optionally) its thumbnails into local R2:
npx wrangler d1 execute DB --local --file=<cert-dump>.sql
npx wrangler r2 object put frc-design-app-dev-thumbnails/thumbnails/<size>/<elementId> --file=<thumb>.gif
To view the state of Cloudflare, type e in Vite to launch the local Cloudflare UI instance.
Double check your Action URLs configured in Onshape. You can also open Browser Dev Tools (usually F12), then open the app in Onshape and see if any errors or warnings appear in the Console or the Network tab.
Occasionally, a process will fail to fully shut down, causing problems when you next attempt to Launch servers since the port is already taken.
If a process fails to start because a port is already taken, you can kill the process squatting on the port by running lsof -i :<port number>, e.g., lsof -i :3000, to get the PID of the process.
You can then kill the process using kill <PID> (or, possibly, kill -9 <PID>).