Railway

Deploy AFFiNE | Open Source Notion, Miro Alternative on Railway

Self Host AFFiNE. Docs, whiteboards, databases, auto migrations & more

Deploy AFFiNE | Open Source Notion, Miro Alternative on Railway

DBs

Just deployed

/data

Just deployed

/var/lib/postgresql

Just deployed

/root/.affine

AFFiNE logo

Deploy and Host AFFiNE on Railway

Deploy on Railway

AFFiNE is an open-source, privacy-first all-in-one workspace that combines docs, whiteboards, and databases into a single canvas — a self-hostable alternative to Notion + Miro. Self-host AFFiNE on Railway and keep every page, edge, and knowledge base on infrastructure you control, with pgvector-backed Postgres, Redis caching, and an HTTPS-terminated public domain configured out of the box.

This Railway template pre-configures three services for a production-ready AFFiNE deployment: the AFFiNE server (ghcr.io/toeverything/affine:stable), a Postgres 16 instance with pgvector for AI and embeddings (pgvector/pgvector:pg16), and Railway's managed Redis cache with AUTH enabled. Database migrations run automatically via Railway's pre-deploy command, and the public URL is wired through AFFINE_SERVER_EXTERNAL_URL so internal links resolve to your Railway domain.

AFFiNE Railway architecture

Getting Started with AFFiNE on Railway

After the Railway template finishes deploying, open the public URL of the AFFiNE service — the first request redirects to /admin/setup for the initial admin account bootstrap. Use the AFFINE_ADMIN_EMAIL and AFFINE_ADMIN_PASSWORD values from the template's environment variables to complete setup. Once inside, create a workspace, invite teammates by email, and start building docs or whiteboards. Install the AFFiNE desktop or mobile app and point it at your Railway URL to sync across devices.

AFFiNE dashboard screenshot

About Hosting AFFiNE

AFFiNE ships a single real-time collaborative canvas where Markdown docs, Kanban boards, data tables, and infinite whiteboards live side-by-side. Every block is bi-directional, so a database row can also be a page, and a whiteboard element can also be a document.

Key features:

  • Block-based editor with Markdown, slash commands, and rich embeds
  • Infinite whiteboards with shapes, connectors, handwriting, and mind maps
  • Databases with Kanban, grid, list, and calendar views
  • Real-time multi-player collaboration with CRDT-backed sync
  • Local-first architecture — data syncs to your own server, not a SaaS
  • AI copilot hooks (optional, requires pgvector and external LLM keys)

Architecture is a NestJS backend (affine) fronted by HTTP, a Postgres database with the pgvector extension for embeddings, and a Redis cache for sessions and job coordination.

Why Deploy AFFiNE on Railway

Railway gives self-hosted AFFiNE the plumbing it needs without YAML wrestling:

  • Automatic HTTPS on a *.up.railway.app domain or your own custom domain
  • Managed Postgres + Redis wired via ${{Postgres.*}} / ${{Redis.*}} references
  • Persistent volumes for AFFiNE uploads and Postgres data
  • Pre-deploy command runs migrations before the app starts
  • One-click redeploys when the AFFiNE upstream image updates

Common Use Cases

  • Internal company wiki and knowledge base with whiteboard-driven RFCs
  • Product design hub combining docs, diagrams, and feature databases in one view
  • Student or research notes with linked references and visual study maps
  • Async planning workspace for distributed teams — docs, boards, and Kanban in one URL

Dependencies for AFFiNE

  • AFFiNE serverghcr.io/toeverything/affine:stable (NestJS monolith, port 3010)
  • Postgres with pgvectorpgvector/pgvector:pg16 (data + embeddings)
  • Redis — Railway managed Redis (AUTH enabled, REDIS_URL auto-wired)

Environment Variables Reference

VariablePurpose
AFFINE_SERVER_EXTERNAL_URLPublic URL used for share links and OAuth callbacks
AFFINE_ADMIN_EMAIL / AFFINE_ADMIN_PASSWORDBootstrap admin credentials on first boot
DATABASE_URLPostgres connection string (with pgvector)
REDIS_SERVER_HOST / REDIS_SERVER_PORTRedis cache coordinates
AFFINE_INDEXER_ENABLEDToggle search indexer (Manticore/ES) — off by default
MAILER_HOST, MAILER_PORT, MAILER_USER, MAILER_PASSWORD, MAILER_SENDEROptional SMTP for invites and password reset

