AI-powered code assistant built on Cloudflare
Chat with Llama 3.3 70B, get debugging help, and run multi-step code reviews — all with persistent memory.
- Streaming AI Chat — Real-time streaming responses from Llama 3.3 70B via Workers AI
- Conversation Memory — Messages persist across page reloads using Durable Objects with SQLite
- Project Context — Set your project details (e.g., "React + TypeScript app") so the AI gives tailored responses
- Multi-Step Code Review — Paste code and get a 3-step review via Cloudflare Workflows: structure analysis, issue detection, improvement suggestions
- Dark/Light Theme — Toggle between themes with Cloudflare-inspired color palette
- Clear History — Reset your conversation at any time
┌──────────────────────┐
│ Browser (Chat UI) │ Static HTML/CSS/JS
└──────────┬───────────┘
│
┌──────▼──────┐
│ Worker │ API Router (src/index.ts)
└──┬───────┬──┘
│ │
┌──────▼───┐ ┌─▼─────────────────┐
│ Durable │ │ Workflow │
│ Object │ │ (CodeReview) │
│(Session) │ │ │
│ │ │ Step 1: Analyze │
│ SQLite: │ │ Step 2: Find Issues│
│ messages │ │ Step 3: Suggest │
│ context │ │ Improvements │
└────┬─────┘ └────────┬──────────┘
│ │
└───────┬────────┘
│
┌──────▼──────┐
│ Workers AI │
│ Llama 3.3 │
│ 70B │
└─────────────┘
| Component | Technology |
|---|---|
| LLM | Llama 3.3 70B (@cf/meta/llama-3.3-70b-instruct-fp8-fast) via Workers AI |
| State/Memory | Durable Objects with embedded SQLite |
| Workflow | Cloudflare Workflows (durable execution engine) |
| Frontend | Static HTML/CSS/JS served via Workers Static Assets |
| Backend | Cloudflare Workers (TypeScript) |
- Node.js >= 18
- A Cloudflare account (free tier works)
- Wrangler CLI
git clone https://github.com/<your-username>/cf_ai_codistant.git
cd cf_ai_codistantnpm installnpx wrangler loginThis opens a browser window for OAuth authentication.
npm run devOpen http://localhost:8787 in your browser. The local dev server simulates Durable Objects and proxies Workers AI calls to Cloudflare's network.
npm run deployYour app will be live at https://cf-ai-codistant.<your-subdomain>.workers.dev.
| Method | Path | Description |
|---|---|---|
POST |
/api/chat |
Send a chat message. Body: { message, sessionId }. Returns SSE stream. |
GET |
/api/history?sessionId=xxx |
Get conversation history for a session. |
DELETE |
/api/history |
Clear history. Body: { sessionId }. |
POST |
/api/context |
Set user context. Body: { sessionId, key, value }. |
GET |
/api/context?sessionId=xxx |
Get all saved context for a session. |
POST |
/api/review |
Start a code review workflow. Body: { sessionId, code, language }. Returns { instanceId }. |
GET |
/api/review?instanceId=xxx |
Poll code review workflow status. |
cf_ai_codistant/
├── src/
│ ├── index.ts # Worker entry point & API router
│ ├── chat-session.ts # Durable Object: conversation memory & AI chat
│ ├── code-review-workflow.ts # Workflow: 3-step code review
│ └── types.ts # Shared TypeScript types
├── frontend/
│ ├── index.html # Chat UI
│ ├── app.js # Client-side logic (SSE, sessions, markdown)
│ ├── styles.css # Cloudflare-themed styles with dark/light mode
│ └── logo.svg # Codistant logo
├── wrangler.toml # Cloudflare Workers configuration
├── tsconfig.json # TypeScript configuration
├── package.json # Dependencies and scripts
├── README.md # This file
├── PROMPTS.md # AI prompts documentation
└── .gitignore
- User sends a message from the browser
- The Worker routes it to the user's Durable Object (identified by
sessionId) - The Durable Object stores the message in SQLite, builds a prompt with system message + project context + conversation history, and calls Workers AI
- The AI response streams back via Server-Sent Events (SSE) to the browser
- The full response is accumulated in the background and saved to SQLite for future context
- User pastes code in the sidebar and clicks "Run Code Review"
- The Worker creates a Cloudflare Workflow instance
- The Workflow runs 3 sequential AI steps (each with automatic retries):
- Analyze: Examines code structure and architecture
- Find Issues: Identifies bugs, security issues, and code smells
- Suggest Improvements: Provides actionable refactoring suggestions
- The browser polls for completion and displays the combined report
- Conversation history: Stored in SQLite within a Durable Object, one instance per
sessionId - Project context: Key-value pairs stored in SQLite, injected into the system prompt for every AI call
- Session ID: Generated client-side as a UUID and persisted in
localStorage
wrangler devruns a local development server that simulates Durable Objects and Workflows- Workers AI calls are proxied to Cloudflare's network (requires authentication via
wrangler login) - SQLite data is stored locally in the
.wrangler/directory during development - Changes to source files trigger automatic rebuilds