Docs/For AI Agents/Deployment Patterns

Deployment Patterns

Ready-to-use nexlayer.yaml templates for common application stacks. Copy these patterns and adapt them to the user's specific needs.

How to Use These Patterns

  1. Identify the stack that matches the user's application
  2. Copy the pattern and replace placeholder values (myuser, image tags, app name)
  3. Adjust environment variables based on the user's actual configuration
  4. Add or remove pods as needed for the specific use case

Available Patterns

Static Website

Simple static site or SPA served by nginx

nexlayer.yaml
application:
  name: my-website
  pods:
    - name: web
      image: nginx:1.27
      path: /
      servicePorts: [80]

Next.js

Next.js application (standalone build)

nexlayer.yaml
application:
  name: nextjs-app
  pods:
    - name: nextjs
      image: myuser/nextjs-app:v1.0.0
      path: /
      servicePorts: [3000]

Next.js + PostgreSQL

Full-stack Next.js with PostgreSQL database

nexlayer.yaml
application:
  name: nextjs-fullstack
  pods:
    - name: nextjs
      image: myuser/nextjs-app:v1.0.0
      path: /
      servicePorts: [3000]
      vars:
        DATABASE_URL: postgresql://postgres:${POSTGRES_PASSWORD}@postgres.pod:5432/mydb

    - name: postgres
      image: postgres:16
      servicePorts: [5432]
      vars:
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
        POSTGRES_DB: mydb
      volumes:
        - name: postgres-data
          size: 1Gi
          mountPath: /var/lib/postgresql

PERN Stack

PostgreSQL + Express + React + Node.js

nexlayer.yaml
application:
  name: pern-app
  pods:
    # Database
    - name: postgres
      image: postgres:16
      servicePorts: [5432]
      vars:
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
        POSTGRES_DB: myapp
      volumes:
        - name: pg-data
          size: 2Gi
          mountPath: /var/lib/postgresql

    # API (server-to-server: postgres.pod)
    - name: express
      image: myuser/express-api:v1.0.0
      path: /api
      servicePorts: [3000]
      vars:
        DATABASE_URL: postgresql://postgres:${POSTGRES_PASSWORD}@postgres.pod:5432/myapp
        NODE_ENV: production

    # Frontend (browser calls the public URL, not express.pod)
    - name: react
      image: myuser/react-app:v1.0.0
      path: /
      servicePorts: [80]
      vars:
        REACT_APP_API_URL: <% URL %>/api

MERN Stack

MongoDB + Express + React + Node.js

nexlayer.yaml
application:
  name: mern-app
  pods:
    # Database
    - name: mongo
      image: mongo:7
      servicePorts: [27017]
      vars:
        MONGO_INITDB_ROOT_USERNAME: admin
        MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD}
      volumes:
        - name: mongo-data
          size: 2Gi
          mountPath: /data/db

    # API
    - name: express
      image: myuser/express-api:v1.0.0
      path: /api
      servicePorts: [3000]
      vars:
        MONGODB_URI: mongodb://admin:${MONGO_PASSWORD}@mongo.pod:27017/myapp?authSource=admin
        NODE_ENV: production

    # Frontend
    - name: react
      image: myuser/react-app:v1.0.0
      path: /
      servicePorts: [80]

Python FastAPI

FastAPI with PostgreSQL

nexlayer.yaml
application:
  name: fastapi-app
  pods:
    - name: api
      image: myuser/fastapi-app:v1.0.0
      path: /
      servicePorts: [8000]
      vars:
        DATABASE_URL: postgresql://postgres:${POSTGRES_PASSWORD}@postgres.pod:5432/mydb

    - name: postgres
      image: postgres:16
      servicePorts: [5432]
      vars:
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
        POSTGRES_DB: mydb
      volumes:
        - name: postgres-data
          size: 1Gi
          mountPath: /var/lib/postgresql

Django

Django with PostgreSQL and Redis

nexlayer.yaml
application:
  name: django-app
  pods:
    - name: django
      image: myuser/django-app:v1.0.0
      path: /
      servicePorts: [8000]
      vars:
        DATABASE_URL: postgresql://postgres:${POSTGRES_PASSWORD}@postgres.pod:5432/django
        REDIS_URL: redis://redis.pod:6379
        DJANGO_SETTINGS_MODULE: myapp.settings.production

    - name: postgres
      image: postgres:16
      servicePorts: [5432]
      vars:
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
        POSTGRES_DB: django
      volumes:
        - name: postgres-data
          size: 2Gi
          mountPath: /var/lib/postgresql

    - name: redis
      image: redis:7
      servicePorts: [6379]

Go API

Go API with PostgreSQL

nexlayer.yaml
application:
  name: go-api
  pods:
    - name: api
      image: myuser/go-api:v1.0.0
      path: /
      servicePorts: [8080]
      vars:
        DATABASE_URL: postgresql://postgres:${POSTGRES_PASSWORD}@postgres.pod:5432/mydb
        GIN_MODE: release

    - name: postgres
      image: postgres:16
      servicePorts: [5432]
      vars:
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
        POSTGRES_DB: mydb
      volumes:
        - name: postgres-data
          size: 1Gi
          mountPath: /var/lib/postgresql

App + Redis Cache

Any app with Redis for caching/sessions

nexlayer.yaml
application:
  name: app-with-cache
  pods:
    - name: app
      image: myuser/my-app:v1.0.0
      path: /
      servicePorts: [3000]
      vars:
        REDIS_URL: redis://redis.pod:6379

    - name: redis
      image: redis:7
      servicePorts: [6379]
      volumes:
        - name: redis-data
          size: 500Mi
          mountPath: /data

WordPress

WordPress with MySQL

nexlayer.yaml
application:
  name: wordpress-site
  pods:
    - name: wordpress
      image: wordpress:6
      path: /
      servicePorts: [80]
      vars:
        WORDPRESS_DB_HOST: mysql.pod:3306
        WORDPRESS_DB_USER: wordpress
        WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
        WORDPRESS_DB_NAME: wordpress
      volumes:
        - name: wp-content
          size: 5Gi
          mountPath: /var/www/html/wp-content

    - name: mysql
      image: mysql:8
      servicePorts: [3306]
      vars:
        MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
        MYSQL_DATABASE: wordpress
        MYSQL_USER: wordpress
        MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      volumes:
        - name: mysql-data
          size: 2Gi
          mountPath: /var/lib/mysql

Remember

  • •Replace myuser/ with the actual Docker Hub username or registry path, and keep a pinned tag on every image (Nexlayer runs linux/amd64 images)
  • •Passwords stay out of the file: ${POSTGRES_PASSWORD} is a reference that gets filled at deploy time. See Environment variables & secrets
  • •Check that servicePorts match what the container actually exposes
  • •Adjust volume sizes based on expected data storage needs
  • •To use your own domain, add the url field under application. Without it, the app gets a generated Nexlayer URL