An open API service indexing awesome lists of open source software.

https://github.com/sethdavis512/rapidalle

React Router 7 + BetterAuth + Trigger.dev + Prisma - AI-powered image generation with DALL-E 3
https://github.com/sethdavis512/rapidalle

ai-image-generation authentication better-auth dalle3 dark-mode fullstack openai postgresql prisma react react-router react-router-7 ssr tailwindcss trigger-dev typescript

Last synced: 3 months ago
JSON representation

React Router 7 + BetterAuth + Trigger.dev + Prisma - AI-powered image generation with DALL-E 3

Awesome Lists containing this project

README

          

# RapiDallβ€’E

A modern, full-stack AI-powered image generation platform built with React Router 7, BetterAuth, Trigger.dev, and Prisma.

## ✨ Features

- 🎨 **AI Typography & Art Generation** - Create stunning typography designs and artistic compositions with OpenAI's DALL-E 3
- πŸ” **Complete Authentication** - Secure user accounts with BetterAuth
- ⚑ **Real-time Updates** - Live task monitoring with Trigger.dev
- πŸ’³ **Credit System** - User-based credit management for generation limits
- πŸŒ™ **Dark Mode** - Comprehensive light/dark theme support
- πŸ“± **Responsive Design** - Beautiful UI that works on all devices
- πŸš€ **Server-Side Rendering** - Fast, SEO-friendly React Router 7
- πŸ—ƒοΈ **Type-Safe Database** - Prisma ORM with PostgreSQLA modern, full-stack AI-powered image generation platform built with React Router 7, BetterAuth, Trigger.dev, and Prisma.

## ✨ Features

- 🎨 **AI Image Generation** - Create stunning images with OpenAI's DALL-E 3
- πŸ” **Complete Authentication** - Secure user accounts with BetterAuth
- ⚑ **Real-time Updates** - Live task monitoring with Trigger.dev
- πŸ’³ **Credit System** - User-based credit management for generation limits
- πŸŒ™ **Dark Mode** - Comprehensive light/dark theme support
- πŸ“± **Responsive Design** - Beautiful UI that works on all devices
- πŸš€ **Server-Side Rendering** - Fast, SEO-friendly React Router 7
- �️ **Type-Safe Database** - Prisma ORM with PostgreSQL

## πŸ› οΈ Tech Stack

### Frontend

- **React Router 7** - Modern SSR framework with file-based routing
- **React 19** - Latest React with concurrent features
- **TypeScript** - Type-safe development
- **TailwindCSS v4** - Utility-first styling with automatic dark mode
- **Lucide React** - Beautiful, customizable icons

### Backend

- **Prisma** - Type-safe database ORM
- **PostgreSQL** - Robust relational database
- **BetterAuth** - Modern authentication with Prisma adapter
- **Trigger.dev v3** - Background task processing and monitoring

### AI & APIs

- **OpenAI DALL-E 3** - State-of-the-art typography and art generation
- **OpenAI GPT-4o** - Enhanced prompt processing and artistic captions

## πŸš€ Getting Started

### Prerequisites

- Node.js 18+
- PostgreSQL database
- OpenAI API key
- Trigger.dev account

### Installation

1. **Clone the repository**

```bash
git clone https://github.com/sethdavis512/tws-trigger-dev.git
cd tws-trigger-dev
```

2. **Install dependencies**

```bash
npm install
```

3. **Set up environment variables**

```bash
cp .env.example .env
```

Fill in your environment variables:

```env
DATABASE_URL="postgresql://user:password@localhost:5432/rapidalle"
OPENAI_API_KEY="your_openai_api_key"
TRIGGER_SECRET_KEY="your_trigger_secret_key"
```

4. **Set up the database**

```bash
npx prisma migrate dev
npx prisma generate
```

### Development

Start the development servers:

```bash
# Terminal 1: React Router dev server
npm run dev

# Terminal 2: Trigger.dev dev server
npm run trigger:dev
```

Your application will be available at `http://localhost:5173`.

## πŸ“ Project Structure

