Production-grade Gmail automation and inbox intelligence platform
MailSift connects to Gmail via OAuth 2.0, lets users define pattern-driven tags, watches inbox events in near real time, processes matched messages with background workers, and serves analytics in a React dashboard.
- Demo
- Highlights
- Quick Start
- Architecture
- Repository Layout
- Tech Stack
- Environment Variables
- Docker Deployment
- API Surface
- Observability
- Testing and Code Quality
- CI/CD
- Production Checklist
- Security
- Troubleshooting
- Roadmap
- Google OAuth 2.0 authentication with session-based login flow
- Gmail watch lifecycle APIs: start, status, stop
- Redis + worker queues for asynchronous mail processing
- Tag pages and custom pattern matching pipeline
- Processed-mail stats and recent activity feed endpoints
- MongoDB persistence for users, tags, pages, and processed email data
- Prometheus metrics endpoint with request-latency histogram
- Containerized full stack with backend, frontend, Redis, Prometheus, ngrok
- Node.js 22+
- npm 10+
- Docker Desktop
- MongoDB instance
- Redis instance
- Google Cloud project with Gmail API and Pub/Sub
cd Backend
npm install
cd ../frontend
npm install- Create
Backend/.env(see full template in Environment Variables) - Create
frontend/.envwith:
VITE_BACKEND_URL=http://localhost:3000cd Backend
npm run startcd frontend
npm run dev- Frontend:
http://localhost:5173 - Backend:
http://localhost:3000
flowchart LR
U[User Browser\nReact Frontend :5173] --> B[Express Backend :3000/:4000]
B --> S[Session Store\nRedis]
B --> M[(MongoDB)]
B --> G[Gmail API / OAuth / PubSub]
G --> W[Webhook Endpoint\n/webhook/gmail-webhook]
W --> Q[Worker Pipelines\nBullMQ + Background Workers]
Q --> M
B --> P[Prometheus Metrics\n/monitor/metrics]
MailSift/
Backend/ Node.js + Express API, routes, workers, validations
frontend/ React + Vite dashboard
docker-compose.yml Local/prod-like multi-service orchestration
.github/workflows/ CI/CD pipeline definitions
routes/: API route handlersworkers/: asynchronous background workersqueues/: queue definitions and orchestrationwebhooks/handlers/: Gmail webhook handlingmetrics/: Prometheus instrumentationvalidations/: request validation schemas
| Layer | Technologies |
|---|---|
| Backend | Node.js 22, Express 4 |
| Frontend | React 19, Vite 7, Tailwind CSS 4 |
| Data | MongoDB |
| Cache/Queues | Redis, BullMQ |
| Auth | Google OAuth 2.0 |
| Observability | Prometheus, prom-client |
| Security Middleware | Helmet, xss-clean, express-mongo-sanitize |
| Delivery | Docker, Docker Compose, GitHub Actions, GHCR |
Create Backend/.env:
# Runtime
NODE_ENV=development
PORT=3000
FRONTEND_URL=http://localhost:5173
# Security / sessions
SESSION_SECRET=replace-with-long-random-secret
ENCRYPTED_KEY=replace-with-32-char-min-secret
# Data stores
MONGODB_URL=mongodb://127.0.0.1:27017/mailquell
REDIS_URL=redis://127.0.0.1:6379
# Google OAuth / Gmail
GMAIL_CLIENT_ID=your-client-id
GMAIL_CLIENT_SECRET=your-client-secret
GMAIL_REDIRECT_URI=http://localhost:3000/users/auth/google/callback
GMAIL_PROJECT_ID=your-gcp-project-id
GMAIL_AUTH_URI=https://accounts.google.com/o/oauth2/auth
GMAIL_TOKEN_URI=https://oauth2.googleapis.com/token
GMAIL_AUTH_PROVIDER_X509_CERT_URL=https://www.googleapis.com/oauth2/v1/certs
TOPIC_NAME=your-pubsub-topic-name
# Optional ngrok
NGROK_AUTH_TOKEN=your-ngrok-token
NGROK_DOMAIN=your-ngrok-domainCreate frontend/.env:
VITE_BACKEND_URL=http://localhost:3000From repo root:
docker compose up -d --build| Service | Port | Purpose |
|---|---|---|
| mailquell-backend | 3000 | API, auth, workers |
| mailquell-frontend | 5173 | UI app |
| mailquell-redis | 6379 | Session + queue broker |
| prom-server | 9090 | Metrics scraping |
| mailquell-ngrok | 4040 | Public tunnel (optional) |
Stop stack:
docker compose down --remove-orphansBase URL: http://localhost:3000
| Method | Route | Description |
|---|---|---|
| GET | /users/auth | Initiate Google OAuth |
| GET | /users/auth/google/callback | OAuth callback and frontend redirect |
| Method | Route | Description |
|---|---|---|
| POST | /watch-gmail | Start Gmail watch |
| POST | /stop-watch | Stop Gmail watch |
| GET | /status | Fetch watch status |
| POST | /auto-login | Auto login from session/cookies |
| POST | /log-out | Logout and destroy session |
| Method | Route | Description |
|---|---|---|
| GET | /processed/processed-mail-stats | Stats by createdBy |
| GET | /processed/mail-activity | Activity timeline |
| Method | Route | Description |
|---|---|---|
| GET | /api/tag-inputs | List tag inputs |
| POST | /api/create-tag-inputs | Create tag input |
| DELETE | /api/remove-tag-inputs/:id | Remove tag input |
| DELETE | /api/clearall-tag-inputs/:id | Clear tag input set |
| GET | /api/tag-pages | List tag pages |
| POST | /api/create-tag-page | Create tag page |
| PATCH | /api/update-tag-page/:id | Update tag page |
| DELETE | /api/remove-tag-page/:id | Delete tag page |
| Method | Route | Description |
|---|---|---|
| GET | /details/profile | Fetch profile data |
| GET | /terms.html | Terms endpoint |
| GET | /privacy.html | Privacy endpoint |
| POST | /webhook/gmail-webhook | Gmail push webhook |
- Metrics endpoint:
GET /monitor/metrics - Request latency histogram:
http_request_duration_ms - Default process/runtime metrics collected by prom-client
- Prometheus scrape config stored in
Backend/prometheus-config.yml
cd Backend
npm run lint
npm run testcd frontend
npm run lint
npm run buildWorkflow file: .github/workflows/main.yml
Pipeline stages:
- Backend CI (install, lint, tests with Mongo + Redis)
- Frontend CI (install, lint, build)
- Security scan (Trivy + SARIF upload)
- Docker image build and push to GHCR
- Deploy simulation using Docker Compose
- Use managed MongoDB and Redis with backups/replication
- Rotate OAuth, session, and encryption secrets periodically
- Enforce HTTPS and secure cookies in production
- Restrict CORS origins to trusted frontend domains
- Add reverse proxy or load balancer
- Configure centralized logs and alerting
- Track SLOs for latency, errors, queue lag, webhook health
- Add indexes for hot query paths (for example, createdBy, processAt)
- Tune worker concurrency and autoscaling behavior
- Never commit environment secrets
- Keep SESSION_SECRET long, random, and environment-specific
- Minimize OAuth scopes where possible
- Validate/sanitize all request input consistently
- Review session and token persistence behavior before launch
- Ensure GMAIL_REDIRECT_URI matches Google Console exactly.
- Verify frontend/backend origin settings and credentials mode.
- In production, ensure HTTPS for secure cookies.
- Validate REDIS_URL and network reachability.
- Validate MONGODB_URL and DB availability.
- Validate frontend VITE_BACKEND_URL and backend exposed port.
- Add OpenAPI/Swagger API docs
- Increase frontend/worker test coverage with coverage gates
- Add dedicated health and readiness endpoints
- Add rate limiting for auth and webhook endpoints
- Add feature flags and strict config validation
