π 5-Minute Setup: A Minimal Multi-User OKR Tracker Powered by Cloudflare (Free, Serverless Full Stack)
In today’s fast-paced world, the OKR (Objectives and Key Results) framework has become the go-to method for managing goals. But why not leverage Serverless technologies to quickly build your own free, secure OKR tracker?
In this guide, we’ll walk through how to use Cloudflare Pages, Workers, and Workers KV to build a full-stack OKR tracking app with multi-user data isolation from scratch. To simplify deployment, the code snippets are turned into ready-to-use prompts. You can feed them into a large model (e.g., Grok or other AI) to generate full code that you can customize or extend.
π― Key Highlights
- Full-Stack Serverless: No server management required, fully running on Cloudflare’s edge network.
- Multi-User Isolation: Use Cloudflare Access for secure authentication, ensuring each user’s data is isolated and separate.
- Minimal Cost: Perfectly leverages Cloudflare Pages, Workers, and Zero Trust’s free tiers.
- Low Latency: Data stored in KV with a globally distributed network, ensuring fast read speeds.
Architecture Overview
The app uses a decoupled front-end and back-end architecture, with Cloudflare Access injecting user identity headers for secure authentication and data isolation.
Tech Stack:
- Frontend: Single Page Application (SPA) hosted on Cloudflare Pages.
- Backend: Business logic handled by Cloudflare Workers.
- Database: Persistent storage using Cloudflare Workers KV.
- Authentication & Security: Managed through Cloudflare Access.
π οΈ Step 1: Set Up Environment and Code
-
Create KV Namespace In the Cloudflare dashboard, go to
Workers & Pages β KV β Create Namespace, name itOKR_STORAGE. -
Deploy Workers Backend Use the following prompt to generate the Workers code and deploy it to your Workers service.
- Bind KV: In Workers settings, bind the
OKR_STORAGEKV namespace to the variableOKR_STORAGE. - Set Route: Configure routes for frontend and API cookie sharing. Recommended route:
okr.yourdomain.com/api/*.
- Bind KV: In Workers settings, bind the
-
Deploy Pages Frontend Use the following prompt to generate the
app.jscode for the frontend and deploy it to Cloudflare Pages.- Important Change: Ensure the
WORKER_URLinapp.jspoints to your Pages domain. Example:const WORKER_URL = "https://okr.yourdomain.com";
- Important Change: Ensure the
π Step 2: Configure Multi-User Isolation (Cloudflare Access)
-
Enable Cloudflare Zero Trust Log in to Cloudflare and complete the basic setup in the
Zero Trustdashboard. -
Configure Identity Provider (IdP)
- Go to
Settings β Authentication β Login Methods. - Add your preferred login methods, such as One-time PIN (email verification) or Google/GitHub login.
- Go to
-
Create Access Application
- In
Access β Applications β Add an application, create an app:- Application name:
OKR Tracker - Subdomain:
okr.yourdomain.com - Cookie Domain: If using a unified domain, no need to configure this.
- Application name:
- In
-
Define Access Policy
- Policy name:
Authorized Users - Action:
Allow - Include: For example,
Email Ends with @yourdomain.com.
- Policy name:
-
Header Injection Once a user successfully logs in, Cloudflare Access automatically injects a
CF-Access-Authenticated-User-Emailheader into requests to identify the user.
π» Project Code Prompts (Feed to Large Models)
1. Workers Backend Code Prompt (Multi-User Isolation)
Generate a Cloudflare Workers JavaScript code for a multi-user OKR tracker backend API. Key features:
- Retrieve the user's email from the 'Cf-Access-Authenticated-User-Email' header. If missing, return 401 Unauthorized.
- Normalize the email to lowercase and use it as a KV key prefix.
- Support the following API endpoints:
- GET /api/okr/periods: Get a list of user periods.
- POST /api/okr/periods: Add a new period.
- GET /api/okr/{period}: Retrieve OKR data for a specific period.
- PUT /api/okr/{period}: Update OKR data for a specific period.
- DELETE /api/okr/{period}: Delete OKR data for a specific period.
- Pages Frontend app.js Code Prompt
Generate a JavaScript code for Cloudflare Pages frontend OKR tracker SPA. Key features:
- Use a unified `apiFetch` function to interact with the backend.
- Support adding, editing, and deleting periods and OKRs.
π Congratulations!
With Cloudflare Pages, Workers, and Zero Trust, you’ve successfully built a personal OKR tracker with enterprise-level security and data isolation. You can now securely share your tracker with friends or team members, knowing your data is safe and separated!