```text
β”œβ”€β”€ app/
β”‚ β”œβ”€β”€ lib/ # Auth configuration and utilities
β”‚ β”œβ”€β”€ models/ # Database operations (Prisma)
β”‚ β”œβ”€β”€ routes/ # Pages and API endpoints
β”‚ β”‚ β”œβ”€β”€ authenticated.tsx # Protected route layout
β”‚ β”‚ β”œβ”€β”€ api/ # API routes
β”‚ β”‚ └── ...
β”‚ β”œβ”€β”€ components/ # Reusable UI components
β”‚ └── ...
β”œβ”€β”€ trigger/
β”‚ └── generateContent.ts # Background image generation task
β”œβ”€β”€ prisma/
β”‚ β”œβ”€β”€ schema.prisma # Database schema
β”‚ └── migrations/ # Database migrations
└── ...
```

## πŸ” Authentication

The app uses **BetterAuth** with email/password authentication:

- **Session-based auth** with 7-day expiry
- **Prisma adapter** for database integration
- **Layout-based protection** for authenticated routes
- **Custom user fields** including credit system

### Key Auth Files

- `app/lib/auth.server.ts` - BetterAuth server configuration
- `app/lib/auth.client.ts` - Client-side auth setup
- `app/lib/session.server.ts` - Auth helper functions
- `app/routes/authenticated.tsx` - Protected route wrapper

## 🎨 Image Generation Workflow

1. **User creates prompt** in the responsive prompt card interface
2. **Credit validation** ensures user has sufficient credits
3. **Background task** triggered via Trigger.dev for async processing
4. **Real-time updates** show generation progress to user
5. **Image persistence** saves results to database with metadata
6. **Gallery display** shows generated images in responsive grid

### Key Generation Files

- `trigger/generateContent.ts` - Main generation task
- `app/routes/api/dalle.ts` - Generation API endpoint
- `app/components/PromptCard.tsx` - Generation interface
- `app/routes/library.tsx` - Image gallery

## πŸ—„οΈ Database Schema

### Core Models

- **User** - Authentication and credits management
- **Prompt** - Reusable generation prompts
- **Image** - Generated images with metadata
- **Auth Tables** - Account, Session, Verification for BetterAuth

### Key Features

- **Cascading deletes** for data integrity
- **Credit system** with atomic operations
- **Relationship mapping** between users, prompts, and images

## πŸš€ Deployment

### Environment Setup

Ensure these environment variables are set:

```env
DATABASE_URL=your_production_postgres_url
OPENAI_API_KEY=your_openai_key
TRIGGER_SECRET_KEY=your_trigger_key
```

### Build for Production

```bash
npm run build
npm run start
```

### Docker Deployment

```bash
docker build -t rapidalle .
docker run -p 3000:3000 rapidalle
```

Compatible with: AWS ECS, Google Cloud Run, Azure Container Apps, Railway, Fly.io

## πŸ§ͺ Development Commands

```bash
npm run dev # Start React Router dev server
npm run trigger:dev # Start Trigger.dev dev server
npm run build # Build for production
npm run typecheck # TypeScript validation
npx prisma studio # Visual database browser
npx prisma migrate dev # Apply database migrations
```

## 🎯 Key Features Deep Dive

### Credit System

- Users start with 10 free credits
- Each image generation costs 1 credit
- Atomic credit deduction prevents race conditions
- Extensible for future payment integration

### Real-time Monitoring

- Live task status updates via Trigger.dev hooks
- Progress indicators during generation
- Error handling and retry logic
- No polling - efficient WebSocket connections

### Dark Mode

- System preference detection
- Comprehensive component coverage
- Smooth transitions and proper contrast ratios
- TailwindCSS media strategy implementation

## 🀝 Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## πŸ“„ License

This project is licensed under the MIT License.

## πŸ™ Acknowledgments

- [React Router](https://reactrouter.com/) - Modern React framework
- [BetterAuth](https://better-auth.com/) - Simple, powerful authentication
- [Trigger.dev](https://trigger.dev/) - Background job processing
- [Prisma](https://prisma.io/) - Next-generation ORM
- [OpenAI](https://openai.com/) - AI-powered image generation

---

Built with ❀️ using React Router 7, BetterAuth, Trigger.dev, and Prisma.