KeystoneJS for E-commerce
Node.js CMS for headless commerce.
Overview
KeystoneJS is a modern, TypeScript-first headless CMS and application framework built on Node.js that provides a GraphQL API and admin interface for content management. Originally developed by Thinkmill, KeystoneJS has evolved into a powerful platform for building complex data-driven applications, offering a code-first approach to schema definition with automatic admin UI generation and type-safe database operations through Prisma ORM.
This stack combines KeystoneJS with PostgreSQL to create a robust foundation for headless e-commerce applications. KeystoneJS handles content management, user authentication, and GraphQL API generation, while PostgreSQL provides ACID-compliant data storage with advanced features like JSON support for flexible product catalogs and full-text search capabilities for product discovery. The integration leverages PostgreSQL's relational strengths for complex e-commerce queries involving orders, inventory, and customer relationships.
This combination is ideal for developers building modern e-commerce platforms who need the flexibility of a headless architecture with the robustness of enterprise-grade data management. E-commerce businesses requiring custom admin interfaces, complex product catalogs, multi-channel content delivery, and sophisticated business logic will benefit from KeystoneJS's extensible hook system and PostgreSQL's advanced querying capabilities.
Key Features
- Auto-generated GraphQL API with built-in playground for testing product queries and mutations
- TypeScript-first schema definition with automatic type generation for e-commerce entities
- Built-in admin interface with customizable forms for managing products, orders, and customers
- Prisma ORM integration providing type-safe database operations and migrations
- Hook system for implementing custom e-commerce logic like inventory updates and order processing
- Session-based authentication with configurable access control for different user roles
- PostgreSQL JSONB support for flexible product attributes and metadata storage
- Full-text search capabilities through PostgreSQL for product catalog searches
Common Use Cases
- 1Headless e-commerce platforms requiring custom frontend applications across web and mobile
- 2Multi-tenant marketplaces with different seller dashboards and product catalogs
- 3B2B commerce platforms with complex pricing rules and customer-specific product visibility
- 4Content-rich e-commerce sites combining product catalogs with editorial content management
- 5Inventory management systems requiring real-time stock tracking and automated reordering
- 6Subscription-based commerce platforms with recurring billing and customer portal functionality
- 7International e-commerce sites requiring multi-currency support and localized product data
Prerequisites
- Docker Engine 20.10+ and Docker Compose V2 for container orchestration
- Minimum 1GB RAM for PostgreSQL optimal performance with e-commerce workloads
- Port 3000 available for KeystoneJS admin interface and GraphQL API access
- Basic understanding of GraphQL queries and mutations for API interaction
- Node.js and TypeScript knowledge for custom schema development and hooks
- Familiarity with Prisma ORM concepts for database schema management
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 keystone: 3 image: keystonejs/keystone:latest4 container_name: keystone5 restart: unless-stopped6 environment: 7 DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}8 SESSION_SECRET: ${SESSION_SECRET}9 ports: 10 - "3000:3000"11 depends_on: 12 - postgres13 networks: 14 - keystone1516 postgres: 17 image: postgres:16-alpine18 container_name: keystone-postgres19 environment: 20 POSTGRES_DB: ${DB_NAME}21 POSTGRES_USER: ${DB_USER}22 POSTGRES_PASSWORD: ${DB_PASSWORD}23 volumes: 24 - postgres_data:/var/lib/postgresql/data25 networks: 26 - keystone2728volumes: 29 postgres_data: 3031networks: 32 keystone: 33 driver: bridge.env Template
.env
1DB_NAME=keystone2DB_USER=keystone3DB_PASSWORD=changeme4SESSION_SECRET=your-session-secretUsage Notes
- 1Docs: https://keystonejs.com/docs
- 2Admin UI at http://localhost:3000 - create admin on first visit
- 3GraphQL API built-in at /api/graphql with Playground
- 4Define schemas in schema.ts: lists for products, orders, users
- 5TypeScript-first with Prisma ORM for database
- 6Hooks and access control for custom business logic
Individual Services(2 services)
Copy individual services to mix and match with your existing compose files.
keystone
keystone:
image: keystonejs/keystone:latest
container_name: keystone
restart: unless-stopped
environment:
DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
SESSION_SECRET: ${SESSION_SECRET}
ports:
- "3000:3000"
depends_on:
- postgres
networks:
- keystone
postgres
postgres:
image: postgres:16-alpine
container_name: keystone-postgres
environment:
POSTGRES_DB: ${DB_NAME}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- keystone
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 keystone:5 image: keystonejs/keystone:latest6 container_name: keystone7 restart: unless-stopped8 environment:9 DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}10 SESSION_SECRET: ${SESSION_SECRET}11 ports:12 - "3000:3000"13 depends_on:14 - postgres15 networks:16 - keystone1718 postgres:19 image: postgres:16-alpine20 container_name: keystone-postgres21 environment:22 POSTGRES_DB: ${DB_NAME}23 POSTGRES_USER: ${DB_USER}24 POSTGRES_PASSWORD: ${DB_PASSWORD}25 volumes:26 - postgres_data:/var/lib/postgresql/data27 networks:28 - keystone2930volumes:31 postgres_data:3233networks:34 keystone:35 driver: bridge36EOF3738# 2. Create the .env file39cat > .env << 'EOF'40DB_NAME=keystone41DB_USER=keystone42DB_PASSWORD=changeme43SESSION_SECRET=your-session-secret44EOF4546# 3. Start the services47docker compose up -d4849# 4. View logs50docker 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/keystone-commerce/run | bashTroubleshooting
- KeystoneJS fails to start with database connection error: Verify DATABASE_URL format and ensure PostgreSQL container is fully initialized before KeystoneJS starts
- Admin interface shows 'Session Secret Required' error: Set a strong SESSION_SECRET environment variable with at least 32 characters
- GraphQL mutations fail with permission errors: Configure access control in your schema.ts lists or create an admin user through the initial setup flow
- PostgreSQL container exits with 'data directory not empty' error: Remove the postgres_data volume or use different volume name to start fresh
- KeystoneJS schema changes not reflected: Restart the KeystoneJS container to trigger Prisma migrations and schema updates
- Memory issues with large product catalogs: Increase PostgreSQL shared_buffers and effective_cache_size through environment variables
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