Mailplain is a modern, AI-powered email client built with Next.js 14, featuring real-time mail processing, third-party integrations (Aurinko, Stripe, OpenAI), and a secure role-based system backed by Clerk. This document serves as comprehensive technical documentation including setup, structure, architecture, APIs, and deployment.
git clone https://github.com/zdemirgithub/mailplain.git
cd mailplain
npm install
cp .env.example .envnpm run devNEXT_PUBLIC_URL=http://localhost:3000
CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
STRIPE_SECRET_KEY=
STRIPE_WEBHOOK_SECRET=
AURINKO_CLIENT_ID=
AURINKO_CLIENT_SECRET=
OPENAI_API_KEY=
DATABASE_URL=mailplain/
├── src/
│ ├── app/ # Next.js App Router pages
│ ├── components/ # UI components
│ ├── lib/ # Business logic (Aurinko, Stripe, OpenAI)
│ ├── hooks/ # Custom React hooks
│ ├── server/ # tRPC routers and DB access
│ ├── styles/ # Global styles
│ ├── trpc/ # tRPC utils (context, router)
│ └── middleware.ts # Clerk route protection middleware
│
├── prisma/ # Prisma schema + migrations
├── public/ # Public static assets
├── .env.example # Environment config
└── README.md
+--------------+ +---------------+
| Frontend | <--> | Next.js App |
| (React/Tail) | | (API + UI) |
+--------------+ +---------------+
| |
v v
Clerk (Auth) tRPC Routers (Server)
| |
v v
Stripe <--> Webhooks <--> Business Logic (lib)
| |
v v
OpenAI Aurinko (Mail API)
| |
v v
Role/Auth Prisma + Neon DB
- Authentication: Clerk (JWT, RBAC)
- Subscriptions: Stripe (Webhook + Limits)
- Mail Integration: Aurinko API
- AI Summaries: OpenAI Completion API
- Email Parsing: Custom logic via
lib/aurinko.ts - Database Management: NeonDB, PostgreSQL, Prisma
- Search Engine: Orama (semantic email search)
Mail Router
listAccounts()→ List all connected email accountssendMail({to, subject, body})→ Send new emailsyncMail()→ Trigger a full sync
Webhooks Router
getWebhooks({ accountId })→ List active webhookscreateWebhook({ accountId, notificationUrl })→ Register new webhookdeleteWebhook({ accountId, webhookId })→ Remove webhook
Search Router
search({ query })→ Semantic full-text search over mail using Pinecone
-
POST /api/stripe/webhook- Stripe payment and subscription webhook handler
-
POST /api/aurinko/webhook- Handles new email events from Aurinko
Unit Tests: src/__tests__/unit
- Isolated logic: middleware, utility functions, auth
Integration Tests: src/__tests__/integration
- API calls, DB queries, multi-module workflows
E2E Tests: __tests__/e2e
- Simulate user login, dashboard navigation, Stripe payment
git init
git remote add origin https://github.com/yourname/mailplain.git
git push -u origin main- Go to vercel.com
- Import project from GitHub
- Set environment variables
- Stripe: Dashboard → Webhooks → Add endpoint
https://yourdomain.com/api/stripe/webhook - Aurinko: Auth during email setup triggers internal
/api/aurinko/webhook
- Prefer tRPC over REST for internal APIs
- Use Clerk's
auth()in server-only environments - Follow consistent error handling using
try/catchandzod - All PRs should include unit or integration tests
MIT
For issues, contact zdemirgithub.