Docs
Development
Dev Guide

Node Dev Guide

Before you start, the Project Architecture doc should be read to know codebase design and app design.

Prerequisites

  • Docker - to run dependent servers locally, needs to be installed locally.

  • Rust - to implement storage in the server, needs to be installed locally. If you need a rust proxy, try https://rsproxy.cn/.

Dependencies

Run PostgreSQL

docker pull postgres
docker run --rm --name affine-postgres -e POSTGRES_PASSWORD=affine -p 5432:5432 -v ~/Documents/postgres:/var/lib/postgresql/data postgres

If you want to use a dedicated volume.

docker volume create affine-postgres
docker run --rm --name affine-postgres -e POSTGRES_PASSWORD=affine -p 5432:5432 -v affine-postgres:/var/lib/postgresql/data postgres

Run MailHog (Optional)

To debug some features related to sending email, like login.

docker run --rm --name mailhog -p 1025:1025 -p 8025:8025 mailhog/mailhog

After the server is started, you need to config ENABLE_LOCAL_EMAIL="true" in the .env file.

Run Web Server (Optinal)

To debug features from the web client to node server, you should read Web Dev Guide to start web server.

Run Stripe Listener (Optinal)

TODO: document about payment development

Initialization

Prepare DB

Enter DB terminal:

docker exec -it affine-postgres psql -U postgres

In the terminal, following the example to init user & table:

psql (15.3 (Debian 15.3-1.pgdg120+1))
Type "help" for help.
 
postgres=# CREATE USER affine WITH PASSWORD 'affine';
CREATE ROLE
postgres=# ALTER USER affine WITH SUPERUSER;
ALTER ROLE
postgres=# CREATE DATABASE affine;
CREATE DATABASE
postgres=# \du

In the last, you can see:

EYjfWjzyTqaLi2cSQKKUCrmRQWag7hyVqByp9tzhWjQ=

Prepare Prisma

At the beginning or once the DB schema is changed, you need to run it.

yarn workspace @affine/server prisma db push

After that, you can enable Prisma Studio to explore and manipulate your data in all of your Prisma projects.

yarn workspace @affine/server prisma studio

Prepare Env

Copy .env file from .env.example in the server project to config database URL and enable local email by MailHog.

ywhNzhPO2xaAD5681q8xvDU6hM6eE8OqUhP7cPBma9o=

Build Rust Package

The server depends on @affine/storage, which is written by Rust and has super high performance, to implement CRDT and is compatible with yjs.

At the beginning or once the package is changed, you need to run it.

yarn workspace @affine/storage build

Development

Now you should be able to start developing affine in the server package.

yarn workspace @affine/server dev