/vagarish

Search engine for Kleros

Primary LanguageTypeScript

Hiatus

This project is not being maintained, and is no longer hosted in the website stated below. Thanks for trying out Vagarish. Feel free to fork this repository or revive the project.

Despite using Typescript and using a decently simple frontend, this backend is unmaintainable in its current state.

  • The whole state was destroyed and rebuilt on every update.
  • It used filesystem and MongoDB in confusing ways
  • Not multichain, nor is it easy to turn it into it
  • PDF parsing stopped working

It was a good concept but it shouldn't be hosted if I don't have time to maintain it.

Vagarish

Vagarish is a search engine for Kleros. For the frontend, go to vagarish-web.

Try it out at vagarish.forer.es

Info

Vagarish is a node.js backend server. It periodically checks for changes in Kleros and will use those changes to keep an internal database up to date. It also provides GraphQL queries to expose the data. They can be fetched from the frontend, vagarish-web, or any other app by using the API.

API

  • For text, just query /api/search?substring=thing and you'll get a JSON with the search results. Sadly, it's case sensitive and it will look for the substring itself.
  • /api/search?id=1000 to fetch a dispute with all its evidence
  • /api/search?courtId=23 to fetch evidence from a court
  • /api/search?by=0x001FE2CdBEeB0743679E958C0861Dd8788B28b19 to fetch all evidence by an address
  • [This hasn't been tested] You can combine queries with &: /api/search?courtId=23&substring=address, this will fetch all evidence containing address in court 23.

Complex queries may break because the search logic really is spaghetti code. Add an issue if you notice something odd.

Alternatively, you can use GraphQL by connecting to /graphql. Check the source code for the required fields.

How to deploy your own Vagarish

Vagarish serves the vagarish-web frontend by default. Just focus on setting a single page, and the app will take care of serving the frontend and doing server work.

Initial setup

Get an Ubuntu server. Can be cheap. Even 1GB servers can keep up.

apt install npm

git clone https://github.com/greenlucid/vagarish

git clone https://github.com/greenlucid/vagarish-web

cd vagarish-web

npm i

cd ../vagarish

cp .env.template .env

Fill your env variables.

npm i

npm run build:full

This last one can take like 20 minutes if it's a small server. It could even crash due to insufficient memory. If you got 1GB RAM or less, follow this guide to add swap to the server. 1GB should be enough. Put a swappiness of 10, and you'll find it somehow faster than before.

MongoDB

Full guide

Get key wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -

Add mongogb apt server echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

Reload apt sudo apt-get update

Install sudo apt-get install -y mongodb-org

Start it sudo systemctl start mongod

Set it to start on reboot: sudo systemctl enable mongod

Server stuff

  • Get nginx, set it up. Point your domain to the DNS. This is a good guide, and you can follow it for the other steps. This is a guide that incorporates Node servers, you will need it to set up a reverse proxy. It might be possible to set the reverse proxy in sites-available directly.
  • Then test that it actually works, by running it with npm start and checking your domain.
  • Get pm2. Guide
  • Get lets encrypt, set it up. Guide. If node + let's encrypt gives you problems, you can alternatively create a dumb html website, certify it, and then get your real page.
  • Put a cron job so that it renews the certificate automatically, or you'll forget:
    • crontab -e, create new line at the end.
    • 0 0 1 */2 * certbot certonly -d vagarish.forer.es --webroot -w /root/vagarish

Init the database

The initial seeding takes way longer than future updates.

cd vagarish

mkdir files/events files/ipfs

echo "[]" > files/events/subcourtIds.json

npm run init

First time can take around, 1 hour or 2. Next times it's around 15 minutes. You will only run npm run init next time. The website is accessible while it's being seeded or updated. If you want your instance to keep up, you should set up automatic updates.

Update the database

Vagarish does not listen to live events, it has to update explictly. To do that, you rerun npm run init. You can use a cron job for this. Because you will be using pm2 to deal with keeping the server alive, you will have to stop pm2, run init, and then restart pm2. There is a bash script that does this for you in update-db.sh. So, just do crontab -e and paste something like this:

0 6 * * * /root/vagarish/update-db.sh

Also do chmod u+x update-db.sh so that cron can execute it.