AInstein

Development Setup

Complete guide to the AInstein monorepo structure, development environment, and tooling.

This guide provides a comprehensive overview of the AInstein monorepo architecture, development setup, and the tools we use to build a production-ready SaaS platform.

Project Structure

AInstein uses a monorepo managed by PNPM workspaces and Turborepo for efficient builds and dependency management. This structure promotes code reuse, type safety, and consistent development patterns across all applications.

Applications (apps/)

Our monorepo contains multiple specialized applications, each serving a specific purpose:

Core Applications

  • app (Port 3000): The main multi-tenant SaaS application

    • Dashboard, content editor, settings management
    • Real-time collaboration with Liveblocks
    • Admin and reseller portals
    • Organization-based multi-tenancy
  • web (Port 3001): Marketing website

    • Public-facing landing pages
    • Pricing, features, blog content
    • MDX-powered content management
    • Multi-language support (18+ languages)
  • api (Port 3002): Dedicated API server

    • Webhook endpoints for Stripe, Clerk
    • External API integrations
    • Background job processing
    • Health check endpoints

Supporting Applications

  • email (Port 3003): Email template development

    • React Email templates
    • Transactional email designs
    • Preview and testing environment
  • docs (Port 3004): Developer documentation

    • Built with Fumadocs
    • API reference documentation
    • Component documentation
    • Integration guides
  • studio (Port 3005): Database management

    • Prisma Studio interface
    • Database exploration and editing
    • Development data management
  • storybook (Port 6006): Component library

    • Design system documentation
    • Interactive component playground
    • Visual testing environment

Packages (packages/)

Shared code and utilities are organized into reusable packages:

Core Infrastructure

  • @repo/auth: Clerk authentication wrapper with multi-tenant support
  • @repo/database: Prisma ORM configuration with Neon serverless PostgreSQL
  • @repo/design-system: Shadcn/ui components built on Radix UI primitives

AI & Collaboration

  • @repo/ai: Unified AI service integrations (OpenAI, Google AI)
  • @repo/collaboration: Liveblocks real-time collaboration infrastructure

External Services

  • @repo/payments: Stripe payment processing and subscription management
  • @repo/analytics: PostHog and Vercel Analytics integration
  • @repo/email: Resend email service configuration
  • @repo/storage: Vercel Blob storage for file uploads
  • @repo/cms: BaseHub headless CMS integration

Platform Features

  • @repo/notifications: Knock notification service
  • @repo/webhooks: Svix webhook management
  • @repo/feature-flags: Feature flag system
  • @repo/seo: SEO utilities and metadata generation
  • @repo/services: DataForSEO API integration

Development & Operations

  • @repo/observability: Sentry error tracking and monitoring
  • @repo/security: Arcjet security and rate limiting
  • @repo/rate-limit: API rate limiting utilities
  • @repo/internationalization: i18n with Languine
  • @repo/testing: Testing utilities and configurations

Configuration

  • @repo/next-config: Shared Next.js configurations
  • @repo/typescript-config: TypeScript configurations

Technology Stack

Frontend

  • React 19.1.0: Latest React with concurrent features
  • Next.js 15.3+: App Router with Turbopack support
  • TypeScript 5.8+: Full type safety across the monorepo
  • Tailwind CSS 4.1+: Utility-first CSS framework
  • Motion (Framer Motion): Animation library

Backend & Database

  • PostgreSQL: Primary relational database
  • Prisma 6.4+: Type-safe ORM with migrations
  • Neon: Serverless PostgreSQL hosting
  • Edge Runtime: Vercel Edge deployment support

Real-time Features

  • Liveblocks 3.0: Real-time collaboration infrastructure
  • Novel Editor: TipTap-based rich text editor with AI
  • WebRTC: Real-time cursors and presence

Development Tools

  • Turborepo: High-performance build system
  • PNPM: Fast, disk space efficient package manager
  • Biome: Code formatting and linting (extends Ultracite)
  • Vitest: Modern testing framework
  • T3 Env: Type-safe environment variables with Zod

Getting Started

Prerequisites

  • Node.js 20+
  • PNPM 8+
  • PostgreSQL (or Neon account)
  • Required API keys (see Environment Setup)

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/ainstein.git
cd ainstein
  1. Install dependencies:
pnpm install
  1. Set up environment variables:
cp .env.example .env.local
  1. Run database migrations:
pnpm db:push

Running the Development Environment

Start all applications in development mode:

pnpm dev

Or run specific applications:

pnpm dev --filter=app     # Main application
pnpm dev --filter=web     # Marketing website
pnpm dev --filter=api     # API server
pnpm dev --filter=docs    # Documentation

Available Ports

  • 3000: Main SaaS application
  • 3001: Marketing website
  • 3002: API server
  • 3003: Email templates
  • 3004: Documentation
  • 3005: Prisma Studio
  • 6006: Storybook

Build & Deployment

Building for Production

Build all applications:

pnpm build

Build specific applications:

pnpm build --filter=app

Type Checking

Run TypeScript type checking:

pnpm typecheck

Linting & Formatting

Format code with Biome:

pnpm format

Check code quality:

pnpm lint

Database Management

Migrations

Generate Prisma client:

pnpm db:generate

Push schema changes:

pnpm db:push

Create a migration:

pnpm db:migrate

Database GUI

Open Prisma Studio:

pnpm studio

Testing

Run all tests:

pnpm test

Run tests in watch mode:

pnpm test:watch

Deployment

The application is optimized for deployment on Vercel:

  • Production: Merges to main trigger automatic production deployments
  • Preview: Pull requests generate preview deployments with unique URLs
  • Edge Runtime: Optimized for edge deployment where applicable

Environment Variables

Required environment variables for production:

  • Database: DATABASE_URL, DIRECT_URL
  • Authentication: CLERK_* variables
  • Payments: STRIPE_* variables
  • AI Services: OPENAI_API_KEY, GOOGLE_AI_API_KEY
  • Collaboration: LIVEBLOCKS_* variables
  • Email: RESEND_API_KEY
  • Analytics: POSTHOG_* variables
  • Monitoring: SENTRY_* variables

See .env.example for a complete list of required variables.

Architecture Patterns

Multi-Tenant Architecture

  • Organization-based data isolation
  • Role-based access control (Super Admin, Reseller, Member)
  • Clerk-powered authentication with custom roles

Server Components & Actions

  • Next.js App Router with React Server Components
  • Server Actions for mutations
  • Optimistic updates with useTransition

Type Safety

  • End-to-end type safety with TypeScript
  • Zod schema validation
  • Type-safe environment variables

Real-time Collaboration

  • Liveblocks for presence and collaboration
  • Conflict-free replicated data types (CRDTs)
  • Real-time cursors and selections

Additional Resources

On this page