Skip to content

Latest commit

 

History

History
168 lines (130 loc) · 5.67 KB

File metadata and controls

168 lines (130 loc) · 5.67 KB

AutoInBox — AI-Powered Email Triage Engine

AI prepares, you approve. AutoInBox automatically classifies, prioritizes, and drafts replies for your emails using a multi-agent pipeline powered by Claude.

Problem & ROI

A knowledge worker receiving 100-500 emails/day spends 2-4 hours on manual triage. ~70% of emails are irrelevant or need simple routing. AutoInBox reduces this to under 15 minutes.

Cost savings: 3.75 hours/day × $50/hour × 22 work days = $4,125/month saved AI cost: ~$27/month (200 emails/day) → 152x ROI

System Architecture

graph TD
    A[Gmail API / OAuth] --> B[Ingestion Agent]
    B --> |Normalize & Dedup| C[Classification Agent]
    C --> |Claude API - 8 Categories| D[Priority Scorer]
    D --> |Weighted 0-100 Score| E[Draft Agent]
    E --> |Claude API - Reply Draft| F[(Supabase DB)]
    F --> G[Next.js Dashboard]
    G --> |Human Review| H{Approve / Edit / Reject}
    H --> |Send| A

    I[Redis] -.-> |Dedup Cache| B
    J[n8n] -.-> |Orchestration| B
Loading

Pipeline Flow

  1. Ingestion — Fetch unread emails via Gmail API, normalize headers, deduplicate via Redis
  2. Classification — Claude classifies into 8 categories with confidence score
  3. Priority Scoring — Weighted score (0-100) based on category, sender history, keywords, recency
  4. Draft Generation — Claude generates reply drafts for actionable emails
  5. Human Review — Dashboard for approve, edit, or reject with one click

Categories

Category Description
urgent Requires immediate attention today
action-needed Requires response, not time-critical
internal Company internal communication
support Customer support requests
sales Sales outreach and proposals
newsletter Newsletters and digests
fyi Informational, no action needed
spam Unsolicited, irrelevant

Tech Stack

Layer Tool
Backend FastAPI (Python 3.12)
LLM Claude 3.5 Sonnet
Database Supabase (PostgreSQL)
Cache Redis
Frontend Next.js 14 + Tailwind CSS
Orchestration n8n (self-hosted)
CI/CD GitHub Actions
Deploy Railway (backend) + Vercel (frontend)

Quick Start

# 1. Clone
git clone https://github.com/yourusername/autoinbox.git
cd autoinbox

# 2. Environment
cp .env.example .env
# Fill in your API keys

# 3. Backend
pip install -e ".[dev]"

# 4. Start services
docker compose -f docker/docker-compose.yml up -d

# 5. Run backend
uvicorn api.main:app --reload --port 8000

# 6. Frontend
cd frontend && npm install && npm run dev

# 7. Open http://localhost:3000

Privacy & Data Handling

  • PII Anonymization: Credit cards, IBANs, phone numbers, SSNs are masked before any LLM call
  • Row Level Security: Supabase RLS ensures data isolation
  • No Prompt Logging: Only token counts are recorded, not prompt content
  • Data Retention: Email body deleted after 90 days, metadata retained
  • Encrypted Storage: Full email bodies stored encrypted, only previews in DB

See ADR-003: Privacy & Email Data for details.

Cost Analysis

Operation Per Email Daily (200 emails) Monthly
Classification ~$0.002 $0.45 $13.50
Draft Generation ~$0.008 $0.45 (60 drafts) $13.50
Total $0.90 $27.00

API Endpoints

GET    /api/emails              # List emails (filter, sort, paginate)
GET    /api/emails/{id}         # Email detail
PATCH  /api/emails/{id}         # Update status
POST   /api/emails/{id}/process # Trigger classification + scoring

GET    /api/drafts/{email_id}          # Get draft
POST   /api/drafts/{email_id}/generate # Generate AI draft
PATCH  /api/drafts/{id}               # Edit draft
POST   /api/drafts/{id}/send          # Send via Gmail
POST   /api/drafts/{id}/reject        # Reject draft

POST   /api/webhooks/gmail     # Gmail push notification
POST   /api/webhooks/trigger   # Manual pipeline trigger
GET    /api/gmail/connect      # Start OAuth flow
GET    /api/metrics/daily      # Dashboard metrics
GET    /api/metrics/costs      # Cost tracking
GET    /health                 # Health check

Project Structure

autoinbox/
├── agents/                 # AI pipeline agents
│   ├── ingestion/          # Fetch, normalize, dedup
│   ├── classifier.py       # 8-category classification
│   ├── priority_scorer.py  # Weighted priority scoring
│   └── draft_writer.py     # AI draft generation
├── api/                    # FastAPI backend
│   ├── routers/            # API endpoints
│   ├── services/           # Supabase, Redis, Gmail
│   ├── models/             # Pydantic schemas
│   └── utils/              # PII anonymizer, cost tracker
├── frontend/               # Next.js 14 dashboard
├── n8n/                    # Workflow orchestration
├── supabase/               # Database migrations
├── tests/                  # Unit + integration tests
├── docker/                 # Docker Compose setup
└── docs/                   # Architecture, ADRs, runbook

Architecture Decision Records

Roadmap

  • Multi-user SaaS support
  • Outlook / IMAP support
  • Fine-tuned classification model
  • Custom category rules per user
  • Slack / Teams notifications
  • Analytics dashboard with trends

License

MIT