Code Monkey home page Code Monkey logo

fabric-survey-app's Introduction

Create a JNU survey application with Hyperledger Fabric

๐Ÿ” Note: I wrote this through a translator ๐Ÿ”Ž

This application allows managers to register surveys and check students' responses



Click here to view the network architecture


Flow Diagram



  1. The blockchain operator sets up the Hyperledger Fabric network and the operator installs and instantiates the smart contract on the Fabric network.
  2. The User interacts with the Vue.js Web interface to register surveys and responses, or with the Explorer to identify blocks in the Fabric network.
  3. The Vue.js client uses the API gateway to interact with the overall servers.
  4. The API gateway uses the Express.js applications API to interact with the fabric network and uses the Flask.py application API to recognize card information.
  5. The Express.js application servers use the fabric-sdk-node to interact with the deployed fabric network and creates APIs for a web client.
  6. The Fabric network notifies the event processing Express.js application when an event occurs during an interaction.
  7. The Explorer identifies blocks by interacting with the fabric network through the postgresql DB.

Featured technologies

  • Hyperledger Fabric v1.4 is a platform for distributed ledger solutions, underpinned by a modular architecture that delivers high degrees of confidentiality, resiliency, flexibility, and scalability.
  • Hyperledger Explorer is a user-friendly Web application tool used to view, invoke, deploy or query blocks, transactions and associated data, network information, chain codes and transaction families, as well as any other relevant information stored in the ledger.
  • Node.js is an open source, cross-platform JavaScript run-time environment that executes server-side JavaScript code.
  • Vue.js is an open-source JavaScript framework for building user interfaces and single-page applications.
  • Flask.py is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications.
  • Tesseract is an optical character recognition engine for various operating systems.

Test Environment Software Versions

โš ๏ธ Note: You will need Node >=10.15.3 to run this pattern! โš ๏ธ

Program Version Program Version
Hyperledger Fabric 1.4.0 Hyperledger Explorer 1.0.0
docker 18.09.7 docker-compose 1.17.1
node 10.20.1 NPM 6.14.4
python 3.6.9 pip 20.0.2
Go 1.11

Steps (Local Deployment using dockerize web app)

  1. Clone the Repo
  2. Prepare prerequisites By shell script
  3. Start the Fabric network By shell script
  4. Run the Dockerize web apps By shell script

Step 1. Clone the Repo

Git clone this repo onto your computer:

ubuntu$ git clone https://github.com/woojae9488/fabric-survey-app
ubuntu$ cd fabric-survey-app/

Step 2. Prepare prerequisites By shell script

The shell script in the fabric-survey-app folder provides simple preparation:

ubuntu$ chmod +x prepare.sh
ubuntu$ sudo ./prepare.sh light
ubuntu$ source ./environment

If your computer has less than 1.5GB of memory, you need to add an -S option or an -s <size> Option to create a swapfile.

After all the scripts are run, the version will be checked at the end. Check the versions of the other programs except python and pip.

The source command is to set the necessary environment variables for starting the fabric network.

For more details, see the contents of the prepare.sh file.

Step 3. Start the Fabric network By shell script

The shell script in the fabric-survey-app folder provides simple Fabric network startup:

ubuntu$ chmod +x operate.sh
ubuntu$ sudo ./operate.sh up

When you run a script, the following things happen in order:

  1. Generate certificates through the "artifacts/crypto-config.yaml" file.
  2. Generate channel artifacts through the "artifacts/configtx.yaml" file.
  3. Deploy the required containers on the Fabric network through the docker-compose command and the "arifacts/docker-compose.yaml" file.
  4. Run the "scripts/script.sh" file using the cli docker container.

When you run a script in the cli docker container, the following things happen in order:

  1. Create a surveynet channel.
  2. All peers join in the surveynet channel.
  3. Update anchor peers for each organization.
  4. Install chaincode on all peers.
  5. Instantiate chaincode in each peer.
  6. The query and Invoke are tested since all configurations are complete.

For more details, see the contents of the operate.sh file.

