Fresh + PostgreSQL
Deno full-stack framework with island architecture.
Overview
Fresh is a modern full-stack web framework for Deno that pioneered the island architecture pattern, where only interactive components are hydrated on the client side while the rest of the page remains static HTML. Built by the Deno team in 2022, Fresh eliminates the traditional build step by serving TypeScript and JSX directly, using Preact for UI components and enabling sub-second page loads through selective hydration. This approach dramatically reduces JavaScript bundle sizes and improves performance compared to traditional single-page applications.
This stack pairs Fresh's edge-first architecture with PostgreSQL's enterprise-grade data management capabilities, creating a powerful combination for building fast, data-driven web applications. Fresh handles the presentation layer with zero-config TypeScript support and file-based routing, while PostgreSQL provides ACID-compliant transactions, advanced JSON querying, and full-text search capabilities. The Deno runtime's built-in PostgreSQL drivers enable type-safe database operations without additional build tools.
Developers building modern web applications, SaaS platforms, or content management systems will find this stack particularly valuable when they need both rapid development cycles and robust data integrity. The combination excels for teams wanting to leverage TypeScript across the entire stack while maintaining the flexibility to scale from simple CRUD applications to complex data-driven platforms with advanced PostgreSQL features like JSON querying and geospatial data processing.
Key Features
- Island architecture with selective hydration reduces JavaScript bundle sizes by 90% compared to traditional SPAs
- Zero-config TypeScript and JSX serving directly from Deno runtime without build steps
- File-based routing system with automatic code splitting and lazy loading
- PostgreSQL JSONB support enables hybrid relational-document data models within Fresh components
- Preact-based islands with automatic client-server state synchronization
- Built-in Deno PostgreSQL drivers with type-safe query builders and prepared statements
- Fresh's edge-ready SSR combined with PostgreSQL's logical replication for global deployments
- Advanced PostgreSQL features like full-text search, window functions, and CTEs accessible through Deno APIs
Common Use Cases
- 1E-commerce platforms requiring fast page loads with complex product catalogs and inventory management
- 2Content management systems leveraging PostgreSQL's full-text search and Fresh's island architecture for editorial interfaces
- 3SaaS dashboards with real-time data visualization using PostgreSQL's JSON aggregation and Fresh's selective hydration
- 4Multi-tenant applications utilizing PostgreSQL's row-level security with Fresh's server-side rendering
- 5Geospatial applications combining PostGIS extensions with Fresh's lightweight client-side mapping components
- 6Developer portfolios and blogs with PostgreSQL-backed content and Fresh's near-instant page transitions
- 7Progressive web applications requiring offline-first capabilities with PostgreSQL's advanced transaction handling
Prerequisites
- Minimum 1GB RAM for PostgreSQL with recommended 2GB+ for production workloads
- Deno runtime knowledge including import maps and permission system concepts
- Basic understanding of Preact/React component patterns and JSX syntax
- PostgreSQL experience with SQL queries, indexing strategies, and connection pooling
- Port 8000 available for Fresh development server and standard PostgreSQL port 5432
- Familiarity with island architecture concepts and server-side rendering principles
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 fresh: 3 image: denoland/deno:latest4 container_name: fresh5 working_dir: /app6 command: run -A main.ts7 environment: 8 DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}9 volumes: 10 - ./:/app11 ports: 12 - "8000:8000"13 depends_on: 14 - postgres15 networks: 16 - fresh-network1718 postgres: 19 image: postgres:16-alpine20 environment: 21 POSTGRES_DB: ${DB_NAME}22 POSTGRES_USER: ${DB_USER}23 POSTGRES_PASSWORD: ${DB_PASSWORD}24 volumes: 25 - postgres_data:/var/lib/postgresql/data26 networks: 27 - fresh-network2829volumes: 30 postgres_data: 3132networks: 33 fresh-network: 34 driver: bridge.env Template
.env
1DB_NAME=fresh2DB_USER=fresh3DB_PASSWORD=changemeUsage Notes
- 1Docs: https://fresh.deno.dev/docs/
- 2Access at http://localhost:8000
- 3No build step: serves TypeScript directly
- 4Island architecture: selective hydration
- 5Preact for UI components
- 6Use deno_postgres or denodb for database access
Individual Services(2 services)
Copy individual services to mix and match with your existing compose files.
fresh
fresh:
image: denoland/deno:latest
container_name: fresh
working_dir: /app
command: run -A main.ts
environment:
DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
volumes:
- ./:/app
ports:
- "8000:8000"
depends_on:
- postgres
networks:
- fresh-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:
- fresh-network
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 fresh:5 image: denoland/deno:latest6 container_name: fresh7 working_dir: /app8 command: run -A main.ts9 environment:10 DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}11 volumes:12 - ./:/app13 ports:14 - "8000:8000"15 depends_on:16 - postgres17 networks:18 - fresh-network1920 postgres:21 image: postgres:16-alpine22 environment:23 POSTGRES_DB: ${DB_NAME}24 POSTGRES_USER: ${DB_USER}25 POSTGRES_PASSWORD: ${DB_PASSWORD}26 volumes:27 - postgres_data:/var/lib/postgresql/data28 networks:29 - fresh-network3031volumes:32 postgres_data:3334networks:35 fresh-network:36 driver: bridge37EOF3839# 2. Create the .env file40cat > .env << 'EOF'41DB_NAME=fresh42DB_USER=fresh43DB_PASSWORD=changeme44EOF4546# 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/fresh-postgres/run | bashTroubleshooting
- TypeError: Cannot resolve module specifier: Ensure Deno import maps are properly configured in deno.json for PostgreSQL client libraries
- Fresh islands not hydrating: Verify island components are exported as default and placed in the islands/ directory with proper naming conventions
- PostgreSQL connection refused: Check that DATABASE_URL environment variable matches the service name 'postgres' not 'localhost' in containerized environment
- Deno permission errors accessing database: Add --allow-net and --allow-env flags to the Deno run command for PostgreSQL connections
- Fresh routes not found: Ensure route files in routes/ directory follow Fresh naming conventions with proper export of handler functions
- PostgreSQL data not persisting: Verify postgres_data volume is properly mounted and PostgreSQL container has write permissions 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