AIRS WOMXNEDU — Best GraphQL Project

IndreshP
HackOn
Published in
8 min readAug 31, 2021

The literacy rate of India is 74.04%. The education in rural areas is much less than in urban areas. This leads to a section of society missing out on a lot of stuff and leads to a vicious cycle. There are a lot of educated and skilled women in India who are unemployed currently due to societal and marital pressures. Our solution is aimed at bringing them together. Educated women willing to teach can use our platform to register to teach. A lot of students have laptops issued by various government schemes. The students can use their laptops to access this portal. There are features for students to apply and get certificates regarding the course studied. All the documents are verifiable through a private blockchain. This app uses peer-to-peer video streaming for online classes. PWA also has features to create courses, join them, create and submit assignments, etc. We also were planning on building a feature to provide counselling for the students, but couldn’t finish it due to time constraints.

GraphQL

What is GraphQL?

GraphQL is a query language for reading and mutating data in APIs. As a backend developer, GraphQL provides a type system where you can describe a schema for your data. In turn, this gives front-end consumers of the API the power to explore and request the exact desired data they need.

Why we used GraphQL and you should too

Traditionally developers have consumed APIs using REST where data entities live on a bunch of URLs on a server. When a request is received the API responds with the full data payload of the entity. That sounds simple enough, but there are two potential drawbacks here:

  • We may need multiple entities at one time, in which case each request is under fetching the actual data we want.
  • In other cases, we may only want a small subset of a data entity. In which case, we need to overfetch from the API.

How GraphQL operates

Instead of multiple URLs, a GraphQL API has a single entrypoint. Data is queried or fetched by describing it with a syntax that mirrors its return shape in JSON. The frontend developer describes the data they want while the backend developer writes code to resolve the request. And it all happens in a syntax that can work with any programming language.

Schema

We can start defining a schema with our own custom objects using the ‘type’ keyword.

We can also give integer and string values to create a relationship with another type.

Notice here that a ‘Course’ has a ‘Prof’ and a ‘Prof’ can have many courses (indicated by the square brackets).

Query

Now every GraphQL API has a ‘Query’ type which is the main entrypoint for a consumer of the API. In the below example, from the first query, we can query a list of courses enrolled by a student.

Mutation

This is how a consumer reads data but they may also want to mutate data in which case we implement a mutation type that defines how data can be modified on the API. In the example below, the first mutation creates a ‘Course’ type from the given input as specified by the ‘CreateCourseInput’ input type.

Resolvers

From there we can define code to resolve this data in any programming language. Resolvers define what to do for a given query or a mutation.

This is the resolver for the ‘studentCourse’ query. It returns a list of courses enrolled by a student by fetching it from the database. In this case, it uses the ‘Ottoman ODM’ for couchbase DB.

This is the resolver for the ‘createCourse’ mutation. It creates a course with the given data and then adds the courseID to the corresponding prof’s list of courses. Then, it saves the created course and the updated prof’s details to the database.

Once deployed, any developer who can consume this API will be able to explore it with a complete understanding of all possible queries and data entities.

Preact

Preact provides the thinnest possible Virtual DOM abstraction on top of the DOM. Most UI frameworks are large enough to be the majority of an app’s JavaScript size. Preact is different: it’s small enough that our code is the largest part of our application.

That means less JavaScript to download, parse and execute — leaving more time for our code.

Also Preact is fast, and not just because of its size. It’s one of the fastest Virtual DOM libraries. It’s also portable and instantly productive.

DevOps and Infrastructure

For any project, especially one that uses a lot of stacks like ours, a well defined DevOps architecture is required for smooth functioning and ease of deployment. Here are various components of our deployment and their purpose in our project:

Docker

Nowadays, docker is so widely used that it almost requires no introduction. However, for those who are new to it, docker is a containerisation platform.

Containers are a standardised unit of software that allows developers to isolate their app from its environment, solving the “it works on my machine” compatibility headache.

Docker-compose is a tool for defining and running multi-container Docker applications. In our project, we had the need to run many containers for the various services, hence we used docker-compose.

Each of the services is a container, and the configurations for how to run it. For example, the couchbase service provides us the database service at the specified ports.

Apache

Apache is a web server software. It is the most popular software used for hosting web services. We have used it to host our site, along with the peertube service.

The configuration has been set up such that every user after registration, would be required to authenticate using Client Certificate Authentication. It uses the ‘SSLVerifyClient’ option to allow access only with a valid client certificate.

Peertube

When choosing a platform to stream our online lectures we wanted to put modern technology to test. So, we used an application called peertube, developed by Framasoft, is the free and decentralized alternative to video platforms. It allowed us to create our own video hosting and streaming server with our own set of rules. It was free from ads. One of the shining feature of this tech was the use of peer to peer web torrenting to stream videos. The PeerTube software can, whenever necessary, use a peer-to-peer protocol (P2P) to broadcast viral videos, lowering the load of their hosts.

But an issue we faced was that peertube needed an RTMP stream to broadcast live videos. But browsers do not natively support the RTMP protocol. So we hacked around this by sending the video stream via websockets to the server. The video stream received by the server was converted to RTMP stream using the ffmpeg library.

We created a portal where teachers can just start the meet in a single click and get the meet ID. The link can be sent to students and they can watch the livestream on any device. The stream will also be recorded and saved for future reference of students.

IPFS

IPFS is a distributed system for storing and accessing files and data. IPFS has rules that determine how data and content move around on the network. Instead of referring to data (photos, articles, videos) by location, or which server they are stored on, IPFS refers to everything by that data’s hash, meaning the content itself. The idea is that if you want to access a particular page from your browser, IPFS will ask the entire network if the data corresponding to the hash exists. A node on IPFS that contains the corresponding hash will return the data, allowing you to access it from anywhere. Due to this content-addressable approach, data and files can be stored and served from anywhere by anyone. It also means that if a particular server is down, the content it hosts is unavailable.

In our project, we used IPFS for storing the course certificates of students. It provides a reliable decentralised way of storing the certificates.

Hyperledger

Hyperledger is a permissioned private blockchain technology. Like other blockchain technologies, it has a ledger, uses smart contracts, and is a system by which participants manage their transactions. The members of a Hyperledger Fabric network enroll through a trusted Membership Service Provider (MSP). It also offers the ability to create channels, allowing a group of participants to create a separate ledger of transactions. It supports networks where privacy (using channels) is a key operational requirement as well as networks that are comparatively open. Transactions must be written to the ledger in the order in which they occur, even though they might be between different sets of participants within the network.

In our project, we used Hyperledger for storing the IPFS hashes course certificates of students. The architectures consists of two organisations — Students and Professors and a common channel — “documentchannel” with a course-certificate contract. It provides a tamper-proof way of storing the hashes. We also created a basic admin panel to assist in managing the blockchain network.

Client Certificate Authentication

Client Certificate Authentication is the process by which users securely access a server or remote computer by exchanging a Digital Certificate. The Digital Certificate can then be mapped to a user account and used to provide access control to network resources, web services and websites.

We issue Client Certificates whenever a student registers in our portal and they can use the certificate for future logins without going through the hassle of setting and remembering passwords.

Couchbase

  • High-Performance Key/Value and Query (N1QL, Views, Search, Analytics) operations
  • Cluster-Awareness and automatic rebalance and failover handling
  • Asynchronous (through RxJava) and Synchronous APIs
  • Transparent Encryption Support
  • Cluster and Bucket level management facilities
  • Complete non-blocking stack through RxJava and Netty

--

--

HackOn
HackOn

Published in HackOn

Building the Indian Blockchain Community • Hackathons, Workshops, Grants, and more 💻

No responses yet