Deployment Dependencies

Hardware Requirements for Self-Hosting AFFiNE

ResourceMinimumRecommended
CPU1 vCPU2 vCPU
RAM1 GB2 GB
Storage (AFFiNE volume)2 GB10 GB
Storage (Postgres volume)2 GB10 GB
RuntimeNode.js 22 (bundled in image)Node.js 22

A solo workspace with a few thousand blocks fits comfortably in 1 GB RAM. Teams with dozens of concurrent editors should raise the AFFiNE service to 2 GB and Postgres to 1 GB.

Self-Hosting AFFiNE

On Railway, the template handles service creation, volume attachment, and variable wiring. The equivalent docker-compose snippet looks like this:

services:
  affine:
    image: ghcr.io/toeverything/affine:stable
    ports: ["3010:3010"]
    depends_on: [postgres, redis]
    environment:
      AFFINE_SERVER_EXTERNAL_URL: https://affine.example.com
      DATABASE_URL: postgresql://affine:pw@postgres:5432/affine
      REDIS_SERVER_HOST: redis
      AFFINE_INDEXER_ENABLED: "false"
    volumes:
      - affine_data:/root/.affine

Run the one-off migration before the main process starts:

docker run --rm --env-file .env \
  ghcr.io/toeverything/affine:stable \
  node ./scripts/self-host-predeploy.js

How Much Does AFFiNE Cost to Self-Host?

AFFiNE core is open-source (MIT) and free to run on any infrastructure, including Railway. There is a hosted AFFiNE Cloud with free and Pro tiers (around $8/user/mo for teams), but nothing in the self-hosted image is paywalled — you pay only Railway's standard usage for the AFFiNE, Postgres, and Redis services plus the attached volume storage. A small workspace typically stays under $10/mo on Railway.

FAQ

What is AFFiNE and why self-host it? AFFiNE is an open-source workspace that blends docs, whiteboards, and databases. Self-hosting on Railway keeps notes, workspaces, and attachments on infrastructure you own, rather than a third-party SaaS.

What does this Railway template deploy? Three services — the AFFiNE server (ghcr.io/toeverything/affine:stable), a pgvector-enabled Postgres 16 (pgvector/pgvector:pg16), and a Railway-managed Redis cache. Volumes are attached for AFFiNE uploads and Postgres data.

Why does AFFiNE need pgvector specifically? AFFiNE uses pgvector for AI-assisted features (semantic search, embeddings). Railway's default Postgres image does not include the extension, so this template ships pgvector/pgvector:pg16 to keep AI paths working out of the box.

How do I enable email invites and password reset in self-hosted AFFiNE on Railway? Set the MAILER_HOST, MAILER_PORT, MAILER_USER, MAILER_PASSWORD, and MAILER_SENDER variables on the AFFiNE service with SMTP credentials (Resend, SendGrid, Mailgun, etc.). Redeploy and the invite/reset flows will send mail.

Can I connect the AFFiNE desktop app to my Railway deployment? Yes. Install AFFiNE Desktop from the official releases, open settings, switch the server to the Railway public URL, and log in with your admin credentials.

How do I back up AFFiNE on Railway? Snapshot the Postgres volume using pg_dump against the DATABASE_PUBLIC_URL, and download the /root/.affine/storage volume contents for uploaded assets. Both volumes are independently snapshottable from the Railway dashboard.

Is AFFiNE production-ready? AFFiNE is pre-1.0 (currently v0.26.x). It is stable for small teams and individuals but expect breaking changes between minor versions — pin the image tag if you need absolute stability.


Template Content

More templates in this category

View Template
Strapi
A popular self-hosted CMS

Milo
7.6K
Deploy
View Template
WordPress with Redis
Deploy WordPress with MariaDB and Redis

Noor Adn
View Template
NEW
Docmost
Self-hosted Notion alternative with real-time collaborative editing.

Tasha