Blitz.js + PostgreSQL
Full-stack React framework inspired by Ruby on Rails.
Overview
Blitz.js is a full-stack React framework that emerged in 2020, inspired by Ruby on Rails' philosophy of convention over configuration. Created to eliminate the complexity of modern React development, Blitz.js provides a batteries-included approach with built-in authentication, database integration via Prisma ORM, and a revolutionary 'Zero-API' data layer that allows direct server function calls from client components without traditional REST or GraphQL APIs. The framework emphasizes rapid development through code generation, automatic TypeScript support, and opinionated project structure that reduces decision fatigue.
This stack pairs Blitz.js with PostgreSQL to create a robust full-stack development environment where PostgreSQL's ACID compliance and advanced querying capabilities complement Blitz.js's type-safe database operations through Prisma. PostgreSQL's mature transaction handling ensures data integrity for Blitz.js applications, while its JSON/JSONB support provides flexibility for storing complex application state alongside traditional relational data. The combination leverages PostgreSQL's full-text search capabilities for content-heavy applications and its extensible nature for custom business logic requirements.
This configuration targets developers building modern web applications who want Rails-like productivity with React's ecosystem benefits. Startups requiring rapid MVP development, teams transitioning from monolithic frameworks to modern JavaScript stacks, and developers building customer-facing applications with complex data relationships will find this stack particularly valuable. The combination eliminates the typical complexity of setting up authentication, database migrations, and API layers while maintaining the scalability and performance characteristics needed for production applications.
Key Features
- Zero-API data layer enabling direct server function calls from React components without REST endpoints
- Built-in Prisma ORM integration with PostgreSQL for type-safe database operations and automatic migrations
- Blitz Auth system with session-based authentication, password hashing, and user management out of the box
- Rails-inspired code generators (blitz generate all) for rapid scaffolding of models, queries, and mutations
- PostgreSQL's JSONB support for storing complex application state alongside relational data with full indexing
- Full-text search capabilities using PostgreSQL's built-in search features with ranking and highlighting
- Automatic TypeScript configuration with end-to-end type safety from database to frontend components
- Hot reloading development environment with automatic database schema synchronization
Common Use Cases
- 1SaaS applications requiring user authentication, subscription management, and complex data relationships
- 2E-commerce platforms needing product catalogs, inventory management, and order processing with ACID transactions
- 3Content management systems leveraging PostgreSQL's full-text search for articles, documentation, or blogs
- 4Customer relationship management (CRM) tools with complex queries across related entities like contacts, deals, and activities
- 5Multi-tenant applications using PostgreSQL's row-level security and schema isolation features
- 6Analytics dashboards requiring complex aggregations and window functions across large datasets
- 7Social platforms needing user profiles, relationships, and activity feeds with real-time updates
Prerequisites
- Docker and Docker Compose installed with minimum 2GB RAM available for PostgreSQL operations
- Node.js 16+ knowledge and familiarity with React hooks and component patterns
- Basic understanding of SQL queries and relational database concepts for Prisma schema design
- Environment file (.env) configured with DB_NAME, DB_USER, and DB_PASSWORD variables
- Port 3000 available for Blitz.js development server and port 5432 for PostgreSQL connections
- Dockerfile present in project root for Blitz.js application build process
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 blitz: 3 build: .4 container_name: blitz5 environment: 6 DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}7 ports: 8 - "3000:3000"9 depends_on: 10 - postgres11 networks: 12 - blitz-network1314 postgres: 15 image: postgres:16-alpine16 environment: 17 POSTGRES_DB: ${DB_NAME}18 POSTGRES_USER: ${DB_USER}19 POSTGRES_PASSWORD: ${DB_PASSWORD}20 volumes: 21 - postgres_data:/var/lib/postgresql/data22 networks: 23 - blitz-network2425volumes: 26 postgres_data: 2728networks: 29 blitz-network: 30 driver: bridge.env Template
.env
1DB_NAME=blitz2DB_USER=blitz3DB_PASSWORD=changemeUsage Notes
- 1Docs: https://blitzjs.com/docs
- 2Access at http://localhost:3000
- 3Zero-API: call server functions directly from components
- 4Built-in authentication with blitz auth
- 5Prisma ORM included
- 6Rails-like generators: blitz generate all
Individual Services(2 services)
Copy individual services to mix and match with your existing compose files.
blitz
blitz:
build: .
container_name: blitz
environment:
DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
ports:
- "3000:3000"
depends_on:
- postgres
networks:
- blitz-network
postgres
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:
- blitz-network
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 blitz:5 build: .6 container_name: blitz7 environment:8 DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}9 ports:10 - "3000:3000"11 depends_on:12 - postgres13 networks:14 - blitz-network1516 postgres:17 image: postgres:16-alpine18 environment:19 POSTGRES_DB: ${DB_NAME}20 POSTGRES_USER: ${DB_USER}21 POSTGRES_PASSWORD: ${DB_PASSWORD}22 volumes:23 - postgres_data:/var/lib/postgresql/data24 networks:25 - blitz-network2627volumes:28 postgres_data:2930networks:31 blitz-network:32 driver: bridge33EOF3435# 2. Create the .env file36cat > .env << 'EOF'37DB_NAME=blitz38DB_USER=blitz39DB_PASSWORD=changeme40EOF4142# 3. Start the services43docker compose up -d4445# 4. View logs46docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/blitz-postgres/run | bashTroubleshooting
- Prisma client generation errors: Run 'blitz prisma generate' after schema changes and rebuild the container
- Database connection refused: Ensure postgres service is fully started before blitz container using depends_on healthcheck
- Migration failures on startup: Check DATABASE_URL format and verify PostgreSQL credentials match environment variables
- Blitz auth session issues: Verify SESSION_SECRET_KEY is set in environment and consistent across container restarts
- Port 3000 already in use: Stop existing Node.js processes or change the host port mapping in docker-compose.yml
- PostgreSQL data persistence lost: Ensure postgres_data volume is properly mounted to /var/lib/postgresql/data
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Ad Space
Shortcuts: C CopyF FavoriteD Download