AI-Powered Gmail Assistant that controls the UI through natural language.
MailPilot is an AI-powered email assistant built as part of the Processity AI hiring assignment.
Unlike traditional chatbots, MailPilot is designed to control the application UI.
Instead of simply answering:
"Send an email to John"
the assistant should:
- Open the compose window
- Fill the recipient
- Fill the subject
- Fill the body
- Allow the user to review
- Send the email after confirmation
The AI is not just a chatbot.
It is the primary controller of the application.
- Python
- FastAPI
- OpenAI API
- Gmail API
- MongoDB
- WebSockets
- React
- JavaScript
- Vite
React Frontend
Inbox Compose Assistant
│
REST + WebSocket
│
FastAPI Backend
│
┌───────────┼────────────┐
▼ ▼ ▼
OpenAI Gmail API MongoDB
│
Gmail Account
Throughout the project we will follow these rules.
Every module should have one responsibility.
No file should become a "God Object."
Business logic belongs inside services.
Example
Assistant
↓
Tool
↓
Service
↓
Gmail Client
↓
Google API
The Assistant never talks directly to Gmail.
Database access should never be mixed with business logic.
Repositories handle MongoDB.
Services handle application logic.
The AI never performs actions directly.
It calls tools.
Example
User
↓
"Show unread emails"
↓
OpenAI
↓
search_emails()
↓
EmailService
↓
MongoDB
↓
Results
The frontend never parses natural language.
The backend sends structured UI actions.
Example
{
"action": "OPEN_COMPOSE"
}{
"action": "FILTER_EMAILS",
"filters": {
"unread": true
}
}{
"action": "OPEN_EMAIL",
"email_id": "123"
}The frontend simply executes these actions.
backend/
src/
api/
ai/
auth/
gmail/
database/
services/
toolkits/
models/
prompts/
config/
utils/
We will build this project incrementally.
Each phase should leave the application in a working state.
Goal
Create a clean project structure.
Tasks
- Create folder structure
- Configure virtual environment
- Configure requirements
- Configure logging
- Configure environment variables
- Configure FastAPI
- Add health endpoint
Result
GET /health
↓
{
"status":"healthy"
}
Goal
Authenticate users with Gmail.
Tasks
- OAuth
- Login
- Refresh Tokens
- Gmail Connection
Result
User successfully connects Gmail.
Goal
Create a reusable Gmail wrapper.
Modules
gmail/
client.py
reader.py
sender.py
drafts.py
labels.py
threads.py
parser.py
Result
Backend can
- Read emails
- Send emails
- Create drafts
- Archive
- Delete
- Labels
Goal
Persist email data locally.
Collections
users
gmail_accounts
emails
threads
assistant_conversations
Tasks
- MongoDB connection
- Repository pattern
- Email synchronization
Result
Emails are cached locally.
Goal
Create the AI assistant.
Tasks
- OpenAI Client
- Prompt Manager
- Tool Registry
- Tool Executor
Result
Assistant can reason about requests.
Goal
Search emails using MongoDB.
Example
Find emails from Sarah
↓
MongoDB
↓
Results
↓
Assistant
Goal
Assistant updates the frontend.
Example
User
Compose an email to John
↓
Assistant
↓
UI Action
↓
Frontend
↓
Compose window opens
The assistant understands
- Current page
- Selected email
- Current thread
- Previous request
Example
Reply to this.
The assistant knows what "this" means.
Goal
Receive emails without refresh.
Flow
Gmail
↓
Watch API
↓
Backend
↓
MongoDB
↓
Frontend Update
Tasks
- Error Handling
- Logging
- Testing
- Docker
- Environment Validation
- Cleanup
Every phase should have meaningful commits.
Examples
feat: initialize project
feat: configure FastAPI
feat: implement Gmail authentication
feat: create Gmail client
feat: integrate MongoDB
feat: add OpenAI assistant
feat: implement tool calling
feat: synchronize Gmail
feat: add websocket support
After the assignment the architecture should allow adding
- Google Calendar
- Google Drive
- Contacts
- Slack
- Outlook
without major architectural changes.
Every phase must leave the project runnable.
We should never break the application while adding features.
If a phase is complete, the application should start successfully before moving to the next phase.
- Project planning
- Folder structure
- FastAPI foundation
- Gmail Authentication
- Gmail Client
- MongoDB
- OpenAI Integration
- AI Tool Calling
- UI Actions
- React Frontend
- Real-time Synchronization
- Production Ready