Skip to content

yocho1/SheetBrain-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

40 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 SheetBrain AI

AI-Powered Formula Auditor for Google Sheets

License: MIT Next.js TypeScript Vercel

Intelligent formula auditing with AI-powered insights, policy compliance checks, and real-time recommendations

πŸš€ Live Demo β€’ πŸ“– Documentation β€’ πŸ› Report Bug


πŸ“‹ Table of Contents


🌟 Overview

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.

Why SheetBrain AI?

  • βœ… 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

✨ Key Features

🎯 Smart Formula Auditing

  • 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

πŸ›‘οΈ Security & Authentication

  • 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

πŸ“Š Comprehensive Results

  • 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

🎨 Modern UI

  • 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

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Google Sheets  β”‚
β”‚    Add-on UI    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ HTTPS
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Vercel (Backend)               β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚   Next.js 15 App Router      β”‚   β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚   β”‚
β”‚  β”‚  β”‚ Auth   β”‚    β”‚  Audit   β”‚  β”‚   β”‚
β”‚  β”‚  β”‚  API   │───▢│   API    β”‚  β”‚   β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚   β”‚
β”‚  β”‚       β”‚              β”‚        β”‚   β”‚
β”‚  β”‚       β–Ό              β–Ό        β”‚   β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚   β”‚
β”‚  β”‚  β”‚ Clerk  β”‚    β”‚OpenRouterβ”‚  β”‚   β”‚
β”‚  β”‚  β”‚  JWT   β”‚    β”‚ (Claude) β”‚  β”‚   β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow

  1. User Action - Select formulas in Google Sheets
  2. Authentication - Apps Script obtains JWT token via debug-login
  3. Audit Request - Send formulas + context to /api/audit
  4. AI Processing - OpenRouter analyzes with Claude 3.5 Sonnet
  5. Response - Structured results with compliance, risks, recommendations
  6. Display - Render results in sidebar with visual indicators

πŸ› οΈ Tech Stack

Backend

Frontend (Apps Script)

Key Dependencies

  • @anthropic-ai/sdk - Claude AI integration
  • jose - JWT handling
  • next - React framework
  • typescript - Type safety
  • webpack - Module bundler

πŸš€ Getting Started

Prerequisites

  • 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

Installation

  1. Clone the repository
git clone https://github.com/yocho1/SheetBrain-AI.git
cd SheetBrain-AI
  1. Install dependencies
pnpm install
  1. Configure environment variables
cd backend
cp .env.example .env.local

Edit .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
  1. Start development server
pnpm dev

Backend will run at http://localhost:3000

Testing the API

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 6

Bash:

# 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)"]]
      }
    }
  }'

πŸš€ Deployment

Backend (Vercel)

  1. Push to GitHub
git add .
git commit -m "feat: initial deployment"
git push origin main
  1. Deploy to Vercel
cd backend
vercel --prod
  1. Configure environment variables in Vercel Dashboard:

    • CLERK_SECRET_KEY
    • SESSION_SECRET
    • OPENROUTER_API_KEY
    • STRICT_AUDIT=true
    • LLM_PROVIDER=openrouter
  2. Set Root Directory to backend in Vercel project settings

Production URL: https://sheetbrain-ai.vercel.app

Apps Script Add-on

  1. Build the add-on
cd apps-script
pnpm build
  1. Update backend URL in src/index.ts:
return 'https://sheetbrain-ai.vercel.app';
  1. Deploy to Google Apps Script
pnpm clasp login
pnpm clasp create --type sheets --title "SheetBrain AI"
pnpm clasp push --force
  1. Open your Google Sheet and paste the code from apps-script-standalone-code.js

  2. Run onOpen function from Apps Script editor to create the menu


πŸ“– Usage

In Google Sheets

  1. Open your Google Sheet

  2. Access SheetBrain AI

    • Look for "SheetBrain AI" menu in the top menu bar
    • Click "SheetBrain AI" β†’ "Open Audit Panel"
  3. Select formulas to audit

    • Click on cells containing formulas
    • Select a range (e.g., A1:A10)
  4. Run audit

    • Click "Run Audit" button in the sidebar
    • Wait for AI analysis (typically 2-5 seconds)
  5. Review results

    • βœ“ Compliant formulas (green)
    • βœ— Non-compliant formulas (red)
    • Risk levels: Low, Medium, High
    • Detailed issues and recommendations

Example Results

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

πŸ“š API Reference

Authentication

Debug Login (Development Only)

POST /api/auth/debug-login
Content-Type: application/json

{
  "userId": "test_user",
  "email": "test@example.com",
  "orgId": "test_org",
  "role": "editor"
}

Response:

{
  "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

Audit Endpoint

Audit Formulas

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 Responses

{
  "error": "No formulas found in the provided range/context",
  "status": 400
}
{
  "error": "Unauthorized",
  "status": 401
}

πŸ“ Project Structure

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

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository

  2. Create a feature branch

git checkout -b feature/amazing-feature
  1. Make your changes

    • Follow existing code style
    • Add tests if applicable
    • Update documentation
  2. Commit your changes

git commit -m "feat: add amazing feature"
  1. Push to your fork
git push origin feature/amazing-feature
  1. Open a Pull Request

Commit Convention

We use Conventional Commits:

  • feat: - New feature
  • fix: - Bug fix
  • docs: - Documentation changes
  • style: - Code style changes (formatting, etc.)
  • refactor: - Code refactoring
  • test: - Adding tests
  • chore: - Maintenance tasks

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments


πŸ“ž Support


Made with ❀️ by yocho1

⭐ Star this repo if you find it helpful!

About

Intelligent formula auditing with AI-powered insights, policy compliance checks, and real-time recommendations

Topics

Resources

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors