Intelligent formula auditing with AI-powered insights, policy compliance checks, and real-time recommendations
- Overview
- Key Features
- Architecture
- Tech Stack
- Getting Started
- Deployment
- Usage
- API Reference
- Project Structure
- Contributing
- License
SheetBrain AI is an intelligent Google Sheets add-on that automatically audits spreadsheet formulas using advanced AI models. It analyzes formulas for compliance, best practices, potential errors, and performance issuesβproviding actionable recommendations in real-time.
- β Automated Compliance - Enforce organizational policies across all spreadsheets
- π Error Detection - Catch circular references, division by zero, and logic errors
- π Performance Optimization - Identify slow formulas and suggest faster alternatives
- π€ AI-Powered Analysis - Leverages Claude 3.5 Sonnet via OpenRouter for intelligent insights
- π― Risk Assessment - Categorizes formulas by risk level (low/medium/high)
- π Contextual Recommendations - Provides specific, actionable improvement suggestions
- Real-time Analysis - Instant feedback on formula quality and compliance
- Multi-Formula Support - Audit entire ranges in a single request
- Context-Aware - Understands sheet purpose, department, and organizational context
- Policy Enforcement - Custom policy rules with default best practices
- Clerk Integration - Enterprise-grade authentication
- JWT Tokens - Secure API access with 15-minute access tokens
- Organization Support - Multi-tenant architecture with org-level policies
- Rate Limiting - 100 requests/minute per user
- Compliance Status - Clear pass/fail indicators for each formula
- Risk Scoring - Low, medium, high risk classification
- Issue Tracking - Detailed list of problems found
- Recommendations - Specific suggestions for improvement
- Performance Metrics - Audit duration and token usage
- Google Sheets Integration - Native sidebar interface
- Responsive Design - Clean, intuitive user experience
- Visual Indicators - Color-coded risk levels and status badges
- Real-time Feedback - Loading states and progress indicators
βββββββββββββββββββ
β Google Sheets β
β Add-on UI β
ββββββββββ¬βββββββββ
β HTTPS
βΌ
βββββββββββββββββββββββββββββββββββββββ
β Vercel (Backend) β
β ββββββββββββββββββββββββββββββββ β
β β Next.js 15 App Router β β
β β ββββββββββ ββββββββββββ β β
β β β Auth β β Audit β β β
β β β API βββββΆβ API β β β
β β ββββββββββ ββββββββββββ β β
β β β β β β
β β βΌ βΌ β β
β β ββββββββββ ββββββββββββ β β
β β β Clerk β βOpenRouterβ β β
β β β JWT β β (Claude) β β β
β β ββββββββββ ββββββββββββ β β
β ββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββ
- User Action - Select formulas in Google Sheets
- Authentication - Apps Script obtains JWT token via debug-login
- Audit Request - Send formulas + context to
/api/audit - AI Processing - OpenRouter analyzes with Claude 3.5 Sonnet
- Response - Structured results with compliance, risks, recommendations
- Display - Render results in sidebar with visual indicators
- Framework - Next.js 15 (App Router)
- Language - TypeScript 5.x
- Authentication - Clerk with JWT
- AI/LLM - OpenRouter + Anthropic SDK
- Deployment - Vercel (Portland, pdx1)
- Package Manager - pnpm 10.x
- Platform - Google Apps Script
- Build Tool - Webpack 5
- Language - TypeScript compiled to ES5
- Deployment - clasp
@anthropic-ai/sdk- Claude AI integrationjose- JWT handlingnext- React frameworktypescript- Type safetywebpack- Module bundler
- Node.js 20.x or higher
- pnpm 10.x or higher
- Google Account with Apps Script enabled
- Vercel Account (for deployment)
- API Keys:
- Clerk API key
- OpenRouter API key
- Clone the repository
git clone https://github.com/yocho1/SheetBrain-AI.git
cd SheetBrain-AI- Install dependencies
pnpm install- Configure environment variables
cd backend
cp .env.example .env.localEdit .env.local with your credentials:
# Required
CLERK_SECRET_KEY=sk_test_xxx...
SESSION_SECRET=your-32-char-secret
OPENROUTER_API_KEY=sk-or-v1-xxx...
LLM_PROVIDER=openrouter
STRICT_AUDIT=true
# Optional
NEXT_PUBLIC_API_BASE_URL=http://localhost:3000
NODE_ENV=development- Start development server
pnpm devBackend will run at http://localhost:3000
PowerShell:
# Get JWT token
$jwt = (Invoke-RestMethod -Uri "http://localhost:3000/api/auth/debug-login" -Method Post -Body (@{
userId="test_user"
email="test@sheetbrain.com"
orgId="test_org"
role="editor"
} | ConvertTo-Json) -ContentType "application/json").accessToken
# Test audit endpoint
$body = @{
range = "A1:A3"
context = @{
sheetName="Sheet1"
range="A1:A3"
organization="Test Corp"
department="Finance"
sheetPurpose="Formula Analysis"
data=@{
formulas=@(
@("=SUM(B1:B10)", "", "")
@("=IF(C1>100,'High','Low')", "", "")
@("=VLOOKUP(D1,E1:F10,2,FALSE)", "", "")
)
}
}
} | ConvertTo-Json -Depth 6
Invoke-RestMethod -Uri "http://localhost:3000/api/audit" -Method Post -Headers @{ Authorization = "Bearer $jwt" } -Body $body -ContentType "application/json" | ConvertTo-Json -Depth 6Bash:
# Get JWT token
JWT=$(curl -s -X POST http://localhost:3000/api/auth/debug-login \
-H "Content-Type: application/json" \
-d '{"userId":"test_user","email":"test@sheetbrain.com","orgId":"test_org","role":"editor"}' | jq -r '.accessToken')
# Test audit endpoint
curl -X POST http://localhost:3000/api/audit \
-H "Authorization: Bearer $JWT" \
-H "Content-Type: application/json" \
-d '{
"range": "A1:A3",
"context": {
"sheetName": "Sheet1",
"organization": "Test Corp",
"data": {
"formulas": [["=SUM(B1:B10)"], ["=IF(C1>100,\"High\",\"Low\")"], ["=VLOOKUP(D1,E1:F10,2,FALSE)"]]
}
}
}'- Push to GitHub
git add .
git commit -m "feat: initial deployment"
git push origin main- Deploy to Vercel
cd backend
vercel --prod-
Configure environment variables in Vercel Dashboard:
CLERK_SECRET_KEYSESSION_SECRETOPENROUTER_API_KEYSTRICT_AUDIT=trueLLM_PROVIDER=openrouter
-
Set Root Directory to
backendin Vercel project settings
Production URL: https://sheetbrain-ai.vercel.app
- Build the add-on
cd apps-script
pnpm build- Update backend URL in
src/index.ts:
return 'https://sheetbrain-ai.vercel.app';- Deploy to Google Apps Script
pnpm clasp login
pnpm clasp create --type sheets --title "SheetBrain AI"
pnpm clasp push --force-
Open your Google Sheet and paste the code from
apps-script-standalone-code.js -
Run
onOpenfunction from Apps Script editor to create the menu
-
Open your Google Sheet
-
Access SheetBrain AI
- Look for "SheetBrain AI" menu in the top menu bar
- Click "SheetBrain AI" β "Open Audit Panel"
-
Select formulas to audit
- Click on cells containing formulas
- Select a range (e.g., A1:A10)
-
Run audit
- Click "Run Audit" button in the sidebar
- Wait for AI analysis (typically 2-5 seconds)
-
Review results
- β Compliant formulas (green)
- β Non-compliant formulas (red)
- Risk levels: Low, Medium, High
- Detailed issues and recommendations
Formula 1: A1
β COMPLIANT Risk: LOW
=SUM(B1:B10)
β No issues found
Formula 2: A2
β NON-COMPLIANT Risk: HIGH
=SUM(B1:B10)/0
β Issues:
- Division by zero error
- Will produce #DIV/0! error
π‘ Recommendations:
- Add error handling: =IFERROR(SUM(B1:B10)/C1, 0)
- Validate divisor is non-zero
POST /api/auth/debug-login
Content-Type: application/json
{
"userId": "test_user",
"email": "test@example.com",
"orgId": "test_org",
"role": "editor"
}Response:
{
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}POST /api/audit
Authorization: Bearer <access_token>
Content-Type: application/json
{
"range": "A1:A5",
"context": {
"sheetName": "Q1 Report",
"organization": "Acme Corp",
"department": "Finance",
"sheetPurpose": "Quarterly reconciliation",
"data": {
"formulas": [
["=SUM(B1:B10)"],
["=IF(C1>100,'High','Low')"],
["=VLOOKUP(D1,Sheet2!A:B,2,FALSE)"]
]
}
}
}Response:
{
"success": true,
"audits": [
{
"cellAddress": "A1",
"formula": "=SUM(B1:B10)",
"compliant": true,
"risk": "low",
"issues": [],
"recommendations": ["Consider using SUMIF for conditional sums"]
},
{
"cellAddress": "A2",
"formula": "=IF(C1>100,'High','Low')",
"compliant": true,
"risk": "low",
"issues": [],
"recommendations": []
},
{
"cellAddress": "A3",
"formula": "=VLOOKUP(D1,Sheet2!A:B,2,FALSE)",
"compliant": false,
"risk": "medium",
"issues": ["Cross-sheet reference may be slow", "VLOOKUP fragile to column changes"],
"recommendations": [
"Consider XLOOKUP for better performance",
"Use named ranges for maintainability"
]
}
],
"count": 3,
"compliant": 2,
"timestamp": "2025-12-31T15:00:00Z",
"duration": 2847
}{
"error": "No formulas found in the provided range/context",
"status": 400
}{
"error": "Unauthorized",
"status": 401
}SheetBrain-AI/
βββ backend/ # Next.js backend
β βββ src/
β β βββ app/
β β β βββ api/
β β β β βββ audit/ # Formula audit endpoint
β β β β βββ auth/ # Authentication endpoints
β β β βββ layout.tsx
β β βββ lib/
β β βββ llm/ # OpenRouter integration
β β βββ auth/ # JWT & Clerk helpers
β β βββ policies/ # Policy management
β βββ .env.local # Environment variables
β βββ package.json
β βββ vercel.json # Vercel config
β
βββ apps-script/ # Google Apps Script add-on
β βββ src/
β β βββ index.ts # Entry point & menu
β β βββ services/ # API client
β β βββ ui/ # Sidebar HTML
β βββ dist/ # Compiled output
β βββ webpack.config.js
β βββ package.json
β
βββ shared/ # Shared types (future)
βββ .gitignore
βββ README.md
βββ package.json # Workspace root
Contributions are welcome! Please follow these steps:
-
Fork the repository
-
Create a feature branch
git checkout -b feature/amazing-feature-
Make your changes
- Follow existing code style
- Add tests if applicable
- Update documentation
-
Commit your changes
git commit -m "feat: add amazing feature"- Push to your fork
git push origin feature/amazing-feature- Open a Pull Request
We use Conventional Commits:
feat:- New featurefix:- Bug fixdocs:- Documentation changesstyle:- Code style changes (formatting, etc.)refactor:- Code refactoringtest:- Adding testschore:- Maintenance tasks
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenRouter - AI model routing
- Anthropic - Claude AI models
- Clerk - Authentication infrastructure
- Vercel - Deployment platform
- Google - Apps Script platform
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: support@sheetbrain.ai
Made with β€οΈ by yocho1
β Star this repo if you find it helpful!