Skip to content

AI-Powered Email Automation Platform — Real-time IMAP Sync, RAG-Based Replies, Smart Categorization, Fuzzy Search & Slack Alerts

Notifications You must be signed in to change notification settings

002sathwik/MailStream-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Assignment - Associate Backend Engineer

🚀 Project Overview – Unified Box (by Outbox Labs)

Unified Box is a full-stack intelligent email management platform that integrates multiple email accounts into one interface, powered by AI summarization, semantic search, and memory recall (Mira).

It enables users to connect Gmail/Outlook accounts, view emails, send replies, and leverage AI to summarize and understand email conversations — all from a single dashboard.


System Architecture Diagram

alt text

System Architecture Docs

🔗 Architecture Documentation

Core Features

1. Multi-Account Email Sync (IMAP Integration)

  • Connect multiple accounts (Gmail / Outlook) securely
  • OAuth login --> and that user can add multiple Accounts
  • Fetch and store emails automatically using IMAP and background sync jobs
  • Parse and index emails for fast retrieval and search in Elasticsearch

2. AI-Powered Email Summarization (Gemini API)

  • Automatically generates short summaries for every new incoming email
  • Categorizes emails into the following labels:
    • Interested
    • Meeting Booked
    • Not Interested
    • Spam
    • Out of Office
  • Uses Google Gemini model for concise, context-aware summaries

3. Mira — Contact Memory System [New Feature]

  • Maintains a memory of all email interactions grouped by contact
  • Each contact stores summarized email history and replies for quick recall
  • Acts like a "personal assistant" that remembers all your email conversations for all emails

4. Semantic Search (Elasticsearch Integration)

  • Full-text + semantic search across email subject, body, sender, and receiver fields
  • Supports fuzzy matching and relevance ranking using multi_match query
  • Fetches context-highlighted search results (like Gmail search)

5. Smart Reply & AI Suggestions

  • Suggests reply drafts using contextual AI generation
  • Allows users to choose tone (friendly, formal, etc.) and edit before sending
  • Integrates with nodemailer for sending replies directly

6. Dashboard (Frontend UI)

  • Sleek, responsive email dashboard built with Next.js + Tailwind CSS
  • Sidebar for accounts, categories, and "Mira memory" section
  • Interactive EmailList and EmailDetail components with live search, filter, and AI features

🏗️ Technical Architecture

Frontend (Client)

Technology Purpose
Next.js 14 Frontend framework for UI and SSR
TypeScript Strict type safety
Tailwind CSS Modern responsive design
Lucide React Icons - Elegant iconography
Axios API communication
Next-Auth Authentication layer
Deployed on Vercel [all free-tiers so it may be slow]

Backend (Server)

Technology Purpose
Node.js + Express.js REST API server
TypeScript Strong typing and modular services
Prisma ORM + PostgreSQL (Neon DB | local docker) Primary data persistence
@elastic/elasticsearch Search and semantic indexing
pinecone vector database for storing Rag Content
Google Gemini API AI summarization and smart reply generation
IMAP + Nodemailer Email retrieval and sending
JWT Authentication Secure user access and token validation
Docker + Docker Compose Containerized backend stack
Deployed on Render [all free-tiers so it may be slow]

Full Setup & Deployment Guide (with Docker Compose in Backend)

An AI-powered email intelligence platform integrating IMAP, Elasticsearch, Gemini AI, and "Mira" — your AI memory.

🧠 1. Clone the Repository

git clone https://github.com/002sathwik/UnifiedBox-outbox-labs-assigment-.git
cd UnifiedBox-outbox-labs-assigment-

Your structure should look like:

UnifiedBox-outbox-labs-assigment-/
 ├── backend/
 │   ├── docker-compose.yml
 │   ├── src/
 │   ├── prisma/
 │   └── package.json
 ├── frontend/
 │   ├── package.json
 │   ├── next.config.js
 │   └── ...
 └── README.md

⚙️ 2. Backend Setup

Step 1️⃣: Go into the backend folder

cd backend

Step 2️⃣: Create .env file inside /backend

Add the following (update your own keys 👇):

# Server
PORT=<port>
NODE_ENV=development

# If using docker, don't use ELASTIC_SEARCH_API_KEY 
ELASTICSEARCH_NODE="https://<elasticsearchnode>:443"
ELASTIC_SEARCH_API_KEY="<elasticsearchapikey>"

JWT_SECRET_KEY=""
FRONTEND_URL=""
GEMINI_API_KEY=""
SLACK_WEBHOOK_URL=""
EXTERNAL_WEBHOOK_URL=""
PINECONE_API_KEY=
PINECONE_ENVIRONMENT=
PINECONE_INDEX_NAME=


DATABASE_URL=""

Step 3️⃣: Install dependencies

bun install

(You can use npm install or yarn if not using Bun.)

Step 4️⃣: Push Prisma schema to Neon DB

npx prisma db push

(Optional: view tables)

npx prisma studio

Step 5️⃣: Run the backend (for development)

bun dev

Server starts on:

🌍 http://localhost:4000

Step 6️⃣: 🐳 Run Backend via Docker Compose

If you prefer full containerized setup:

1️⃣ Build and start containers:

docker-compose up --build

2️⃣ Run in background (detached):

docker-compose up -d

3️⃣ Stop containers:

docker compose down

👉 This will build your backend container and automatically start services defined in docker-compose.yml

Step 7️⃣: Build for production (manual)

bun run build
bun start

💻 3. Frontend Setup

Step 1️⃣: Go to the frontend directory

cd ../frontend

Step 2️⃣: Create .env.local

# next-auth environment variables
NEXTAUTH_URL=<usernextauthurl>
NEXTAUTH_SECRET=<secretvalue>

# OAuth Credentials for Google
GOOGLE_CLIENT_ID=<googleclientid>
GOOGLE_CLIENT_SECRET=<usergoogleclientsecret>

# Backend URL
NEXT_PUBLIC_BACKEND_URL=<userbackendurl>

Step 3️⃣: Install dependencies

bun install

Step 4️⃣: Run frontend

bun run dev

Frontend runs on:

💻 http://localhost:3000

Step 5️⃣: Build frontend for production

bun run build
bun start

🎯 User Journey

1. Login with Gmail

User logs in using any Gmail account First-time users are redirected to the account connection page

2. Connect Email Account(s)

Add IMAP credentials for your email accounts Background Processing Begins:

Retrieves emails from connected accounts Generates AI summaries using Gemini API Stores emails in PostgreSQL database Indexes emails in Elasticsearch for fast search Creates Mira Memory summaries for each contact

3. Dashboard Access

Redirected to the main dashboard after setup Available Features:

Search: Retrieve all emails using semantic search Filter: Filter emails by account, folder, and AI categories RAG Training: Add custom training data for personalized replies AI Reply Suggestions: Get context-aware reply suggestions using RAG + Gemini API Send Replies: Send emails directly from the dashboard

4. Mira Memory

View all past conversations grouped by contact Access summarized email history for quick context recall Acts as your personal email assistant with complete conversation memory

🚀 Deployment & Infrastructure

Performance Note All free-tier services: application as it handles requests within free-tier constraints.

Acknowledgment This is a proof-of-concept built rapidly to demonstrate core functionality. While it successfully implements all required features,

About

AI-Powered Email Automation Platform — Real-time IMAP Sync, RAG-Based Replies, Smart Categorization, Fuzzy Search & Slack Alerts

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages