ipfs-service-provider
Overview
This is a 'boilerplate' repository. It's intended to be forked to start new projects. However, it can also be run as a stand-alone Circuit Relay, for supporting the PSF network.
Boilerplate
This repository has been forked from the koa-api-boilerplate. It has all the same features as that boilerplate:
- Koa framework for REST APIs
- User management
- Access and rate-limit control using JWT tokens.
This boilerplate extends that code to provide the basic features required to be a 'service provider' on the IPFS network. This is a core concept in the web3 Cash Stack. These basic features include:
- ipfs-coord for coordinating service providers and consumers across the IPFS network.
- JSON RPC for creating an API between providers and consumers.
If you are interested in creating your own service provider on the IPFS network, fork this repository and start building.
Branches
This code repository was refactored from CommonJS format to ECMA Script Modules (ESM) format because js-ipfs made the same change, and this repository depends heavily on that one. A CommonJS format version of this code repository is maintained in the cjs branch. This is useful for projects that can not make use of ESM yet, like Electron.js and P2WDB.
Circuit Relay
This 'production' environment for this boilerplate sets up a series of Docker containers, orchestrated with Docker Compose. This boilerplate code can be run without modification, in order to set up a Circuit Relay and support the PSF network. You can get paid a bounty for doing so, in PSF tokens. See the section below on setting up a Production Docker Container.
Features
This project covers basic necessities of most APIs.
- Koa framework for REST APIs
- Authentication (passport & jwt)
- Database (mongoose)
- Testing (mocha)
- Doc generation with apidoc
- Linting using Standard
- Packaged for production environment as a Docker container
- ipfs-coord for coordinating peers over IPFS
- JSON RPC for mirroring the REST API over IPFS
Requirements
- node ^14.18.2
- npm ^8.3.0
- Docker ^20.10.8
- Docker Compose ^1.27.4
Installation
Development Environment
Note: This software now uses an external go-ipfs IPFS node. The instructions below have not been updated to reflect this.
A development environment will allow you modify the code on-the-fly and contribute to the code base of this repository. PM2 is recommended for running this code base as an IPFS Circuit Relay.
git clone https://github.com/Permissionless-Software-Foundation/ipfs-service-provider
cd ipfs-service-provider
./install-mongo-sh
sudo npm install -g node-pre-gyp
npm install
./ipfs-service-provider.sh
Production Environment
The docker directory contains a Dockerfile for building a production deployment.
docker-compose pull
docker-compose up -d
You can bring the containers back up with docker-compose up -d.
Operation Notes
-
There is a memory leak in the version of js-ipfs. The app is currently configured to shut down every 8 hours to flush memory. It relies on a process manager like pm2, Docker, or systemd to restart the app after it shuts down, in order to ensure continuous operation.
-
The PSF network operates as a private network. It does not connect or interact with the wider PSF network, relying instead on gateways to bridge the two networks, when they need to share content. This improves the performance and experience for everyone in the PSF network. To join the network, you'll need to add the swarm.key file to the IPFS data folder.
-
For external installations, the swarm.key file will typically go in
~/.ipfs/swarm.key -
For production Docker containers, the key would go in
ipfs-service-provider/production/data/go-ipfs/data/swarm.key
Structure
The file layout of this repository differs from the koa-api-boilerplate. Instead, it follows the file layout of Clean Architecture.
Usage
npm startStart server on live modenpm run docsGenerate API documentationnpm testRun mocha testsdocker-compose buildBuild a 'production' Docker containerdocker-compose upRun the docker container
Documentation
API documentation is written inline and generated by apidoc.
Visit http://localhost:5000/docs/ to view docs
There is additional developer documentation in the dev-docs directory.
Dependencies
- koa2
- koa-router
- koa-bodyparser
- koa-generic-session
- koa-logger
- MongoDB
- Mongoose
- Passport
- Nodemon
- Mocha
- apidoc
- ESLint
- ipfs-coord
IPFS
Snapshots pinned to IPFS will be listed here.