Skip to content

utkarsh125/automail-ai

Repository files navigation

automail.

screely-1740699239185

Technology Stack

This project is built using the T3 Stack, enhanced with additional tools for AI capabilities and payment processing. The tech stack includes:

  • Clerk Authentication: Clerk
  • Next.js Frontend Framework: Next.js (App Router)
  • tRPC Backend Framework: tRPC
  • Prisma Database ORM: Prisma
  • PostgreSQL Database: NeonDB (or locally containerized PostgreSQL)
  • TailwindCSS UI: TailwindCSS + ShadCN
  • Stripe Payments: Stripe (To be integrated)
  • Vercel Hosting: Vercel (potential alternative: self-hosting on EC2 with NGINX as a reverse proxy)
  • AI Capabilities:
    • Gemini API Gemini API for text generation
    • Cohere Cohere for RAG-based chatbot
    • Orama Orama for full-text search

Project's working and why I couldn't deploy it

πŸ“Ί Watch the video: YouTube Link The project uses multiple APIs, here is a list of APIs that are employed in this project

  • Aurinko for mail sync offers 15 day free trial
  • Cohere API used for the RAG Chat generous monthly limit
  • Gemini API use to interact with gemini-2.0-flash which is used for Text Generation generous limit

Challenges that I faced during the creation of this project

  • AURINKO DOES NOT SUPPORT Gmail STRAIGHT OUT OF THE BOX and a lot of configuration were required from Google Cloud Platform
  • Gemini + VertexAI complex setup did not allow me to generate embeddings for Orama
  • HUGGINGFACE had a not-so-generous pricing for their Inference API it stops at the consumption of just $0.10
  • Stripe Integration since it does not work that well in India because of KYC issues, setting it up was difficult even for mock payments

Architectural Flow

Pasted image 20250210233524


Project Structure

.
β”œβ”€β”€ bun.lock
β”œβ”€β”€ components.json
β”œβ”€β”€ next.config.js
β”œβ”€β”€ next-env.d.ts
β”œβ”€β”€ package.json
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ postcss.config.js
β”œβ”€β”€ prettier.config.js
β”œβ”€β”€ prisma
β”‚Β Β  β”œβ”€β”€ migrations/
β”‚Β Β  β”œβ”€β”€ migration_lock.toml
β”‚Β Β  └── schema.prisma
β”œβ”€β”€ public
β”‚Β Β  └── favicon.ico
β”œβ”€β”€ README.md
β”œβ”€β”€ src
β”‚Β Β  β”œβ”€β”€ app
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ api/
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ _components/
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ mail/
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ sign-in/
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ sign-up/
β”‚Β Β  β”‚Β Β  └── layout.tsx
β”‚Β Β  β”œβ”€β”€ components
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ kbar/
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ ui/
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ link-account-button.tsx
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ theme-provider.tsx
β”‚Β Β  β”‚Β Β  └── theme-toggle.tsx
β”‚Β Β  β”œβ”€β”€ hooks/
β”‚Β Β  β”œβ”€β”€ lib/
β”‚Β Β  β”œβ”€β”€ server/
β”‚Β Β  β”œβ”€β”€ styles/
β”‚Β Β  β”œβ”€β”€ trpc/
β”‚Β Β  β”œβ”€β”€ env.js
β”‚Β Β  β”œβ”€β”€ middleware.ts
β”‚Β Β  β”œβ”€β”€ playground.ts
β”‚Β Β  └── page.tsx
β”œβ”€β”€ start-database.sh
β”œβ”€β”€ tailwind.config.ts
└── tsconfig.json

Step Zero: Preliminary Research

Before starting development, the following must be explored:

  • Clerk Authentication (Completed)
  • Aurinko (Completed)
  • Orama Search (Completed)
  • Gemini AI Text Generation (Completed)
  • RAG Chat (Completed)
  • Stripe payment (Pending)

Development Flow

1. Email Client Setup

  • Understand how Aurinko fetches and manages emails.
  • Configure API access for seamless email synchronization.

2. Project Bootstrapping

  • Set up a Next.js project with Clerk authentication.
  • Integrate ShadCN UI components.
  • Initialize Prisma ORM with a PostgreSQL database.

3. API Configuration

  • Set up Aurinko API to receive and sync emails.
  • Implement database schema and webhook management for real-time updates.

4. Search and AI Integration

  • Implement full-text search using Orama.
  • Build UI components to display emails and threads.
  • Implement search UI with dynamic filtering.

5. AI-Driven Features

  • RAG-based chatbot using Cohere.
  • AI-assisted replies and email composition (Copilot-like functionality).

6. Payments and Deployment

  • Integrate Stripe for payment processing.
  • Deploy the application on Vercel or EC2.
  • Create a landing page for the SaaS product.

Project Initialization

This project follows the T3 Stack setup:

bun create t3-app@latest  # or use npm
docker run --name postgres-container -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_DB=postgres -p 5432:5432 -d postgres

Why T3 Stack?

  • TypeScript-first approach for strong typing.
  • tRPC enables a seamless full-stack API experience.
  • Next.js for a robust React framework.
  • Prisma for efficient database handling.
  • TailwindCSS for fast UI development.

Clerk Authentication Setup

Clerk provides a complete authentication suite with:

  • Multi-factor authentication
  • Advanced security & bot detection
  • Social sign-on options
  • Session management

Install Clerk

bun install @clerk/nextjs

Middleware Configuration

Add a middleware.ts file inside src/:

import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server'

const isPublicRoute = createRouteMatcher([
    '/sign-in(.*)', '/sign-up(.*)'
]) 

export default clerkMiddleware(async (auth, request) => {
  if (!isPublicRoute(request)) {
    await auth.protect()
  }
})

export const config = {
  matcher: [
    '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
    '/(api|trpc)(.*)',
  ],
}

Wrapping layout.tsx with <ClerkProvider>

import "~/styles/globals.css";
import { ClerkProvider } from '@clerk/nextjs';
import { TRPCReactProvider } from "~/trpc/react";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <ClerkProvider>
      <html lang="en">
        <body>
          <TRPCReactProvider>{children}</TRPCReactProvider>
        </body>
      </html>
    </ClerkProvider>
  );
}

Remaining Tasks

Critical Integrations:

  • Stripe Stripe (Pending)
  • Rate Limiting (Pending)
  • Database Configuration:
    • Use NeonDB as the primary PostgreSQL instance.
    • Alternative: Self-host PostgreSQL on EC2 with NGINX.

AI Improvements:

  • Improve context handling in responses.
  • Fix missing EmailAddress and Name in replies.

Database Migration

Instead of npx prisma migrate, use:

bun prisma db push  # Pushes schema to DB

Important: Remove the "query" param from db.ts, as it complicates operations. Further research required.


Deployment Strategy

  • Option 1: Deploy to Vercel (simple, managed hosting)
  • Option 2: Host on EC2, using NGINX for reverse proxy

Summary

This document outlines the project setup, authentication flow, database configuration, and AI capabilities. Key tasks include AI fine-tuning, Stripe integration, and final deployment. The project follows a structured approach, leveraging modern frameworks to build a robust SaaS product.

About

A simple email client with AI based text-generation and RAG (Retrieval Augmented Generation) Chat.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages