AFFiNE

AFFiNE is a modern, self-hosted knowledge base and productivity platform that combines note-taking, document collaboration, and database-style organization in a single workspace. Designed as an open-source alternative to tools like Notion, it offers a flexible and powerful environment for managing personal or team knowledge. This stack includes: AFFiNE server for the main workspace and web interface Automated migration service to prepare and update the database PostgreSQL with vector extension for structured data and advanced indexing Redis for caching and background task processing Persistent storage for uploads and configuration data Perfect for individuals, teams, and developers who want a privacy-focused, all-in-one workspace for notes, wikis, and project organization with full control over their data.

yaml

docker-compose.yml

services:
  affine:
    image: ghcr.io/toeverything/affine:${AFFINE_REVISION:-stable}
    container_name: affine_server
    ports:
      - ${PORT:-3010}:3010
    depends_on:
      redis:
        condition: service_healthy
      postgres:
        condition: service_healthy
      affine_migration:
        condition: service_completed_successfully
    volumes:
      - ${UPLOAD_LOCATION}:/root/.affine/storage
      - ${CONFIG_LOCATION}:/root/.affine/config
    environment:
      - REDIS_SERVER_HOST=redis
      - DATABASE_URL=postgresql://${DB_USERNAME}:${DB_PASSWORD}@postgres:5432/${DB_DATABASE:-affine}
      - AFFINE_INDEXER_ENABLED=false
    restart: unless-stopped
  affine_migration:
    image: ghcr.io/toeverything/affine:${AFFINE_REVISION:-stable}
    container_name: affine_migration_job
    volumes:
      - ${UPLOAD_LOCATION}:/root/.affine/storage
      - ${CONFIG_LOCATION}:/root/.affine/config
    command:
      - sh
      - "-c"
      - node ./scripts/self-host-predeploy.js
    environment:
      - REDIS_SERVER_HOST=redis
      - DATABASE_URL=postgresql://${DB_USERNAME}:${DB_PASSWORD}@postgres:5432/${DB_DATABASE:-affine}
      - AFFINE_INDEXER_ENABLED=false
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
  redis:
    image: redis
    container_name: affine_redis
    healthcheck:
      test:
        - CMD
        - redis-cli
        - "--raw"
        - incr
        - ping
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped
  postgres:
    image: pgvector/pgvector:pg16
    container_name: affine_postgres
    volumes:
      - ${DB_DATA_LOCATION}:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: ${DB_DATABASE:-affine}
      POSTGRES_INITDB_ARGS: "--data-checksums"
      POSTGRES_HOST_AUTH_METHOD: trust
    healthcheck:
      test:
        - CMD
        - pg_isready
        - "-U"
        - ${DB_USERNAME}
        - "-d"
        - ${DB_DATABASE:-affine}
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped

.ENV

.env example

# select a revision to deploy, available values: stable, beta, canary
AFFINE_REVISION=stable

# set the port for the server container it will expose the server on
PORT=3010

# set the host for the server for outgoing links
# AFFINE_SERVER_HTTPS=true
# AFFINE_SERVER_HOST=affine.yourdomain.com
# or 
# AFFINE_SERVER_EXTERNAL_URL=https://affine.yourdomain.com

# position of the database data to persist
DB_DATA_LOCATION=~/.affine/self-host/postgres/pgdata
# position of the upload data(images, files, etc.) to persist
UPLOAD_LOCATION=~/.affine/self-host/storage
# position of the configuration files to persist
CONFIG_LOCATION=~/.affine/self-host/config

# database credentials
DB_USERNAME=affine
DB_PASSWORD=
DB_DATABASE=affine

deployment

Quick Start

  1. Create a working directory named after the service.
  2. Copy the compose file and generated `.env` into that directory.
  3. Review the variables and replace placeholders with real values.
  4. Run `docker compose up -d`.
mkdir affine-redis-postgres
cd affine-redis-postgres
# create docker-compose.yml
# create .env
docker compose up -d