How zengroot147/mail_craft works
1. Overall shape
- MailCraft is a single-page React application with a Supabase-backed backend. The front end is built with React 18 + TypeScript + Vite, styled with Tailwind CSS, and composed largely from shadcn/ui primitives.
- The backend is split between Supabase Auth/Postgres and Supabase Edge Functions for privileged actions like AI drafting and Gmail integration.
2. App entry and routing
- The app bootstraps from src/main.tsx into src/App.tsx.
- Route-level pages are in src/pages/: Index (main product), Auth, Profile, ResetPassword, and NotFound.
- This suggests a clear boundary between public/auth flows and the signed-in workspace.
3. Authentication and user session boundary
- src/contexts/AuthContext.tsx centralizes the authenticated session state.
- Supabase Auth is the primary identity layer, and profile-related data is accessed through hooks such as useProfile.
- Authentication is likely the gate that controls access to email tools, account settings, and connected Gmail features.
4. Client-side data access
- src/integrations/supabase/client.ts is the main browser-side DB/auth client.
- src/integrations/supabase/types.ts indicates generated typed schema access, so the app is strongly typed end-to-end against Supabase data.
- Server state is managed with TanStack React Query per the README, which likely handles profile, drafts, analytics, and connection status.
5. Core product workspace
- The main product surface is an email composition and enhancement workspace centered on components like EmailComposer, AIChatAssistant, RefinementBar, DraftComparison, and DraftStats.
- Around that composer are specialized analysis tools: ToneAnalyzer, GrammarCheck, ComplianceCheck, ReadabilityScore, SensitiveInfoCheck, and LinkDetector.
- This makes the UI architecture modular: one primary compose flow with many specialized “assist” panels.
6. AI generation and writing assistance flow
- AI draft generation is handled through the Supabase Edge Function supabase/functions/draft-email.
- The presence of src/lib/aiHeaders.ts and src/lib/sse.ts suggests the client talks to AI endpoints with authenticated headers and may support streaming responses via SSE.
- README says the AI provider is Google Gemini, so the AI boundary is intentionally pushed off the client and into backend functions.
7. Gmail integration flow
- Gmail connectivity is implemented as a backend workflow with three edge functions:
- gmail-oauth-start
- gmail-oauth-callback
- gmail-send
- src/hooks/useGmailConnection.ts manages the client-side connection state.
- This is a distinct integration boundary: the browser initiates auth, Supabase handles the OAuth callback securely, and send operations happen server-side.
8. Email intelligence and productivity features
- The app includes a wide set of analysis and workflow modules beyond drafting:
- EmailSummarizer, EmailThreadBuilder, EmailToTask, QuickReplySuggestions
- SubjectLineSuggestions, ColdEmailOptimizer, LanguageSelector, ToneSelector, LengthControl
- ScheduleReminder, TextToSpeech, VoiceInput
- These are likely fed from the same underlying draft/content model, making the email text the central domain object.
9. Analytics and dashboard subsystem
- DashboardInsights, EmailAnalytics, WorkspaceStats, ProductivityStreaks, PeakHoursHeatmap, and DraftStats indicate a separate analytics layer.
- useEmailEvents suggests event collection from user actions, which then drives dashboard metrics and streaks.
- This is the main observational loop in the app: user composing activity becomes analytics and recommendations.
10. Persistence and schema
- Supabase migrations in supabase/migrations/ define the database schema over time.
- The presence of add_gmail_connections.sql indicates dedicated storage for connected Gmail accounts, separate from basic auth.
- The overall data model likely includes users/profiles, drafts, email events, templates/snippets, and Gmail connection metadata.
11. Reusable UI system
- src/components/ui/ is a full shadcn/Radix component layer: dialogs, sheets, command palette, tables, tabs, tooltips, etc.
- Higher-level components such as CommandPalette, OnboardingTour, ThemeToggle, and CollapsibleSection build product behavior on top of those primitives.
- This creates a clean separation between design-system primitives and feature components.
12. Platform/tooling and deployment
- The repo uses Vite for the frontend build, Vitest for tests, and ESLint for linting.
- vercel.json indicates the frontend is deployed on Vercel, while Supabase hosts the backend services/functions.
- Public assets like sitemap.xml, robots.txt, and structured data files show the app also has an SEO-aware landing/public-facing surface.
13. How the major flows connect
- A signed-in user opens the React SPA, authenticates through Supabase, and loads profile/connection state.
- They compose or paste email text into the workspace, invoke AI assistance, and receive generated or analyzed content from Supabase Edge Functions.
- If connected, Gmail OAuth enables sending through backend functions rather than directly from the browser.
- User actions are recorded as events and summarized in analytics dashboards and productivity views.
14. Architecture boundary summary
- The key architectural boundary is between the interactive client workspace and the server-side integration layer.
- The client handles composition, UI state, and local interactions; Supabase handles identity, persistence, OAuth, AI proxying, and Gmail send operations.
- That split is what makes the repository diagram-friendly: one central SPA, one typed backend/data layer, and several narrowly scoped edge-function integrations.
Main entry points: EmailComposer.tsx Workspace · client.ts Supabase client · AIChatAssistant.tsx AI assistant · useGmailConnection.ts Gmail hook
Components 26
Client app
React SPA, pages, workspace features, and client-side state.
- Main entry · Bootstraps the SPA and mounts the application root.
src/main.tsx - App shell · Top-level application shell and route wiring.
src/App.tsx - Pages · Public and authenticated route-level screens.
src/pages/Index.tsx - Auth context · Centralizes authenticated session state for the client.
src/contexts/AuthContext.tsx - Profile hook · Loads and exposes profile-related state.
src/hooks/useProfile.ts - Gmail hook · Tracks Gmail connection state in the client.
src/hooks/useGmailConnection.ts - Event hook · Collects email activity events for workspace analytics.
src/hooks/useEmailEvents.ts - Workspace · Primary email drafting and refinement workspace.
src/components/EmailComposer.tsx - AI assistant · Generates and refines email content with AI assistance.
src/components/AIChatAssistant.tsx - Analysis tools · Tone, grammar, compliance, readability, and safety review modules.
src/components/ToneAnalyzer.tsx - Productivity tools · Summaries, replies, tasks, scheduling, voice, and related helpers.
src/components/EmailSummarizer.tsx - Templates · Saved drafts, snippets, templates, and signature assets.
src/components/TemplatesGallery.tsx - Dashboard · Analytics, streaks, heatmaps, and workspace metrics.
src/components/DashboardInsights.tsx - AI headers · Prepares authenticated request headers for AI calls.
src/lib/aiHeaders.ts - SSE stream · Client-side support for streaming AI responses.
src/lib/sse.ts
UI kit
Reusable shadcn/Radix primitives and shared UI helpers.
- UI primitives · Shared shadcn/Radix building blocks used across the app.
src/components/ui/button.tsx
Supabase backend
Auth, database types, migrations, and edge functions.
- Supabase client · Main browser-side Supabase client for auth and data access.
src/integrations/supabase/client.ts - DB types · Generated TypeScript schema types for Supabase data.
src/integrations/supabase/types.ts - Cloud auth · Cloud-auth integration layer used by the client.
src/integrations/cloud-auth/index.ts - Draft function · Server-side AI drafting function backed by Supabase Edge Functions.
supabase/functions/draft-email/index.ts - OAuth start · Starts Gmail OAuth in a server-side flow.
supabase/functions/gmail-oauth-start/index.ts - OAuth callback · Completes Gmail OAuth and persists connection state securely.
supabase/functions/gmail-oauth-callback/index.ts - Gmail send · Server-side email sending through connected Gmail accounts.
supabase/functions/gmail-send/index.ts - Migrations · Database schema evolution and Gmail connection storage.
supabase/migrations/20260407000100_add_gmail_connections.sql
Platform
Build, deployment, and public assets.
- Public assets · Robots, sitemap, web manifest, and structured data.
public/sitemap.xml - Build config · Frontend build, tests, linting, and deployment configuration.
vite.config.ts
Connections 26
- Main entry → App shell: mounts · The Vite entry mounts the application shell.
- App shell → Pages: routes to · The app shell selects route-level pages.
- Pages → Auth context: uses · Pages depend on session state for auth gating.
- Pages → Workspace: opens · Signed-in pages expose the composition workspace.
- Workspace → AI assistant: invokes · The composer is paired with AI drafting and refinement.
- Workspace → Analysis tools: runs · Workspace content is checked by specialized analysis modules.
- Workspace → Productivity tools: feeds · Draft text powers summarization and workflow helpers.
- Workspace → Templates: reuses · Drafting pulls from templates, snippets, and signatures.
- Workspace → Event hook: emits · Composition activity is recorded for analytics.
- Dashboard → Event hook: consumes · Dashboard metrics are derived from user email events.
- Auth context → Supabase client: authenticates · Session state is backed by Supabase auth.
- Profile hook → Supabase client: queries · Profile state is loaded through the Supabase client.
- Profile hook → DB types: types · Profile queries use generated database types.
- Gmail hook → Supabase client: tracks · Gmail connection state comes from backend data.
- AI headers → Supabase client: secures · AI requests are prepared with authenticated client context.
- SSE stream → Draft function: streams · The client receives streamed AI output from the edge function.
- AI assistant → AI headers: uses · AI assistance uses authenticated request headers.
- AI assistant → SSE stream: streams · Assistant UI supports incremental AI responses.
- AI assistant → Draft function: calls · Draft generation is handled by the backend function.
- Gmail hook → OAuth start: starts · The client initiates Gmail authorization.
- OAuth start → OAuth callback: returns · OAuth start flows into the callback handler.
- Gmail hook → Gmail send: sends via · Connected Gmail accounts are used for backend sending.
- OAuth callback → Migrations: persists · Connection metadata is stored in the database schema.
- Cloud auth → Supabase client: bridges · Cloud auth sits beside the main Supabase client integration.
- Build config → Public assets: packages · Build and deployment include public SEO assets.
- Build config → UI primitives: supports · Shared UI primitives are used throughout the build.