An AI-powered code review application built on Cloudflare Workers, featuring real-time code analysis, detailed feedback, and conversation history.
Try it now: https://cf-ai-code-review-frontend.pages.dev
| Component | URL |
|---|---|
| Frontend | https://cf-ai-code-review-frontend.pages.dev |
| Backend API | https://cf-ai-code-review.wuchuoxi.workers.dev |
- Live Demo
- Features
- Requirements
- Setup Instructions
- Project Structure
- Usage
- Components
- Testing
- API Endpoints
- Troubleshooting
- Architecture & Improvements
- Technologies Used
- Documentation
- AI-Powered Code Review: Uses Llama 3.3 70B (via Cloudflare Workers AI) to analyze code across multiple dimensions
- Comprehensive Feedback: Reviews security, performance, code quality, best practices, and potential bugs
- Multi-Language Support: Supports 12 programming languages (JavaScript, TypeScript, Python, Java, Go, Rust, C++, C, PHP, Ruby, Swift, Kotlin)
- Conversation Memory: Maintains review history and allows follow-up questions using Durable Objects
- Export Functionality: Export reviews as Markdown or JSON
- Search & Filter: Search review history by code, language, summary, or score
- Caching: In-memory caching for instant repeated reviews
- Diff Review: Review unified diffs with file-by-file analysis and line-specific feedback
- GitHub PR Integration: Review pull requests directly from GitHub URLs with automatic diff extraction
- GitHub Authentication: OAuth 2.0 authentication for accessing private repositories
- Review Sharing: Generate shareable links for code reviews (30-day expiration)
- Analytics Dashboard: Track review statistics, score trends, category breakdowns, and language usage
- Dark/Light Theme: System-aware theme switching with smooth transitions
- Multi-Mode Interface: Switch between Code, Diff, and GitHub PR review modes
- User Management: User profiles, session linking, and authentication state management
- Modern UI: Built with React, Tailwind CSS, and shadcn/ui components with React Bits-inspired animations
- Real-time Analysis: Fast, responsive code review with detailed categorization
- Enhanced Animations: Scroll-triggered reveals, floating effects, skeleton loaders, and smooth micro-interactions
- Responsive Design: Mobile-friendly layouts and adaptive components
- Node.js 18+ and npm
- Cloudflare account with Workers AI enabled
- Wrangler CLI installed globally or locally
From the project root:
npm install
cd frontend && npm install-
Login to Cloudflare:
npx wrangler login
-
Update
wrangler.toml:- Ensure your Cloudflare account ID is set (optional, can be auto-detected)
- The Durable Objects binding is already configured
-
Deploy Durable Objects (first time only):
npx wrangler deploy
Create a .dev.vars file in the root directory (for local development):
# Optional: Add any environment variables here
ENVIRONMENT=development
# GitHub OAuth (optional, for GitHub PR reviews and authentication)
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
AUTH_SECRET=your_random_secret_key_for_jwt_signing
# Optional: GitHub token for public PR reviews (fallback if user not authenticated)
GITHUB_TOKEN=your_github_personal_access_tokenSetting up GitHub OAuth:
- Go to GitHub Settings β Developer settings β OAuth Apps
- Create a new OAuth App
- Set Authorization callback URL to:
- Development:
http://localhost:8787/api/auth/github/callback - Production:
https://cf-ai-code-review.wuchuoxi.workers.dev/api/auth/github/callback
- Development:
- Copy Client ID and Client Secret to
.dev.vars(dev) or usewrangler secret put(production) - Generate a random secret for
AUTH_SECRET(e.g., usingopenssl rand -base64 32)
Terminal 1 - Frontend:
cd frontend
npm run devFrontend will run on http://localhost:5173
Terminal 2 - Worker:
npx wrangler devWorker will run on http://localhost:8787
Update Frontend API URL:
Create frontend/.env.local:
VITE_API_URL=http://localhost:8787npm run devThis uses concurrently to run both frontend and worker.
# Build frontend
cd frontend && npm run build
# Deploy worker
npx wrangler deployThe application is deployed to Cloudflare with the following URLs:
- Frontend: https://cf-ai-code-review-frontend.pages.dev
- Backend: https://cf-ai-code-review.wuchuoxi.workers.dev
# Build and deploy
npm run build
npx wrangler deploy# Build with production API URL
cd frontend
VITE_API_URL=https://cf-ai-code-review.wuchuoxi.workers.dev npm run build
cd ..
# Deploy to Pages
npx wrangler pages deploy frontend/dist --project-name cf-ai-code-review-frontendnpx wrangler secret put GITHUB_CLIENT_ID
npx wrangler secret put GITHUB_CLIENT_SECRET
npx wrangler secret put AUTH_SECRETFor production, configure your GitHub OAuth App with:
- Homepage URL:
https://cf-ai-code-review-frontend.pages.dev - Authorization callback URL:
https://cf-ai-code-review.wuchuoxi.workers.dev/api/auth/github/callback
cf_ai_code_review/
βββ frontend/ # React + Vite frontend
β βββ src/
β β βββ components/ # React components
β β β βββ ui/ # shadcn/ui components
β β β βββ analytics/ # Analytics components
β β β β βββ StatCard.tsx
β β β β βββ ScoreChart.tsx
β β β β βββ CategoryBreakdown.tsx
β β β βββ CodeInput.tsx
β β β βββ ReviewDisplay.tsx
β β β βββ DiffInput.tsx
β β β βββ DiffViewer.tsx
β β β βββ DiffReviewDisplay.tsx
β β β βββ GitHubPRInput.tsx
β β β βββ AnalyticsDashboard.tsx
β β β βββ ShareButton.tsx
β β β βββ SharedReviewPage.tsx
β β β βββ LoginButton.tsx
β β β βββ UserMenu.tsx
β β β βββ ThemeToggle.tsx
β β β βββ ConversationHistory.tsx
β β β βββ FollowUpInput.tsx
β β β βββ ScoreCounter.tsx
β β β βββ SkeletonLoader.tsx
β β β βββ BackgroundGrid.tsx
β β β βββ TextReveal.tsx
β β βββ context/ # React contexts
β β β βββ AuthContext.tsx
β β βββ hooks/ # Custom React hooks
β β β βββ useScrollReveal.ts
β β β βββ useAuth.ts
β β β βββ useTheme.ts
β β β βββ useAnalytics.ts
β β βββ lib/ # Utilities
β β β βββ api.ts # API client
β β β βββ cache.ts # Review caching
β β β βββ export.ts # Export functionality
β β βββ types/ # TypeScript types
β β βββ App.tsx # Main app component
β β βββ main.tsx # Entry point
βββ src/
β βββ worker/ # Cloudflare Worker
β βββ index.ts # Main entry point
β βββ routes.ts # API route handlers
β βββ llm.ts # LLM integration (code review)
β βββ llm-diff.ts # LLM integration (diff review)
β βββ diff.ts # Diff parsing utilities
β βββ github.ts # GitHub API integration
β βββ auth.ts # Authentication utilities
β βββ auth-routes.ts # Authentication routes
β βββ share.ts # Review sharing utilities
β βββ analytics.ts # Analytics calculations
β βββ durable-object.ts # Session Durable Object
β βββ user-durable-object.ts # User Durable Object
β βββ config.ts # Configuration management
β βββ errors.ts # Custom error classes
β βββ validation.ts # Input validation
β βββ cors.ts # CORS handling
β βββ types.ts # TypeScript types
βββ wrangler.toml # Cloudflare configuration
βββ package.json
βββ README.md # This file
βββ PROMPTS.md # AI prompts documentation
-
Start the application:
npm run dev
-
Open the frontend in your browser:
http://localhost:5173 -
Try out the components:
LLM (Workers AI):
- Submit code for review to see Llama 3.3 70B analyze your code
- Try the test code below to see security vulnerability detection
User Input (Pages/Frontend):
- Paste code in the text area
- Select programming language
- Click "Review Code" to submit
Memory/State (Durable Objects):
- All reviews are automatically saved
- View review history in the sidebar
- Click any review to view it again
- Follow-up questions maintain conversation context
Workflow/Coordination (Workers + Durable Objects):
- Worker coordinates between AI, storage, and frontend
- Durable Objects manage session state and review history
- Request timeouts and error handling ensure reliability
-
Paste this test code:
function login(username, password) { const query = `SELECT * FROM users WHERE username='${username}' AND password='${password}'`; return db.query(query); }
-
Select "Javascript" from the language dropdown
-
Click "Review Code"
-
View results:
- Review score (1-10)
- Categorized feedback (Security, Performance, Quality, Best Practices, Bugs)
- Detailed suggestions with code examples
-
Try follow-up questions:
- Scroll to "Ask a Follow-up Question"
- Ask: "Can you explain the SQL injection vulnerability?"
- Get detailed explanations
-
Explore features:
- Export reviews (MD or JSON buttons)
- Search review history
- Submit same code twice to see caching in action
- Share reviews with shareable links
- View analytics dashboard
- Switch between Code, Diff, and GitHub PR modes
- Toggle dark/light theme
Core Review Components:
- CodeInput: Code input area with language selection
- DiffInput: Unified diff input with file upload support
- GitHubPRInput: GitHub PR URL input with authenticated user PR selector
- ReviewDisplay: Displays review results in categorized tabs
- DiffReviewDisplay: File-by-file diff review results
- DiffViewer: Visual diff display with syntax highlighting
- ConversationHistory: Sidebar showing all past reviews
- FollowUpInput: Input for asking follow-up questions
Feature Components:
- AnalyticsDashboard: Review statistics and trends
- ShareButton: Generate and copy shareable review links
- SharedReviewPage: Public view for shared reviews
- LoginButton: GitHub OAuth authentication
- UserMenu: User profile and logout menu
- ThemeToggle: Light/dark mode switcher
UI Components:
- SkeletonLoader: Loading state placeholders
- BackgroundGrid: Animated background effects
- TextReveal: Scroll-triggered text animations
- ScoreCounter: Animated score display
- Worker (index.ts): Main API gateway
- Routes: Handles all API endpoints (review, diff, PR, auth, share, analytics)
- LLM Integration: Interfaces with Llama 3.3 via Workers AI
llm.ts: Code review promptsllm-diff.ts: Diff review prompts
- Durable Objects:
durable-object.ts: Session state and review historyuser-durable-object.ts: User profiles and tokens
- GitHub Integration:
github.ts- PR fetching, user PRs, comment posting - Authentication:
auth.ts- OAuth flow, JWT tokens, user management - Sharing:
share.ts- Short ID generation, KV storage - Analytics:
analytics.ts- Statistics calculation - Diff Parsing:
diff.ts- Unified diff parser
Try this sample JavaScript code:
function login(username, password) {
const query = `SELECT * FROM users WHERE username='${username}' AND password='${password}'`;
return db.query(query);
}The AI should identify:
- SQL injection vulnerability (Security)
- Missing input validation (Best Practices)
- Plain text password storage (Security)
Test the following features:
- Code Review: Export functionality (Markdown and JSON), follow-up questions, search/filter in review history, caching (submit same code twice), multiple programming languages
- Diff Review: Upload a .diff file, paste a unified diff, review with context
- GitHub PR Review: Review a public PR, authenticate and review private PRs, select from your open PRs
- Sharing: Share a review and access it via the shareable link
- Analytics: View dashboard with statistics, score trends, and category breakdowns
- Authentication: Sign in with GitHub, access private repos, logout
- Theme: Toggle between light and dark modes
Submit code for review.
Request:
{
"code": "function test() { return true; }",
"language": "javascript",
"sessionId": "optional-session-id"
}Response:
{
"review": {
"score": 8,
"summary": "...",
"categories": { ... }
},
"sessionId": "uuid"
}Get review history for a session.
Response:
{
"reviews": [...]
}Ask a follow-up question.
Request:
{
"question": "Can you explain the security issue?",
"reviewId": "review-uuid"
}Response:
{
"answer": "..."
}Review a unified diff.
Request:
{
"diff": "diff --git a/file.js b/file.js\n...",
"context": "optional context",
"sessionId": "optional-session-id"
}Response:
{
"review": {
"score": 7,
"summary": "...",
"fileReviews": [...],
"overallSuggestions": [...]
},
"parsedDiff": { ... },
"sessionId": "uuid"
}Review a GitHub pull request.
Request:
{
"prUrl": "https://github.com/owner/repo/pull/123",
"sessionId": "optional-session-id"
}Response:
{
"review": { ... },
"parsedDiff": { ... },
"prInfo": {
"title": "...",
"author": "...",
"baseBranch": "...",
"headBranch": "...",
"additions": 100,
"deletions": 50,
"changedFiles": 5
},
"sessionId": "uuid"
}Get authenticated user's open pull requests.
Response:
{
"pulls": [...],
"totalCount": 10
}Post a comment to a GitHub PR.
Request:
{
"prUrl": "https://github.com/owner/repo/pull/123",
"comment": "Review comment text"
}Response:
{
"success": true,
"commentUrl": "https://github.com/...",
"commentId": 123456
}Initiate GitHub OAuth flow.
Query Parameters:
redirectUrl: Frontend redirect URL after authsessionId: Optional session ID to link
Response: Redirects to GitHub OAuth
OAuth callback endpoint (handled by GitHub redirect).
Get current authenticated user.
Response:
{
"user": {
"id": "github:123",
"githubLogin": "username",
"displayName": "User Name",
"avatarUrl": "...",
"email": "..."
}
}Logout current user.
Response:
{
"success": true
}Create a shareable link for a review.
Request:
{
"reviewId": "review-uuid",
"sessionId": "session-uuid"
}Response:
{
"shortId": "abc123",
"shareUrl": "https://..."
}Get a shared review by short ID.
Response:
{
"shortId": "abc123",
"sessionId": "...",
"reviewId": "...",
"codeReview": { ... },
"createdAt": "...",
"expiresAt": "..."
}Get analytics data for a session.
Query Parameters:
sessionId: Session ID
Response:
{
"totalReviews": 10,
"averageScore": 7.5,
"scoreDistribution": { ... },
"categoryBreakdown": { ... },
"languageStats": { ... },
"reviewsOverTime": [ ... ]
}- Ensure you're logged in:
npx wrangler login - Check
wrangler.tomlconfiguration - Verify Workers AI is enabled in your Cloudflare account
- Check
VITE_API_URLinfrontend/.env.local - Ensure worker is running on the correct port
- Check CORS headers in worker responses
- Verify Workers AI is enabled in your Cloudflare account
- Check API rate limits
- Review worker logs:
npx wrangler tail
- Ensure Durable Objects are deployed:
npx wrangler deploy - Check binding name matches in
wrangler.toml
- Security: Configurable CORS, input validation, request timeouts
- Type Safety: Full TypeScript with proper interfaces (no
anytypes) - Error Handling: Custom error classes with user-friendly messages
- Performance: In-memory caching, optimized data storage, request timeouts
- User Experience: Export functionality, search/filter, better error messages
- Configuration: Environment-aware configuration management
- Frontend: React 19 + TypeScript + Vite + Tailwind CSS + shadcn/ui
- UI Enhancements: React Bits-inspired animations (scroll reveals, skeleton loaders, background effects)
- Backend: Cloudflare Workers + Durable Objects + KV Storage
- AI: Llama 3.3 70B via Cloudflare Workers AI (
@cf/meta/llama-3.3-70b-instruct-fp8-fast) - Storage:
- Durable Objects for session persistence (30-day TTL, max 50 reviews per session)
- Durable Objects for user data and authentication tokens
- KV Storage for OAuth state (10-minute TTL) and shared reviews (30-day TTL)
- Caching: In-memory cache (1-hour TTL, max 50 entries)
- Authentication: GitHub OAuth 2.0 with JWT tokens stored in HttpOnly cookies
- External APIs: GitHub API for PR fetching and commenting
- README.md - Complete project documentation with setup and running instructions
- PROMPTS.md - All AI prompts used in the application (required for assessment submission)
This project meets all Cloudflare AI assignment requirements:
- β LLM: Uses Llama 3.3 70B via Cloudflare Workers AI
- β Workflow/Coordination: Cloudflare Workers + Durable Objects for state management
- β User Input: React frontend (Cloudflare Pages compatible) with code input interface
- β Memory/State: Durable Objects for session persistence and review history
- β
Repository Name: Prefixed with
cf_ai_(cf_ai_code_review) - β README.md: Includes project documentation and clear running instructions
- β PROMPTS.md: Documents all AI prompts used in the application
- Cloudflare Workers Documentation
- Workers AI Documentation
- Durable Objects Documentation
- shadcn/ui Documentation
MIT License
- Built with Cloudflare Workers
- UI components from shadcn/ui
- AI powered by Llama 3.3 via Cloudflare Workers AI