Enterprise-grade AI-powered email management platform with real-time IMAP synchronization, intelligent categorization, and RAG-based suggested replies.
GitHub Repository: https://github.com/chiragSahani/ai-based-inbox-onebox.git
- π§ Real-Time Email Sync - IMAP IDLE for β₯2 accounts (no polling, fetches last 100 emails)
- π€ AI Categorization - 11 intelligent categories using Google Gemini 2.5 Flash
- π Full-Text Search - Elasticsearch-powered search with multi-dimensional filtering
- π― Smart Filtering - Filter by account, folder, and AI category
- π¬ RAG-Based Replies - Context-aware AI replies using Qdrant vector database
- π¨ Webhook Integration - Idempotent Slack notifications on "Interested" emails
- π¨ Modern UI - Dark-themed Next.js 15 interface with shadcn/ui
- π± Responsive Design - Fully responsive with mobile support
- π‘οΈ Security - Helmet.js security headers, CORS, API key authentication
- β‘ Rate Limiting - 5 different rate limiters (API, Search, AI, Auth, Account)
- π Monitoring - 5 health check endpoints, metrics, and performance tracking
- π Feature Flags - Toggle services via environment variables
- π¨ Error Handling - Global error handler with custom error classes
- π Request Logging - Morgan + Pino structured logging with request IDs
- β Input Validation - Joi schema validation on all endpoints
- ποΈ MVC Architecture - Clean separation with Model-Service-Controller pattern
- π Idempotent Webhooks - Message-ID based deduplication
- π Graceful Shutdown - Clean resource cleanup on exit
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FRONTEND (Port 3000) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Next.js 15 + React 19 + shadcn/ui + Zustand β β
β β - 56 UI Components - Dark Theme - TypeScript β β
β ββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββ
β HTTP/REST API
βββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββ
β BACKEND (Port 5000) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Express 5 + TypeScript + MVC Architecture β β
β β - Security - Rate Limiting - Validation β β
β ββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββββ β
βββββββββββββΌβββββββββββΌβββββββββββΌβββββββββββΌββββββββββββββββ
β β β β
βββββββββΌβββββ ββββΌβββββ ββββΌββββββ ββββΌβββββββ
βElasticsearchβ βQdrant β β Gmail β β Gemini β
β :9200 β β :6333 β β IMAP β β AI β
ββββββββββββββ βββββββββ ββββββββββ βββββββββββ
π For detailed architecture, see ARCHITECTURE.md
- Node.js 18+ (Download)
- Docker & Docker Compose (Install)
- Gmail account with App Password
- Gemini API key (Get Free Key)
git clone https://github.com/chiragSahani/ai-based-inbox-onebox.git
cd reachinbox-oneboxdocker-compose up -d
# Verify services are running
curl http://localhost:9200/_cluster/health
curl http://localhost:6333/healthzcd server
npm installCreate server/.env file:
# Server Configuration
PORT=5000
NODE_ENV=development
CLIENT_URL=http://localhost:3000
# Feature Flags
ENABLE_ELASTICSEARCH=true
ENABLE_VECTOR_DB=true
ENABLE_AI_LABELING=true
ENABLE_WEBHOOKS=true
ENABLE_REALTIME=false
# IMAP Account 1 (Required)
IMAP_USER_1=your-email@gmail.com
IMAP_PASSWORD_1=your-16-char-app-password
IMAP_HOST_1=imap.gmail.com
IMAP_PORT_1=993
# IMAP Account 2 (Optional)
IMAP_USER_2=second-email@gmail.com
IMAP_PASSWORD_2=your-16-char-app-password
IMAP_HOST_2=imap.gmail.com
IMAP_PORT_2=993
# Elasticsearch
ELASTICSEARCH_URL=http://localhost:9200
# Qdrant Vector Database
QDRANT_URL=http://localhost:6333
# Google Gemini AI
GEMINI_API_KEY=your-gemini-api-key-here
# Webhooks (Optional)
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
WEBHOOK_SITE_URL=https://webhook.site/your-unique-url
BOOKING_LINK=https://cal.com/your-usernamecd ../client
npm install # or pnpm installCreate client/.env.local file:
NEXT_PUBLIC_API_URL=http://localhost:5000Terminal 1 - Backend Server:
cd server
npm run dev
# Server running at http://localhost:5000Terminal 2 - Frontend Client:
cd client
npm run dev
# Client running at http://localhost:3000π Visit: http://localhost:3000
- β Real emails from your Gmail account synced in real-time
- β AI-categorized emails with color-coded badges (11 categories)
- β Full-text search across subject and body
- β Smart filters by account, folder, and AI category
- β AI-generated reply suggestions using RAG pipeline
- β Account switcher for managing multiple email accounts
- β Beautiful dark theme with purple gradients
- β Responsive layout that works on mobile and desktop
reachinbox-onebox/
βββ client/ # Next.js 15 Frontend
β βββ app/ # App Router (Next.js 15)
β β βββ layout.tsx # Root layout
β β βββ page.tsx # Home page
β β βββ globals.css # Dark theme styles
β βββ components/
β β βββ page.tsx # Main email app
β β βββ header.tsx # Search + notifications
β β βββ sidebar.tsx # Account/category filters
β β βββ email-list.tsx # Email inbox list
β β βββ email-detail.tsx # Email viewer
β β βββ suggested-replies.tsx # AI reply generation
β β βββ ui/ # 56 shadcn/ui components
β βββ hooks/
β β βββ use-email-store.ts # Zustand state management
β βββ lib/
β β βββ api.ts # API client
β β βββ constants.tsx # AI categories config
β βββ package.json
β
βββ server/ # Express 5 Backend
β βββ src/
β β βββ config/
β β β βββ index.ts # Environment config
β β β βββ constants.ts # App constants
β β β βββ ai-prompts.config.ts # Gemini AI prompts
β β β βββ seed-data.ts # Vector DB sample data
β β βββ models/
β β β βββ Email.model.ts # Email entity
β β βββ controllers/
β β β βββ email.controller.ts # Email CRUD
β β β βββ account.controller.ts# Account management
β β β βββ health.controller.ts # Health checks
β β β βββ notification.controller.ts # Notifications
β β βββ services/
β β β βββ elasticsearch.service.ts # Search engine
β β β βββ imap.service.ts # Email sync
β β β βββ ai.service.ts # Gemini AI
β β β βββ vector.service.ts # RAG pipeline
β β β βββ webhook.service.ts # Notifications
β β β βββ email-processor.service.ts # Orchestrator
β β βββ middlewares/
β β β βββ security.middleware.ts # Helmet, CORS
β β β βββ ratelimit.middleware.ts # 5 rate limiters
β β β βββ error.middleware.ts # Global error handler
β β β βββ logger.middleware.ts # Morgan + Pino
β β βββ validators/
β β β βββ email.validator.ts # Joi validation
β β βββ api/
β β β βββ email.routes.ts # Email endpoints
β β β βββ account.routes.ts # Account endpoints
β β β βββ health.routes.ts # Health endpoints
β β β βββ notification.routes.ts # Notification endpoints
β β βββ index.ts # Server entry point
β βββ package.json
β
βββ docker-compose.yml # Elasticsearch + Qdrant
βββ .gitignore # Git ignore (.env, node_modules)
βββ README.md # This file
βββ ARCHITECTURE.md # Detailed architecture
| Feature | Implementation | Status |
|---|---|---|
| Security Headers | Helmet.js (CSP, XSS, HSTS, X-Frame-Options) | β |
| CORS | Origin whitelist with credentials support | β |
| Rate Limiting | 5 endpoint-specific limiters | β |
| Input Validation | Joi schema validation | β |
| Request Sanitization | Trim inputs, size limits (10MB) | β |
| Error Handling | Global handler with stack traces (dev only) | β |
| API Key Auth | Production API key authentication | β |
| Load Balancer | Trust proxy for X-Forwarded-* headers | β |
| Endpoint | Window | Max Requests |
|---|---|---|
| General API | 15 min | 100 |
| Search | 5 min | 50 |
| AI Operations | 1 hour | 50 |
| Authentication | 15 min | 5 |
| Account Creation | 1 hour | 10 |
GET /api/emailsGet all emails with pagination.
Query Parameters:
page(number) - Page number (default: 1)pageSize(number) - Items per page (default: 20, max: 500)
Response:
{
"success": true,
"data": {
"emails": [...],
"pagination": {
"total": 150,
"page": 1,
"pageSize": 20,
"totalPages": 8
}
}
}GET /api/emails/searchSearch and filter emails.
Query Parameters:
q(string) - Search query (searches subject + body)account(string) - Filter by account IDfolder(string) - Filter by folder namecategory(string) - Filter by AI categorypage(number) - Page numberpageSize(number) - Items per page
Example:
curl "http://localhost:5000/api/emails/search?q=meeting&category=Interested&page=1"GET /api/emails/:idGet email by ID.
Response:
{
"success": true,
"data": {
"id": "1234567890",
"from": "john@example.com",
"subject": "Project Update",
"body": "Email content...",
"aiCategory": "Important",
"date": "2024-01-15T10:30:00Z"
}
}POST /api/emails/:id/suggest-replyGenerate AI-powered reply suggestion using RAG.
Request Body:
{
"includeContext": true
}Response:
{
"success": true,
"data": {
"reply": "Thank you for your email...",
"context": [...]
}
}GET /api/accountsList all configured IMAP accounts.
GET /api/health # Basic health check
GET /api/health/detailed # All services status + metrics
GET /api/health/ready # Kubernetes readiness probe
GET /api/health/live # Kubernetes liveness probe
GET /api/health/metrics # Application metricsGET /api/notifications # Get all notifications
GET /api/notifications/unread # Get unread notifications
PUT /api/notifications/:id/read # Mark as read
DELETE /api/notifications # Clear allThe system automatically categorizes emails into 11 intelligent categories:
| Category | Description | Icon |
|---|---|---|
| Interested | Positive responses, asking questions | π― |
| Meeting Booked | Confirmed meetings with date/time | π |
| Not Interested | Clear rejections, "No thank you" | β |
| Follow Up | Requires response, checking in | π§ |
| Job Opportunity | Recruitment, career opportunities | πΌ |
| Newsletter | Marketing, promotional content | π° |
| Spam | Unsolicited, suspicious emails | π« |
| Out of Office | Automated absence replies | ποΈ |
| Important | Urgent, time-sensitive emails | |
| Informational | FYI, no action needed | βΉοΈ |
| Uncategorized | Fallback category | π |
- Dark Theme - Professional purple gradient theme (
oklchcolor space) - Search Bar - Real-time full-text search
- Sidebar Filters - Account switcher + AI category filters
- Email List - Avatar initials, unread badges, star functionality
- Email Detail View - HTML email rendering with reply composer
- AI Reply Generator - RAG-based suggestions with copy-to-clipboard
- Notification Center - Real-time notifications with badge count
- Responsive Layout - Mobile-first design with breakpoints
- Loading States - Skeleton loaders and spinners
- Error Handling - Toast notifications for errors
# Basic health check
curl http://localhost:5000/api/health
# Detailed health with all services
curl http://localhost:5000/api/health/detailed
# Kubernetes readiness probe
curl http://localhost:5000/api/health/ready
# Application metrics
curl http://localhost:5000/api/health/metrics{
"success": true,
"timestamp": "2024-01-15T10:30:00Z",
"uptime": 3600,
"environment": "production",
"services": {
"elasticsearch": {
"status": "healthy",
"clusterStatus": "green"
},
"qdrant": {
"status": "unknown",
"message": "Health check not implemented"
},
"imap": {
"status": "running",
"message": "IMAP services are active"
}
},
"system": {
"platform": "linux",
"nodeVersion": "v18.17.0",
"memory": {
"total": 16384,
"free": 8192,
"used": 8192,
"percentage": 50
},
"cpu": {
"cores": 8,
"model": "Intel Core i7"
}
}
}Request Logging:
- HTTP requests logged with Morgan (dev/production formats)
- Unique request ID tracking (
X-Request-ID) - Performance monitoring (slow request detection >1s)
Application Logging:
- Structured JSON logs with Pino
- Log levels: error, warn, info, debug
- Automatic error serialization
Problem: IMAP connection failed
Solutions:
- Use Gmail App Password, not your regular password
- Enable IMAP in Gmail Settings β Forwarding and POP/IMAP
- Enable 2-Step Verification to generate App Passwords
- Check firewall allows port 993 (IMAP SSL)
# Test IMAP connection
openssl s_client -connect imap.gmail.com:993 -crlfProblem: Elasticsearch or Qdrant not accessible
Solutions:
# Check container status
docker ps
# View logs
docker logs reachinbox-onebox-elasticsearch-1
docker logs reachinbox-onebox-qdrant-1
# Restart services
docker-compose restart
# Rebuild containers
docker-compose down -v
docker-compose up -d --buildProblem: EADDRINUSE: address already in use
Solutions:
Windows:
netstat -ano | findstr :5000
taskkill /PID <PID> /FLinux/Mac:
lsof -ti:5000 | xargs kill -9Or change port in server/.env:
PORT=5001Problem: 429 Too Many Requests from Gemini API
Solutions:
- Default: 15 calls/minute (configurable)
- Increase delay in
server/.env:
GEMINI_CALLS_PER_MINUTE=10- Upgrade to Gemini Pro API for higher limits
# Server
cd server
npm run build
npm start
# Client
cd client
npm run build
npm startNODE_ENV=production
PORT=5000
CLIENT_URL=https://your-domain.com
API_KEY=your-secure-api-key-here
# Enable security features
ENABLE_API_KEY_AUTH=true- Set
NODE_ENV=production - Configure
API_KEYfor authentication - Enable HTTPS (Let's Encrypt or certificate)
- Set up reverse proxy (Nginx/Apache)
- Configure CORS with production origins
- Enable Elasticsearch authentication
- Set up monitoring (Prometheus + Grafana)
- Configure centralized logging (ELK stack)
- Set appropriate rate limits
- Configure health check endpoints
- Set up automatic backups
- Configure secrets management (HashiCorp Vault)
# Build images
docker build -t reachinbox-server:latest ./server
docker build -t reachinbox-client:latest ./client
# Run with docker-compose
docker-compose -f docker-compose.prod.yml up -d| Technology | Version | Purpose |
|---|---|---|
| Next.js | 15.2.4 | React framework with App Router |
| React | 19 | UI library with latest features |
| TypeScript | 5 | Type safety |
| shadcn/ui | Latest | 56 pre-built components |
| Zustand | Latest | Lightweight state management (< 1KB) |
| Tailwind CSS | 4.1.9 | Utility-first styling |
| Lucide React | 0.454.0 | Icon library (1000+ icons) |
| Zod | 3.25.76 | Schema validation |
| React Hook Form | 7.60.0 | Form management |
| Technology | Version | Purpose |
|---|---|---|
| Node.js | 18+ | JavaScript runtime |
| Express | 5.1.0 | Web framework |
| TypeScript | 5.9.3 | Type safety |
| Joi | 18.0.1 | Input validation |
| Helmet | 8.1.0 | Security headers |
| Pino | 10.1.0 | Fast JSON logging |
| Morgan | 1.10.1 | HTTP request logging |
| node-imap | 0.9.6 | IMAP email sync |
| Elasticsearch | 7.17.1 | Full-text search |
| Qdrant | Latest | Vector database |
| Google Gemini | 0.24.1 | AI categorization & replies |
- Docker - Containerization
- Docker Compose - Multi-container orchestration
- Elasticsearch - Document store (9200)
- Qdrant - Vector store (6333)
- Real-Time Email Sync - IMAP IDLE for β₯2 accounts
- Fetch Last 30 Days - Fetches last 100 emails on startup
- AI Categorization - 11 categories using Gemini AI
- Full-Text Search - Elasticsearch with subject + body
- Filtering - Multi-dimensional (account, folder, category)
- RAG-Based Replies - Qdrant vector search + Gemini
- Webhook Integration - Idempotent Slack notifications
- Dark UI - Professional Next.js interface
- MVC Architecture - Clean separation of concerns
- Security - Helmet, CORS, rate limiting, validation
- Error Handling - Global handler with custom errors
- Monitoring - 5 health check endpoints
- Logging - Morgan + Pino structured logs
- Feature Flags - Toggle services via ENV
- Graceful Shutdown - Clean resource cleanup
- Load Balancer Support - Trust proxy configuration
- Type Safety - Full TypeScript coverage
- Modern UI - Next.js 15 + 56 shadcn/ui components
npm run dev # Development with ts-node-dev
npm run build # Compile TypeScript to dist/
npm start # Run compiled JavaScript
npm run lint # Run ESLint
npm test # Run tests (if implemented)npm run dev # Next.js development server
npm run build # Production build
npm start # Start production server
npm run lint # Run Next.js linter-
Enable 2-Step Verification:
- Go to Google Account Security
- Enable "2-Step Verification"
-
Generate App Password:
- Visit App Passwords
- Select "Mail" and "Other (Custom name)"
- Copy the 16-character password
- Use this in
IMAP_PASSWORD_1(no spaces)
-
Enable IMAP:
- Go to Gmail β Settings β Forwarding and POP/IMAP
- Enable IMAP access
- Visit Google AI Studio
- Click "Create API Key"
- Copy the key
- Add to
server/.env:
GEMINI_API_KEY=AIzaSy...- Create Slack app at api.slack.com/apps
- Enable "Incoming Webhooks"
- Create new webhook for your channel
- Copy webhook URL
- Add to
server/.env:
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...- README.md - This file (overview & quick start)
- ARCHITECTURE.md - Detailed architecture guide
- server/README.md - Backend API documentation
ISC
- UI design inspired by ReachInbox
- Built with β€οΈ using modern technologies
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
For issues and questions:
- π Report Bug
- π‘ Request Feature
β Star this repo if you find it helpful!
Built for the ReachInbox Assignment | GitHub