How mendableai/firegeo works
Project type and purpose
• This is a full-stack SaaS starter application built with Next.js 15, TypeScript, Tailwind CSS, and PostgreSQL.
• It provides user authentication (Better Auth), billing (Autumn + Stripe), AI-powered chat, brand monitoring (using Firecrawl and multiple AI providers), email notifications (Resend), and a Postgres database accessed via Drizzle ORM.
File structure
• app/: Next.js 15 “app directory” containing both page components and serverless API routes under app/api.
• app/api/auth, app/api/autumn, app/api/brand-monitor, app/api/chat, app/api/credits, app/api/user – These route.ts files implement RESTful or RPC endpoints.
• app/(auth) and other page folders: client-side pages (login, register, dashboard, brand-monitor UI, chat UI, pricing, etc.).
• components/: React UI components split by feature (autumn, brand-monitor, ui).
• lib/: Shared utilities, API wrappers, database client & schema (lib/db), provider configs, SSE parser, scraping helpers, error types.
• hooks/: React hooks for data fetching and subscriptions (useConversations, useBrandAnalyses, useAutumnCustomer, etc.).
• config/: Static configuration (autumn-products, constants).
• migrations & better-auth_migrations: SQL migration files for Drizzle ORM and Better Auth.
• scripts/: Setup scripts (Autumn billing, Stripe portal).
• middleware.ts, next.config.ts: Next.js configuration.
README for additional insights
• Confirms tech stack: Next.js, React, Tailwind CSS, Drizzle ORM, Better Auth, Autumn, Firecrawl, AI providers, Resend.
• Lists project structure and setup workflow.
a. Main components:
1. Client Browser – React SPA pages served by Next.js
2. Next.js Server (Edge or Node Serverless Lambdas)
• SSR pages
• API routes under app/api/**
3. Authentication Service – Better Auth
4. Billing Service – Autumn (Stripe integration)
5. Database – PostgreSQL (Drizzle ORM)
6. AI Providers – OpenAI, Anthropic, Google Gemini, Perplexity
7. Web-Scraping Service – Firecrawl
8. Email Service – Resend
9. SSE/Event Stream – Server-Sent Events for long-polling in brand-monitor
b. Relationships & data flows:
• Browser ←→ Next.js pages (HTTP/HTTPS).
• Browser → Next.js API (fetch calls from hooks like useMessages, useBrandAnalyses).
• Next.js API ↔ Database (lib/db.ts via Drizzle ORM).
• Next.js API ↔ Better Auth for session, JWT, user management.
• Next.js API ↔ Autumn billing endpoints for subscription, usage tracking.
• Next.js API ↔ Firecrawl & AI providers for brand analysis and chat.
• Next.js API ↔ Resend email service.
• SSE connections from API (app/api/brand-monitor/hooks/use-sse-handler.ts) → Browser for real-time updates.
c. Architectural patterns/design principles:
• Folder-based routing & API routes (Next.js app router).
• Serverless functions for each API route.
• Layered architecture: UI components, data-fetching hooks, API services, business logic in lib/, persistence layer in lib/db.
• Single source of configuration (config/, env-validation).
• Event streaming for long-polling / real-time device updates.
d. Key technologies & libraries:
• Next.js 15 (app router + serverless routes)
• React 19 + TypeScript 5.7
• Tailwind CSS & shadcn/ui
• Drizzle ORM + PostgreSQL
• Better Auth (authentication & migrations)
• Autumn + Stripe (billing)
• Firecrawl (web scraping)
• OpenAI, Anthropic, Google Gemini, Perplexity (AI chat & brand analysis)
• Resend (email)
• SSE parser & utilities for real-time streams