Gmail Client AI is a full-stack web application that replicates Gmail's core functionality while adding AI-powered draft generation. Built to handle 10,000+ emails with seamless performance, this project demonstrates expertise in full-stack development, cloud infrastructure, and system design.
- High-Performance Sync: Syncs 400-500 Gmail threads per minute
- Smooth UX: Handles 10,000+ threads with infinite scroll
- AI Integration: Context-aware email draft generation using Google's Gemini API
- Cloud-Native: Leverages AWS S3 for scalable email storage
- Secure: OAuth 2.0 authentication with proper token management
- Full Gmail Integration via Google OAuth 2.0
- Blazing-Fast Sync - Background synchronization with automatic scheduling
- Smart Threading - Proper conversation threading for replies and forwards
- Rich Email Rendering - HTML emails rendered from S3 with inline images
- Attachment Management - Upload, download, and inline display support
- Real-Time Search - Database-level search across subject, sender, and content
- Infinite Scroll - Smooth pagination for large mailboxes (10k+ threads)
- Label Management - Full support for Gmail labels and filters
- Compose & Reply - Full-featured email composition with proper threading
- Smart Draft Generation - Context-aware suggestions using Gemini API
- Interactive Editing - Review and customize AI-generated drafts
- Conversation Context - Analyzes entire thread for relevant responses
| Frontend | Backend | Database & Storage | External APIs |
|---|---|---|---|
| Next.js 15 | Next.js API Routes | PostgreSQL (Neon) | Gmail API |
| TypeScript | tRPC | AWS S3 | Google Gemini |
| Tailwind CSS | NextAuth.js | Redis | AWS SDK |
| shadcn/ui | Drizzle ORM | ||
| tRPC |
βββββββββββββββ OAuth ββββββββββββββββ
β Client β βββββββββββββββΊ β Google β
β (Browser) β β OAuth β
ββββββββ¬βββββββ ββββββββββββββββ
β
β tRPC
β
ββββββββΌβββββββββββββββββββββββββββββββββββββββ
β Next.js Application β
β ββββββββββββββ βββββββββββββββ β
β β tRPC β β NextAuth β β
β β API β β Session β β
β βββββββ¬βββββββ ββββββββ¬βββββββ β
β β β β
β βββββββΌββββββββββββββββββΌβββββββ β
β β Business Logic Layer β β
β β β’ GmailSyncService β β
β β β’ MessageService β β
β β β’ ThreadService β β
β βββββββ¬βββββββββββββββββββββββββ β
ββββββββββΌβββββββββββββββββββββββββββββββββββββ
β
ββββββ΄βββββ¬ββββββββββββββ¬βββββββββββββββ
β β β β
βββββΌββββ ββββΌβββ ββββββΌββββββ βββββΌβββββ
β Gmail β β S3 β βPostgreSQLβ β Gemini β
β API β β β β β β API β
βββββββββ βββββββ ββββββββββββ ββββββββββ
- Authentication: User authenticates via Google OAuth 2.0
- Sync Process:
- Fetch Gmail threads (400-500/min)
- Extract metadata β PostgreSQL
- Upload HTML bodies β S3
- Upload attachments β S3
- Display:
- Query metadata from PostgreSQL
- Fetch HTML from S3 (presigned URLs)
- Render in client with infinite scroll
- AI Draft:
- Extract thread context from DB
- Send to Gemini API
- Display generated draft for editing
- Node.js 18+
- PostgreSQL database (or Neon account)
- AWS account (S3 bucket)
- Google Cloud Console project (OAuth credentials)
- Gemini API key
- Clone the repository
git clone https://github.com/kanethuong/gmail-client-ai.git
cd gmail-client-ai- Install dependencies
npm install- Set up environment variables
cp .env.example .envConfigure the following in .env:
# Database
DATABASE_URL="postgresql://..."
DATABASE_URL_UNPOOLED="postgresql://..."
# Google OAuth
GOOGLE_CLIENT_ID="your-client-id"
GOOGLE_CLIENT_SECRET="your-client-secret"
# NextAuth
NEXTAUTH_SECRET="your-secret"
NEXTAUTH_URL="http://localhost:3000"
# AWS S3
AWS_ACCESS_KEY_ID="your-access-key"
AWS_SECRET_ACCESS_KEY="your-secret-key"
AWS_REGION="us-east-1"
S3_BUCKET_NAME="your-bucket-name"
# Gemini AI
GEMINI_API_KEY="your-gemini-key"
# Optional: Redis for caching
REDIS_URL="redis://..."-
Set up Google OAuth
- Go to Google Cloud Console
- Create a new project
- Enable Gmail API
- Create OAuth 2.0 credentials
- Add authorized redirect URI:
http://localhost:3000/api/auth/callback/google - Add scopes:
gmail.readonly,gmail.send
-
Set up AWS S3
- Create an S3 bucket
- Configure CORS for your domain
- Create IAM user with S3 access
- Generate access keys
-
Push database schema
npm run db:push- Run the development server
npm run devVisit http://localhost:3000
Comprehensive test suite with 98 tests covering:
# Run all tests
npm test
# Run with coverage
npm run test:coverage
# Run specific test suite
npm test gmail-api.test.tsTest Coverage:
- Unit tests for core services
- Integration tests for API routes
- System tests for database schema
- Workflow validation tests
- Push your code to GitHub
- Import project in Vercel
- Add environment variables
- Deploy!
Note: Set up Vercel Cron for scheduled sync:
// vercel.json
{
"crons": [{
"path": "/api/sync/scheduled",
"schedule": "0 */6 * * *"
}]
}docker build -t gmail-client-ai .
docker run -p 3000:3000 gmail-client-ai- β OAuth tokens encrypted in database
- β S3 presigned URLs with expiration (1 hour)
- β Environment variables never committed
- β Input validation with Zod
- β SQL injection prevention via ORM
- β User data isolation by user ID
- β HTTPS enforced in production
- Real-time sync via Gmail webhooks (push notifications)
- Advanced search with filters (date range, attachment type)
- Email templates and signatures
- Dark mode support
- Mobile responsive improvements
- Multi-account support
- Email scheduling
- Advanced AI features (summarization, categorization)