A Fully Async-based backend for Moerphous.
Note: MongoDB is being used to store only the wallet classic_address and its seed to make transactions work. This project is just a POC for an NFT marketplace backend. In the future, once deployed on the mainnet, MetaMask will be utilized to connect the wallet.
- Development Requirements
- Project Structure
- Installation with Make
- Access Swagger Documentation
- Access Redocs Documentation
- Authentication and Authorization
- Deployments
- Core Dependencies
- License
- Make (GNU command)
- Python (>= 3.8)
- Poetry (1.2)
❯ tree app
.
├── auth # Package contains different config files for the `auth` app.
│  ├── crud.py # Module contains different CRUD operations performed on the database.
│  ├── router.py # Module contains different routes for this api.
│  └── schemas.py # Module contains different schemas for this api for validation purposes.
├── wallets # Package contains different config files for the `wallets` app.
│  ├── crud.py # Module contains different CRUD operations performed on the database.
│  ├── models.py # Module contains different models for ODMs to inteact with database.
│  ├── router.py # Module contains different routes for this api.
│  └── schemas.py # Module contains different schemas for this api for validation purposes.
├── nfts # Package contains different config files for the `nfts` app.
│  ├── crud.py # Module contains different CRUD operations performed on the database.
│  ├── models.py # Module contains different models for ODMs to inteact with database.
│  ├── router.py # Module contains different routes for this api.
│  └── schemas.py # Module contains different schemas for this api for validation purposes.
├── utils # Package contains different common utility modules for the whole project.
│  ├── dependencies.py # A utility script that yield a session for each request to make the crud call work.
│  ├── engine.py # A utility script that initializes an ODMantic engine and client and set them as app state variables.
│  ├── jwt.py # A utility script for JWT.
│  ├── mixins.py # A utility script that contains common mixins for different models.
├── config.py # Module contains the main configuration settings for project.
├── __init__.py
├── main.py # Startup script. Starts uvicorn.
└── py.typed # mypy related file.The best way to configure, install main dependencies, and run the project is by using make. So, ensure you have make installed and configured on your machine. If it is not the case, head over to this thread on StackOverflow to install it on windows, or this thread to install it on Mac OS.
Having make installed and configured on your machine, you can now run make under the root directory of this project to explore different available commands to run:
make
Please use 'make <target>' where <target> is one of:
venv Create a virtual environment
install Install the package and all required core dependencies
run Running the app locally
deploy-deta Deploy the app on a Deta Micro
clean Remove all build, test, coverage and Python artifacts
lint Check style with pre-commit
test Run tests quickly with pytest
test-all Run tests on every Python version with tox
coverage Check code coverage quickly with the default Python
build Build docker containers services
up Spin up the containers
down Stop all running containersmake venvsource .venv/bin/activatemake installNote: This command will automatically generate a .env file from .env.example, uninstall the old version of poetry on your machine, then install latest version 1.2.2, and install the required main dependencies.
Head over to the official website to create a MongoDB account and a cluster.
Fill in the following environment variables in your .env file accordingly:
# Database
MONGODB_USERNAME=
MONGODB_PASSWORD=
MONGODB_HOST=cluster_name.example.mongodb.net
MONGODB_DATABASE=xrplRegister an account on pinata, and create a new API under the development tab.
Set the following environment variable in your .env file according to your credentials:
# Pinata Cloud
PINATA_API_KEY=
PINATA_API_SECRET=Generate a secret key using OpenSSL and update its env var in the .env file.
openssl rand -hex 128
afa1639545d53ecf83c9f8acf4704abe1382f9a9dbf76d2fd229d4795a4748712dbfe7cf1f0a812f1c0fad2d47c8343cd1017b22fc3bf43d052307137f6ba68cd2cb69748b561df846873a6257e3569d6307a7e022b82b79cb3d6e0fee00553d80913c1dcf946e2e91e1dfcbba1ed9f34c9250597c1f70f572744e91c68cbe76# App config:
JWT_SECRET_KEY=afa1639545d53ecf83c9f8acf4704abe1382f9a9dbf76d2fd229d4795a4748712dbfe7cf1f0a812f1c0fad2d47c8343cd1017b22fc3bf43d052307137f6ba68cd2cb69748b561df846873a6257e3569d6307a7e022b82b79cb3d6e0fee00553d80913c1dcf946e2e91e1dfcbba1ed9f34c9250597c1f70f572744e91c68cbe76
DEBUG=infomake runNote: You have to set DEBUG=info to access the docs.
For development purposes, you can use openapi to interact with the endpoints. To do so, you have to follow the steps below in order:
- Generate a faucet wallet through the
/api/v1/walletpost endpoint.
- Copy the access token from the response, and use it to authorize openapi with the backend.
As you can notice, the default openapi authorization form has been customized to authenticate wallets using only an access token.
- Now you can interact with any endpoint that require authentication.
To run the entire platform, you have to clone the moerphous submodule using the following command:
git submodule update --init --recursiveOnce that is done, make sure you have compose v2 installed and configured on your machine, and run the following command to build the predefined docker services(make sure you have a .env file beforehand):
Using Make
make buildor simply running:
docker compose build
Once that is done, you can spin up the containers:
Using Make
make upor running:
docker compose up
Wait until the client service becomes available:
moerphous-client-1 | Starting the development server...
You can stop the running containers but issuing the following command on a separate terminal session:
make down
You'll need to create a Deta account to use the Deta version of the APIs.
Make sure you have Deta CLI installed on your machine. If it is not the case, just run the following command(on a Linux distro or Mac):
curl -fsSL https://get.deta.dev/cli.sh | shManually add /home/<user_name>/.deta/bin/deta to your path:
PATH="/home/<user_name>/.deta/bin:$PATH"Now you can deploy the app on a Deta Micro:
make deploy-detaYou can then use the Deta UI to check the logs and the URL the API is hosted on.
Notes:
-
Make sure your
.envfile is being provided with valid env vars values accordingly. -
The
main.pyfile is used as an entry point for Deta. The same goes forrequirements.txt. -
Deta Micros are limited to 512MB per deployment.
This button will only deploy the server.
Note that this approach is not perfect because in the docker world, you should only have one service for each container, and you should use docker-compose to build and run more than two containers(e.g. one for the server and the other one for the client). However, Heroku doesn't support docker-compose with multiple services(except databases and such.). Hence running both services in one container.
To do so, ensure you have already installed and configured the Heroku CLI on your machine. If it is not the case, you can install it on Ubuntu using the following command:
sudo wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | shNow, you need to install the Heroku container registry plugin:
heroku plugins:install heroku-container-registryOnce that is completed, log in to your registry:
heroku container:loginNow, create a Heroku app:
heroku create <a unique app name>You can list all your apps to verify that your recent app has been created:
heroku appsSet your env variables in the .env file.
Build your container image:
docker compose -f heroku-compose.yml buildDeploy to Heroku:
heroku container:push web --app <your heroku app name>; heroku logs --tailOnce the build and push are completed, you can run the following command in a separate shell to interact with the app:
heroku open --app=<your app name>You can refer to heroku dev center for more info. Happy Herokuing!
The following packages are the main dependencies used to build this project:
This project and the accompanying materials are made available under the terms and conditions of the MIT LICENSE.





