# Remix + Prisma + PostgreSQL

> Full-stack Remix application with Prisma ORM and PostgreSQL database.

- Category: Full Web Stacks
- Difficulty: intermediate
- Components: remix, postgresql, redis, nginx
- Tags: remix, prisma, postgresql, typescript, react
- Source: https://docker.recipes/full-stacks/remix-prisma-stack

## Overview

Remix is a full-stack web framework that focuses on web standards and modern UX, built by the creators of React Router. It emphasizes server-side rendering, progressive enhancement, and efficient data loading through its nested routing system and built-in data fetching capabilities. Unlike traditional React frameworks, Remix leverages the web platform's native capabilities for forms, caching, and navigation while providing excellent developer experience with TypeScript support and file-based routing.

This stack combines Remix's full-stack capabilities with Prisma's type-safe database toolkit and PostgreSQL's robust relational database features. Prisma generates TypeScript types from your database schema, providing end-to-end type safety from database queries to your Remix loaders and actions. Redis handles session storage and caching to improve performance, while PostgreSQL stores your application data with ACID compliance and advanced querying capabilities. NGINX serves as a reverse proxy, handling SSL termination and static file serving in production.

This combination is ideal for developers building data-intensive web applications who value type safety, performance, and maintainability. Startups and medium-sized companies will appreciate the rapid development cycle enabled by Prisma's schema-first approach and Remix's convention-over-configuration philosophy. The stack excels for applications requiring complex data relationships, user authentication, and real-time features while maintaining excellent SEO and user experience through server-side rendering.

## Features

- Server-side rendering with Remix's nested routing and progressive enhancement
- Type-safe database operations with Prisma's auto-generated TypeScript client
- Redis-based session management with automatic expiration and distributed storage
- PostgreSQL's JSONB support for flexible schema alongside relational data
- Prisma's database migrations with automatic schema synchronization
- NGINX reverse proxy with HTTP/2 support and static asset optimization
- Remix's built-in error boundaries and catch boundaries for robust error handling
- PostgreSQL's full-text search capabilities integrated with Prisma queries

## Use cases

- E-commerce platforms with complex product catalogs and user management
- Content management systems requiring SEO optimization and fast page loads
- SaaS applications with multi-tenant data isolation and real-time features
- Educational platforms with user progress tracking and content delivery
- Dashboard applications with data visualization and user authentication
- Blog platforms with commenting systems and content management
- Booking systems with availability tracking and payment processing

## Prerequisites

- Docker Engine 20.10+ and Docker Compose V2
- Node.js 18+ knowledge for Remix development and Prisma CLI usage
- Minimum 2GB RAM (1GB for PostgreSQL, 512MB for Redis, 512MB for applications)
- Basic understanding of SQL and database schema design
- Ports 80, 443, 3000, 5432, and 6379 available on host system
- Familiarity with TypeScript and React for Remix development

## docker-compose.yml

```yaml
services:
  remix:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "3000:3000"
    environment:
      DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
      REDIS_URL: redis://redis:6379
      SESSION_SECRET: ${SESSION_SECRET}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
    networks:
      - remix-net
    restart: unless-stopped

  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - remix-net
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    volumes:
      - redis_data:/data
    networks:
      - remix-net
    restart: unless-stopped

  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./certs:/etc/nginx/certs:ro
    depends_on:
      - remix
    networks:
      - remix-net
    restart: unless-stopped

volumes:
  postgres_data:
  redis_data:

networks:
  remix-net:
    driver: bridge
```

## .env

```bash
# PostgreSQL
POSTGRES_USER=remix
POSTGRES_PASSWORD=secure_postgres_password
POSTGRES_DB=remix

# Remix
SESSION_SECRET=secure_session_secret_at_least_32_chars
NODE_ENV=production
```

## Usage notes

- Create Remix app: npx create-remix
- Remix app at http://localhost:3000
- Run migrations: npx prisma migrate deploy
- Configure nginx.conf for production

## Troubleshooting

- Prisma Client not found: Run 'npx prisma generate' to regenerate the client after schema changes
- Database connection refused: Ensure PostgreSQL is healthy with 'docker-compose ps' and check DATABASE_URL format
- Redis connection timeout: Verify Redis container is running and REDIS_URL matches service name 'redis:6379'
- Remix build failures: Clear node_modules and run 'npm install' then 'npm run build' to resolve dependency conflicts
- NGINX 502 Bad Gateway: Check that Remix service is running on port 3000 and nginx.conf upstream configuration is correct
- Prisma migration failures: Reset database with 'npx prisma migrate reset' and reapply migrations in development

