Table of contents
Introduction
Bank Microservices is my own approach to a bank application, with a microservices-based architecture and using the MERN stack, which can handle creating, updating, and deleting accounts, customers and loans, store data on-chain and make predictions about potential loan defaults.
Technical details
The bulk of this application is made up of (i) smart contracts, which are written in Solidity using Hardhat, and tested using Foundry, (ii) back-end code, written in TypeScript using Express.js and Python using Flask, and (iii) front-end code which is mostly written in TypeScript using Next.js, a React.js framework.
Both, back end (all the APIs but that of the Flask web service) and front end, are implemented based on a hexagonal architecture .
Also, a scikit-learn pipeline has been developed that includes a Skorch neural net binary classifier that wraps a Pytorch neural net. A hyperparameter optimization of both, model and training, evaluated by cross-validation is performed in a Jupyter notebook.
Finally, data can be queried from a local TheGraph node using GraphQL. The subgraph that is used is set to support multiple networks, relevant deployment data will be shared accordingly.
All of the microservices have their own Docker images.
- Contracts frameworks: Hardhat and Foundry
- Front-end framework: Next.js
- Back-end frameworks: Express.js and Flask
- Front-end language: TypeScript
- Back-end language: TypeScript and Python
- Query language: GraphQL
- Data resources: MongoDB and TheGraph
- Styling: PostCSS
- Python dependency manager: Poetry
- Machine learning framework: Pytorch
Overview
packages/*
: npm packages that contain code and configuration files that are used by other packages or services.services/*
: microservices that make up the bulk of the application.services/**/contracts/*
: smart contracts written in Solidity language.services/**/scripts/*
: TypeScript scripts to deploy contracts and to write relevant information about them in both front-end and subgraph workspaces.services/**/tasks/setState
: Hardhat task to set a state to the local node.services/**/contracts/test/foundry/*
: test contracts to run with Foundry.services/client/src/app/*
: React.js functional components, CSSModules files, PostCSS mixins and a global css file.services/client/src/features/*
: services code with its core and data sources.services/client/src/**/shared/*
: user interface code shared across files at the same folder level.services/**/subgraph/scripts/*
: script to generate a subgraph manifest from a template, replacing keys for values from a JSON file.services/**/subgraph/src/*
: mappings, written in AssemblyScript, constants and entities used to extract data from the local Hardhat chain, process them and store them.services/**/subgraph/templates/*
: a subgraph manifest template.services/**/api/**/core/*
: this folder gathers the business logic of each service.services/**/api/**/controllers/*
: functions that define the operations desired by the API of the application.services/**/api/**/data-sources/*
: class that implements methods described in the repositories.
Running locally
This application uses pnpm and is configured to run with Docker Compose.
Open another tab in terminal and:
Testing the contracts
Related posts
I have written the following post to explain in detail this project:
Notes
This project is released under MIT License.