# Remix + PostgreSQL

> Full-stack React framework with PostgreSQL and Prisma ORM.

- Category: Full Web Stacks
- Difficulty: intermediate
- Components: remix, postgres
- Tags: remix, react, postgres, prisma
- Source: https://docker.recipes/full-stacks/remix-postgres

## Overview

Remix is a full-stack React framework that emphasizes web standards, server-side rendering, and progressive enhancement. Built by the creators of React Router, Remix takes a unique approach by leveraging the platform's native capabilities like HTTP caching, forms, and URLs, while providing modern developer experience through nested routing, error boundaries, and automatic data loading. Unlike traditional SPAs, Remix renders pages on the server by default and progressively enhances with JavaScript, resulting in faster initial page loads and better SEO.

This stack combines Remix's server-first architecture with PostgreSQL's robust relational database capabilities and Prisma ORM for type-safe database operations. The integration creates a powerful full-stack solution where Remix's loader and action functions handle server-side data fetching and mutations, while PostgreSQL provides ACID-compliant data storage with advanced querying capabilities. Prisma acts as the bridge, generating type-safe client code from your database schema and handling migrations.

This combination is ideal for developers building data-intensive web applications who want React's component model with server-side rendering benefits. E-commerce platforms, content management systems, and SaaS applications particularly benefit from Remix's form handling and PostgreSQL's transaction support. The stack appeals to teams transitioning from traditional server-rendered applications to modern React while maintaining performance and accessibility standards.

## Features

- Server-side rendering with progressive enhancement for optimal Core Web Vitals
- Nested routing with parallel data loading and error boundaries
- Built-in form handling using web standards without client-side JavaScript
- Type-safe database operations through Prisma's generated client
- PostgreSQL's JSONB support for flexible schema evolution alongside relational data
- Automatic code splitting and prefetching based on route hierarchy
- Advanced PostgreSQL features like full-text search and window functions
- Hot module replacement for both client and server code during development

## Use cases

- E-commerce platforms requiring complex product catalogs and transaction integrity
- Content management systems with hierarchical page structures and SEO requirements
- SaaS applications needing server-side authentication and data validation
- Multi-tenant applications leveraging PostgreSQL's row-level security
- Real-time dashboards combining PostgreSQL analytics with Remix's streaming responses
- Progressive web apps that work without JavaScript but enhance with it
- Team collaboration tools requiring complex relational data modeling

## Prerequisites

- Docker and Docker Compose installed on your system
- Node.js 18+ knowledge for Remix development and build processes
- Basic understanding of React components and modern JavaScript
- SQL fundamentals for PostgreSQL schema design and querying
- Minimum 1GB RAM available for PostgreSQL container operations
- Port 3000 available for the Remix development server

## docker-compose.yml

```yaml
services:
  remix:
    build: .
    container_name: remix
    environment:
      DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
    ports:
      - "3000:3000"
    depends_on:
      - postgres
    networks:
      - remix-network

  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: ${DB_NAME}
      POSTGRES_USER: ${DB_USER}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - remix-network

volumes:
  postgres_data:

networks:
  remix-network:
    driver: bridge
```

## .env

```bash
DB_NAME=remix
DB_USER=remix
DB_PASSWORD=changeme
```

## Usage notes

- Docs: https://remix.run/docs
- Access at http://localhost:3000
- Server-side rendering by default, progressive enhancement
- Nested routes with layouts and error boundaries
- Use Prisma or Drizzle for database access
- Built-in form handling without client-side JavaScript

## Troubleshooting

- Database connection refused: Ensure PostgreSQL container is fully started before Remix attempts connection, add healthcheck or wait script
- Prisma generate fails: Run 'npx prisma generate' after schema changes and rebuild the Docker image to include generated client
- Hot reload not working: Bind mount your source code directory to the container for development mode file watching
- PostgreSQL data lost on restart: Verify the postgres_data volume is properly mounted and not being removed between container restarts
- Environment variables not loading: Ensure .env file is in the correct directory and variables match the docker-compose.yml references
- Build fails with Prisma errors: Include Prisma generate step in your Dockerfile after copying package.json and schema.prisma files