Step 4. Run the Dockerize web apps By shell script

Now, finally, run only the deploy.sh shell script will end the whole process.

ubuntu$ cd web-app/
ubuntu$ chmod +x deploy.sh
ubuntu$ sudo ./deploy.sh start all

If everything is done well, we are ready to access our fabric network. Go to http://[HOST-IP]:8080/ to view the client app, or http://[HOST-IP]:8888/ to view the Explorer app. ๐Ÿ˜„
Now test the web you created. The id and password of the existing manager are admin, adminpw.

If you want to run applications separately from the Explorer or just the Explorer, you can run them through the following commands:

ubuntu$ sudo ./deploy.sh start msa       # Exclude the Explorer
ubuntu$ sudo ./deploy.sh start explorer  # Just the Explorer

For more information, see the contents of the deploy.sh file and the resources in the docker-config directory.


Steps (Local Deployment without dockerize web app)

It is not possible to run the Explorer when running web applications in a local deployment because only dockerized Explorer is available in this code pattern.

These steps overlap with the preceding steps(Step 1. and Step 3.). Therefore, I will explain the other parts only.

  1. Clone the Repo
  2. Prepare all prerequisites By shell script
  3. Start the Fabric network By shell script
  4. Run the web servers and client

Step 2. Prepare all prerequisites By shell script

The shell script in the fabric-survey-app folder provides simple preparation:

ubuntu$ chmod +x prepare.sh
ubuntu$ sudo ./prepare.sh all
ubuntu$ source ./environment

If your computer has less than 1.5GB of memory, you need to add an -S option or an -s <size> Option to create a swapfile.

After all the scripts are run, the version will be checked at the end. Make sure that all version of the programs are checked.

The source command is to set the necessary environment variables for starting the fabric network.

For more details, see the contents of the prepare.sh file.

Step 4. Run the web servers and client

To deploy without a dockerize web servers or client, each servers and client must be run directly. At this step, you can modify and execute the code as you wish.

First, let's run a fabric-manager server, a fabric-student server, and a fabric-event server that connects to the fabric network.

ubuntu$ cd web-app/servers/fabric-manager/
ubuntu$ npm install
ubuntu$ npm start
ubuntu$ cd ../fabric-student/
ubuntu$ npm install
ubuntu$ npm start
ubuntu$ cd ../fabric-event/
ubuntu$ npm install
ubuntu$ npm start

Here, the fabric-student server does not matter, but the fabric-event server must run later than the fabric-manager server. (This is because the fabric-manager server registers the certificate of the fabric-event server.)

Then, run the card-recognize server and the API gateway.

ubuntu$ cd ../card-recognize/
ubuntu$ pip3 install -r ./requirements.txt
ubuntu$ python3 app.py
ubuntu$ cd ../api-gateway/
ubuntu$ npm install
ubuntu$ npm start

If you don't want to use Chonnam National University's student card recognition, you don't have to run the card-recognize server and you have to change the client's student signup process.

Finally, run the client.

ubuntu$ cd ../../client/
ubuntu$ npm install
ubuntu$ npm run serve

If everything is done well, we are ready to access our fabric network. Go to http://localhost:8080/ to see your app. ๐Ÿ˜„
Now test the web you created. The id and password of the existing manager are admin, adminpw.


Stop the Fabric network

After testing network, or if an error occurs and the network must be stopped, go to the fabric-survey-app folder and the following should be done:

ubuntu$ sudo ./operate.sh down

If you also want to shut down dockerize web apps:

ubuntu$ cd web-app/
ubuntu$ sudo ./deploy.sh stop all  # Or msa or explorer

About the surveynet Fabric network

This section will show pictures of the network structure or elements of the surveynet.

Structure of the surveynet Fabric network



How an application communicates with a network



Datasets stored in the ledger



lifecycle of survey state




References

The most helpful references

About using Hyperledger Fabric with Node

About using Node for deploy the servers

About using Vue for deploy the client

About using Flask and Tesseract for deploy the card recognize api

The others

fabric-survey-app's People

Contributors

woojae9488 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.