<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohamed Shadab</title>
    <description>The latest articles on DEV Community by Mohamed Shadab (@statebait).</description>
    <link>https://dev.to/statebait</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F132861%2F1ceafca9-377f-4214-8c93-f5de58877015.png</url>
      <title>DEV Community: Mohamed Shadab</title>
      <link>https://dev.to/statebait</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/statebait"/>
    <language>en</language>
    <item>
      <title>Building a Chatroom Web App with Hasura</title>
      <dc:creator>Mohamed Shadab</dc:creator>
      <pubDate>Fri, 15 May 2020 00:00:00 +0000</pubDate>
      <link>https://dev.to/statebait/building-a-chatroom-web-app-with-hasura-14cj</link>
      <guid>https://dev.to/statebait/building-a-chatroom-web-app-with-hasura-14cj</guid>
      <description>&lt;p&gt;You will be learning how to set up Hasura and will learn how to write specific GraphQL queries which help you build this Web App.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Most of the react code is already written and the tutorial branch has only the GraphQL logic/code missing from it. However you can choose to build from scratch while taking reference from &lt;a href="https://github.com/statebait/hasura-chatroom-demo.git"&gt;https://github.com/statebait/hasura-chatroom-demo.git&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Setting up Hasura &amp;amp; the Database
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;To follow the tutorial you will need the tutorial branch of the repository; clone the repository like this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  git clone &lt;span class="nt"&gt;--single-branch&lt;/span&gt; &lt;span class="nt"&gt;--branch&lt;/span&gt; tutorial https://github.com/statebait/hasura-chatroom-demo.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Next, you need to start the docker containers for the PostgreSQL database and Hasura GraphQL Engine. Run the following for that inside the repo:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  docker-compose up &lt;span class="nt"&gt;-d&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This will spin up both the containers and now the Hasura console should be available at:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  http://localhost:8080/console
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If for some reason nothing appears, try running the docker command again.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Get familiar with the console 😃. Navigate to the "DATA" tab and here we will create all the tables we need for the Chatroom Web App.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go ahead and click on 'Create Table' next to the Schema heading.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The first table we will be creating is the 'users' table. Name the table 'users', add a column called username with column_type as Text. Add this column as the primary key. Finally, click "Add Table" below.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  table_name: users
  Columns:
  column_name: username (Primary Key)
  column_type: Text
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Next, we need a table for chatrooms. Create this:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  table_name: chatrooms
  Columns:
  #1
  column_name: id (Primary Key)
  column_type: Integer Auto-Increment
  #2
  column_name: name (Unique)
  column_type: Text
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Finally, we need to create a table for the messages, here we'll need to add 2 Foreign Keys for the chatroom and user.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Create this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  table_name: messages
  Columns:
  #1
  column_name: id (Primary Key)
  column_type: Integer Auto-Increment
  #2
  column_name: text
  column_type: Text
  #3
  column_name: chatroom_id (Foreign Key)
  column_type: Integer
  #4
  column_name: user (Foreign Key)
  column_type: Text
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now navigate below to the Foreign Key section and add the first foreign key from the table chatrooms:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  messages.chatroom_id -&amp;gt; chatrooms.id
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And not the second foreign key from the table users:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  messages.user -&amp;gt; users.username
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Great! Now you are done with adding the tables!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Go ahead and click on the chatrooms table and go to the 'Insert Rows' tab. Here add one chatroom with any name you like. (You can add multiple too 😇).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now go to the "GRAPHIQL" tab. This is a GraphQL playground where you can play and test different queries before adding them to your Apps. In this demo, we will deal with all the 3 types of queries available in GraphQL - Query, Mutation, Subscription.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the 'Explorer' (If you can't see there should be a button to named 'Explorer' to open it up) you will see a bunch of queries already there which you can just click on and add. In the bottom part of the Explorer, you can add (switch) to Mutations/Subscriptions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Building the Web App
&lt;/h3&gt;

&lt;p&gt;The React app consist of three views:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Login&lt;/li&gt;
&lt;li&gt;Chatroom List&lt;/li&gt;
&lt;li&gt;Chatroom&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tutorial branch has all the code for the working demo except all the GraphQL related logic, which is the main focus of this tutorial.&lt;/p&gt;

&lt;p&gt;So let's begin!&lt;/p&gt;

&lt;p&gt;Install dependencies by running the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Apollo Setup
&lt;/h4&gt;

&lt;p&gt;We will be using the &lt;a href="https://www.apollographql.com/docs/react/"&gt;Apollo Client (React)&lt;/a&gt; for querying the GraphQL API generated by Hasura&lt;/p&gt;

&lt;p&gt;Start by creating a file called &lt;code&gt;apollo.js&lt;/code&gt; inside of the &lt;code&gt;src&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;The file should have this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ApolloClient&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apollo-client&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;WebSocketLink&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apollo-link-ws&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;HttpLink&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apollo-link-http&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;split&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apollo-link&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getMainDefinition&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apollo-utilities&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;InMemoryCache&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apollo-cache-inmemory&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wsLink&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;WebSocketLink&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ws://localhost:8080/v1/graphql&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;reconnect&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;httpLink&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;HttpLink&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://localhost:8080/v1/graphql&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;link&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;definition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getMainDefinition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nx"&gt;definition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;kind&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;OperationDefinition&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
      &lt;span class="nx"&gt;definition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;operation&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;subscription&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="nx"&gt;wsLink&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;httpLink&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;InMemoryCache&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;ApolloClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;link&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-web-client&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1.3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;queryDeduplication&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;defaultOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;watchQuery&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;fetchPolicy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cache-and-network&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the above code, we use 2 links and a split method which dynamically switches the link depending on the type of operation. We need this functionality because we will be using subscriptions which don't use the regular http connection and instead use a web socket connection.&lt;/p&gt;

&lt;h4&gt;
  
  
  Login View
&lt;/h4&gt;

&lt;p&gt;The Login View has a simple input box where one can enter their name; on entering the name a mutation to create a user is made in the database, the 'USER' key is added to local storage for future use and finally, the user is navigated to the chatrooms view.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;src/components/Login.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add the following imports:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;graphql-tag&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useMutation&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@apollo/react-hooks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, we need a mutation to add the user to the database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ADD_USER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
  mutation addUser($user: String) {
    insert_users(objects: { username: $user }) {
      affected_rows
    }
  }
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then add this hook to the Login component that uses the mutation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;addUser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="p"&gt;}]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useMutation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ADD_USER&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;addUser&lt;/code&gt; in the above code is a promise given to you. We need to execute it on submit so add this to the onSubmit function inside the &lt;code&gt;if&lt;/code&gt; block:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;addUser&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;variables&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;USER&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;handleLogin&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Chatroom List View
&lt;/h4&gt;

&lt;p&gt;The Chatroom List View is a simple list of clickable chatrooms available. It requires a simple query to fetch the chatrooms.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;src/components/ChatroomList.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add the following imports:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useQuery&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@apollo/react-hooks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;graphql-tag&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next, we need a query to fetch the chatrooms from the database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;GET_CHATROOMS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
  {
    chatrooms {
      name
      id
    }
  }
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then add this hook to the ChatroomList component that uses the query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;GET_CHATROOMS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Chatroom view
&lt;/h4&gt;

&lt;p&gt;The Chatroom View is the crux of the Web App, it displays the list of messages sent in the chatroom and an input field to send more messages.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;src/components/Chatroom.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add the following imports:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useSubscription&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useMutation&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@apollo/react-hooks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;graphql-tag&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We need a subscription for the messages and a mutation to add a message to the database;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MESSAGE_SUBSCRIPTION&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
  subscription messageSubscription($chatroomId: Int!) {
    messages(where: { chatroom_id: { _eq: $chatroomId } }) {
      id
      text
      user
    }
  }
`&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SEND_MESSAGE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
  mutation sendMessage($chatroomId: Int, $text: String, $user: String) {
    insert_messages(
      objects: { chatroom_id: $chatroomId, text: $text, user: $user }
    ) {
      affected_rows
    }
  }
`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Add the following hooks to use the above subscription and mutation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useSubscription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;MESSAGE_SUBSCRIPTION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;variables&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;chatroomId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;sendMessage&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useMutation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;SEND_MESSAGE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Vola! You should have a working application!&lt;/p&gt;

</description>
      <category>hasura</category>
      <category>graphql</category>
      <category>react</category>
      <category>apollo</category>
    </item>
    <item>
      <title>Yoctosehns Software Architecture</title>
      <dc:creator>Mohamed Shadab</dc:creator>
      <pubDate>Sun, 26 Apr 2020 00:00:00 +0000</pubDate>
      <link>https://dev.to/statebait/yoctosehns-software-architecture-57bh</link>
      <guid>https://dev.to/statebait/yoctosehns-software-architecture-57bh</guid>
      <description>&lt;p&gt;The early platform of Yoctosehns can be divided into 4 services; 2 independent micro frontends one used for statistical calculation and the other for general monitoring built with ReactJS and AngularJS respectively. The other 2 services were a Python Flask based REST API which crudely inserted data on to the final service that is the MySQL Database.&lt;/p&gt;

&lt;p&gt;The Flask service had multiple APIs (mostly CRUD) baked into it for fetching data from the database and one rather important API which handled all the HTTP requests from the Hardware nodes to make entries into the database.&lt;/p&gt;

&lt;p&gt;Redesigning this was important as having 2 different frontends which easily could have been the same module was difficult to manage. Other than that, since the data was used to perform statistics and advanced monitoring, there was a lot of varied data fetching involved. Creating separate APIs for each of these was difficult.&lt;/p&gt;

&lt;p&gt;The new software architecture of Yoctosehns utilizes Microservices architecture. In this architecture, each process is isolated into a different service that that is independent of each other. They communicate with each other through the help of the REST API (Application Programming Interface) and GraphQL API which both leverage the HTTP protocol under the hood.&lt;/p&gt;

&lt;p&gt;An architecture diagram to explain it better:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JiR5lykA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ad50guco6d3s4l3vxdlu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JiR5lykA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ad50guco6d3s4l3vxdlu.png" alt="Architecture Diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Python Flask Server
&lt;/h2&gt;

&lt;p&gt;Tools/Technologies used: &lt;a href="https://flask.palletsprojects.com/en/1.1.x/"&gt;Python Flask&lt;/a&gt;, &lt;a href="https://flask-cors.readthedocs.io/en/latest/"&gt;Flask CORS&lt;/a&gt;, &lt;a href="https://flask-sqlalchemy.palletsprojects.com/en/2.x/"&gt;Flask SQLAlchemy&lt;/a&gt;, &lt;a href="https://arrow.readthedocs.io/en/latest/"&gt;Arrow&lt;/a&gt;, &lt;a href="https://flask-jwt-extended.readthedocs.io/en/stable/"&gt;Flask JWT Extended&lt;/a&gt;, &lt;a href="https://gunicorn.org/"&gt;Gunicorn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the heart/core of the entire system. It handles authentication, requests from the hardware components and inserting the data coming from the hardware nodes into the database. The Arrow library for python is used to manage timestamps and dates in the computations and data storage in the database. Gunicorn is used as the production server for the Flask App and its powerful logging system is leveraged to monitor the different requests coming in from the Hardware nodes.&lt;/p&gt;

&lt;p&gt;Its sub-components are:&lt;/p&gt;

&lt;h4&gt;
  
  
  REST API
&lt;/h4&gt;

&lt;p&gt;A very small set of APIs used to handle incoming requests from the Hardware Nodes. REST which stands for Representational state transfer is a software architectural style that defines a set of constraints to be used for creating Web services. Web services that conform to the REST architectural style, called RESTful Web services, provide interoperability between computer systems on the Internet. We use the REST API which is built on top of the HTTP protocol to communicate with the Hardware nodes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Authentication system
&lt;/h4&gt;

&lt;p&gt;The Authentication system facilitates all the authorization processes throughout the platform. It is&lt;br&gt;
a simple JWT (JSON Web Token) based authentication system which handles auth based requests from the frontend and has a shared secret with the Hasura GraphQL Engine. It functions with the use of an access token which is generated using the HS256 encryption algorithm with a secret only known to the backend. The communication happens through a single endpoint based on the REST API explained below leveraging the HTTP protocol.&lt;/p&gt;

&lt;h4&gt;
  
  
  SQLAlchemy ORM
&lt;/h4&gt;

&lt;p&gt;SQLAlchemy ORM (Object-Relationship Mapping) is used to have a well-defined schema using different models corresponding to the tables in the Database. This ORM is also used to handle inserting the monitoring data from the Hardware nodes into the database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hasura GraphQL Engine
&lt;/h2&gt;

&lt;p&gt;Tools/Technologies used: &lt;a href="https://hasura.io/"&gt;Hasura&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Hasura GraphQL Engine coupled with the database form the brain of the system. Hasura is an open-source engine that connects to your databases &amp;amp; microservices and auto-generates a production-ready GraphQL backend. It generates a thorough GraphQL API for all the different tables present in the PostgreSQL database. We can query, mutate, or subscribe to any part of the database using this and it makes fetching varying data a breeze on the frontend. GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools. It also uses the HTTP protocol for communication under the hood.&lt;/p&gt;

&lt;h2&gt;
  
  
  PostgreSQL Database
&lt;/h2&gt;

&lt;p&gt;Tools/Technologies used: &lt;a href="https://www.postgresql.org/"&gt;PostgreSQL&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Contains all of the data we store from the Hardware Nodes and also computed data of the different statistics we perform on that data in a multitude of different tables. It is connected to the GraphQL Engine using the HTTP and to the Flask based server using the SQLAlchemy ORM.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frontend
&lt;/h2&gt;

&lt;p&gt;Tools/Technologies used: &lt;a href="https://nextjs.org/"&gt;NextJS&lt;/a&gt;, &lt;a href="https://www.apollographql.com/"&gt;Apollo GraphQL&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Frontend handles interface processes, visualization, and interaction with users. It contains a well-organized dashboard with useful insights and monitoring data for the users. The technology used to build this is NextJS (which uses ReactJSs rendering engine) as the main framework and using the sophisticated GraphQL API exposed by Hasura allows for detailed data throughput between the systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Containerization
&lt;/h2&gt;

&lt;p&gt;Tools/Technologies used: &lt;a href="https://www.docker.com/"&gt;Docker&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have used Docker to containerize the entire software stack into multiple different containers i.e one for the database, one for the flask server etc. This allows us with a predictable and safe production environment which is highly scalable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;The next steps involved adding &lt;a href="https://www.nginx.com/"&gt;NGINX&lt;/a&gt; to the mix. NGINX is a load balancer that accelerates content and application delivery, improves security, facilitates availability and scalability. Therefore integrating this would be a big win.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>python</category>
      <category>sqlalchemy</category>
      <category>postgres</category>
    </item>
    <item>
      <title>GSoC 2019 Documented</title>
      <dc:creator>Mohamed Shadab</dc:creator>
      <pubDate>Sat, 09 Nov 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/statebait/gsoc-2019-documented-e4n</link>
      <guid>https://dev.to/statebait/gsoc-2019-documented-e4n</guid>
      <description>&lt;h2&gt;
  
  
  &lt;a href="https://summerofcode.withgoogle.com/archive/2019/projects/4861160250146816/"&gt;Project Info&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Project:&lt;/strong&gt; Web Pipeline For Kinetic (ODE-Based) Models&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt; Ordinary differential equations are widely used for modelling biological networks and processes of kinetics. The idea of the project is to create a web application that allows a user to submit an SBML model and select methods of analysis and receive results. The different kind of analysis methods that will be available for use are Steady State Analysis, Parameter Fitting, Simulation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Organization:&lt;/strong&gt; Computational Biology @ University of Nebraska-Lincoln&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mentors:&lt;/strong&gt; Achilles Rasquinha, Robert Moore&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 1
&lt;/h2&gt;

&lt;p&gt;The objectives for my phase one were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a project boilerplate&lt;/li&gt;
&lt;li&gt;Setup SBML parser API (SBML abbr. for Systems Biology Markup Language)&lt;/li&gt;
&lt;li&gt;Create Canvas and Render Model using ccNetViz&lt;/li&gt;
&lt;li&gt;Decrease memory footprint of Docker Images&lt;/li&gt;
&lt;li&gt;Create a simulation tab with appropriate panels&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/HelikarLab/ode-app/issues/1"&gt;Create a project boilerplate&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Tools/Technologies used: &lt;a href="https://facebook.github.io/create-react-app/"&gt;Create React App&lt;/a&gt;, &lt;a href="https://reactjs.org/"&gt;ReactJS&lt;/a&gt;, &lt;a href="https://nodejs.org/en/"&gt;NodeJS&lt;/a&gt;, &lt;a href="https://expressjs.com/"&gt;ExpressJS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The project was to be developed with ReactJS for the frontend and NodeJS for the backend. My mentor had suggested some boilerplates to begin with but honestly, I am not a fan of boilerplate and love to go vanilla and then build upon that. So what did I do, well what anybody would do - used create react app for the React part and copied the code of some other Node (express) project I had done before. And there you go, easy right, well not really, things got complex over time as we needed to integrate python and docker into the project.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/HelikarLab/ode-app/issues/2"&gt;Setup a SBML parser API&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Tools/Technologies used: &lt;a href="https://www.python.org/"&gt;Python&lt;/a&gt;, &lt;a href="https://github.com/sbmlteam/python-libsbml"&gt;Python API for libsbml&lt;/a&gt;, &lt;a href="https://github.com/extrabacon/python-shell"&gt;python-shell&lt;/a&gt;, &lt;a href="https://github.com/utatti/express-formidable"&gt;express-formidable&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this task, the idea was that the user would upload a SBML file and the application would return all the information present in the SBML file. For this, we had to research the different SBML parser libraries available and in which language was their API written. We finally decided to go with python-libsbml as it was developed by the team which developed SBML itself and was actively maintained, had a comprehensive API along with good docs.&lt;/p&gt;

&lt;p&gt;Using the python parser entailed a python integration with NodeJS (as the parsing would happen in the backend) and I initially thought this would be troublesome but it turned out to be as easy as importing an npm package and calling its API, namely python-shell.&lt;/p&gt;

&lt;p&gt;The code for the above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;PythonShell&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sbmlParser.py&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Something went wrong.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;unlinkSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./uploads/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;a href="https://github.com/HelikarLab/ode-app/issues/3"&gt;Create Canvas and Render Model using ccNetViz&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Tools/Technologies used: &lt;a href="https://github.com/HelikarLab/ccNetViz"&gt;ccNetViz&lt;/a&gt;, &lt;a href="https://reactstrap.github.io/"&gt;reactstrap&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The objective of this task was to create an acceptable visualisation of the SBML model that was parsed by the backend so that the user can understand the model better. Now to understand how the model would be visualised we need to understand what constitutes a model. Each model has multiple reactions. Each reaction is reversible or irreversible and has products and reactants. Each product/reactant is a specie. All of this information needed to be adequately represented by a graph. It took some time but the Mentors figured out a way and well only the implementation was remaining.&lt;/p&gt;

&lt;p&gt;The toughest part of this task was to get ccNetViz work with React. Once I figured that (it was trial and error 😪), figuring out the logic of how to create the nodes and edges for the graph was also kind of a challenge, mostly because ccNetViz has an API caveat, i.e. you need to give references of the nodes when you are defining edges.&lt;/p&gt;

&lt;p&gt;As for other details, I developed a bare minimum interface (with reactstrap) for the app which displayed information of each reaction, specie and the model info.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/HelikarLab/ode-app/issues/5"&gt;Decrease memory footprint of Docker Images&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Proceed only if you know what docker is and how it works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tools/Technologies used: &lt;a href="https://www.docker.com/"&gt;Docker&lt;/a&gt;, &lt;a href="https://hub.docker.com/r/statebait/python-libsbml"&gt;Docker Python libSBML&lt;/a&gt;, &lt;a href="https://hub.docker.com/_/alpine"&gt;Docker Official Alpine Image&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All the docker images we used were around 1gb each and having a 3 container system (which later became to 2) that is a lot of memory and therefore the need to reduce the memory footprint of the Docker Images came up.&lt;/p&gt;

&lt;p&gt;Now, if you have the question that, how does one do that? Yeah, my mind raced through the same question. Mentor, to the rescue; "Use an alpine image". 🙌&lt;/p&gt;

&lt;p&gt;"A minimal Docker image based on Alpine Linux with a complete package index and only 5 MB in size!"&lt;/p&gt;

&lt;p&gt;Alpine images are great. If you aren't using them you should. I made my own &lt;a href="https://github.com/shadxx7/docker-python-libsbml"&gt;base image&lt;/a&gt; for python-libsbml and got the memory footprint down a lot.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/HelikarLab/ode-app/issues/6"&gt;Create a simulation tab with appropriate panels&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Tools/Technologies used: &lt;a href="https://github.com/STRML/react-grid-layout"&gt;React-Grid-Layout&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this task, I was to create 4 different panels which contain configuration required for the simulation. The difficult part of this task was figuring out a sustainable/scalable state and manipulating it as each panel intercommunicated with each other in the effort to create a viable configuration. To use easy-peasy for global state management was a great choice and helped a lot in this task but more on that in 'Extras'.&lt;/p&gt;

&lt;p&gt;As for the panels, used react-grid-layout which makes it super easy to create draggable and resizeable layouts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 2
&lt;/h2&gt;

&lt;p&gt;As most of the basis of the project was laid down, now all of the logic for the kinetic laws was to be implemented. This phase involved a deep dive into biochemistry, understanding the bio models we were dealing with and the kind of kinetic laws that exist and how they work.&lt;/p&gt;

&lt;h3&gt;
  
  
  Choosing a simulation library
&lt;/h3&gt;

&lt;p&gt;I had to finalize which library I was going to use to form the system of differential equations and solve them to receive the concentration values. This honestly took a lot of time as there were many libraries which did this with each having some trade-off. We finally decided to go with &lt;a href="https://pypi.org/project/stimator/"&gt;stimator&lt;/a&gt; because of the simple API it provided.&lt;/p&gt;

&lt;p&gt;Example of the API it provided:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;stimator&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;read_model&lt;/span&gt;

&lt;span class="n"&gt;model_description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"""
title A two-reaction chemical system
r1: A -&amp;gt; B, rate = k1 * A
r2: B -&amp;gt; C, rate = k2 * B - k3 * C
k1 = 0.1
k2 = 2
k3 = 1
init: (A = 1)
"""&lt;/span&gt;

&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;read_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_description&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The only problem with this library was...well it didn't work out of the box. What I did was that I downloaded the source files, found the bug that was causing it not to work, fixed it, repackaged the source files into a wheel file and now I ship the custom fixed library in the app itself. If you need to learn how to package your own wheel file to install using pip see &lt;a href="https://dzone.com/articles/executable-package-pip-install"&gt;this&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Building the plot panel
&lt;/h3&gt;

&lt;p&gt;Tools/Technologies used: &lt;a href="https://apexcharts.com/"&gt;Apex Charts&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The plot that displayed the simulation which was a timeline of the change in concentration values of the species taking part in the simulation needed to have a configurable API because the species could be toggled in/out of the plot. Apex Charts provided the perfect API for the same.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://camo.githubusercontent.com/ed2ce7255c9fd70c83759d0c721baa595a8bc6e2/68747470733a2f2f692e696d6775722e636f6d2f4c4c31634854362e676966" class="article-body-image-wrapper"&gt;&lt;img src="https://camo.githubusercontent.com/ed2ce7255c9fd70c83759d0c721baa595a8bc6e2/68747470733a2f2f692e696d6775722e636f6d2f4c4c31634854362e676966" alt="Demo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Kinetic Laws
&lt;/h3&gt;

&lt;p&gt;The simulations performed are basically applying a particular Kinetic Law to a reaction and devising a rate for the reaction.&lt;/p&gt;

&lt;p&gt;There are 3 Kinetic Laws currently available to use in the application:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Law of Mass Action&lt;/li&gt;
&lt;li&gt;Michaelis-Menten Kinetics&lt;/li&gt;
&lt;li&gt;Hill Kinetics&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other than this you can define your own Custom Rate in the application.&lt;/p&gt;

&lt;p&gt;You can learn more in the &lt;a href="https://github.com/HelikarLab/ode-app/wiki/Kinetic-Laws"&gt;wiki.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 3
&lt;/h2&gt;

&lt;p&gt;Phase 3 was mostly refactoring the code, commenting, documentation and finally testing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Refactoring, Commenting and Documentation
&lt;/h3&gt;

&lt;p&gt;Tools/Technologies used: &lt;a href="https://www.npmjs.com/package/prop-types"&gt;prop-types&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Refactoring involved visiting all files and cleaning up unnecessary code, breaking down bigger components into smaller ones and finally adding Prop-Types to each component for better runtime assertions and to increase code readability. Further, writing comments on any function which did not straight out make sense was done to increase code readability. Finally, the documentation involved writing development related instructions in the &lt;a href="https://github.com/HelikarLab/ode-app/blob/develop/README.md"&gt;README&lt;/a&gt; and all docs related to usage, application architecture, kinetic laws and references were written in the &lt;a href="https://github.com/HelikarLab/ode-app/wiki"&gt;GitHub repository wiki&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Testing
&lt;/h3&gt;

&lt;p&gt;Tools/Technologies used: &lt;a href="https://www.cypress.io/"&gt;cypress&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For testing, we used cypress, a E2E testing framework. Cypress is hands down amazing 🤩. The kind of automation you can achieve with this framework is phenomenal. Its API is relatively easy and the features it provides complements the entire testing process. Further, it helps you write code which is easier to test and also helps you keep test cases in mind while coding. Tests are simple, for eg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Reactions populated&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;cy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[data-test="reactions-table"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tbody&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tr&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above code gets the reaction table and checks if the reactions were properly loading into the model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Extras
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Docker
&lt;/h4&gt;

&lt;p&gt;To achieve consistent behaviour across different Operating Systems and to simplify the deployment process, docker was integrated into the project. 3 different containers were used - Server, Client and the database. All of them are launched together using docker-compose.&lt;/p&gt;

&lt;h4&gt;
  
  
  Database
&lt;/h4&gt;

&lt;p&gt;The database used was &lt;a href="https://www.postgresql.org/"&gt;PostgreSQL&lt;/a&gt; and the ORM in NodeJS was &lt;a href="http://docs.sequelizejs.com/"&gt;Sequelize&lt;/a&gt;. The App contains 3 models - Model, Reactions and Species. Honestly, I changed the models a bunch of times until I was satisfied with the structure and with that said I am sure they ought to change a few times as the application grows. Other than that currently 2 API's integrate the Database with the application; 'save model' and 'load model' API.&lt;/p&gt;

&lt;h4&gt;
  
  
  easy-peasy
&lt;/h4&gt;

&lt;p&gt;Initially, I used &lt;a href="https://redux.js.org/"&gt;Redux&lt;/a&gt; for the state management of the react app. If you are accustomed to Redux then you would know the boilerplate it entails which started becoming an issue. Just then I came across this new library &lt;a href="https://easy-peasy.now.sh/"&gt;easy-peasy&lt;/a&gt;. A state management library built on top of Redux which takes away all the boilerplate of Redux and makes state management extremely easy(as the name suggests 😁). It features a hook based API which gave me the incentive to migrate the entire react app to use react hooks(and now all the code looks really clean).&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;Learned a ton of things during my Google Summer of Code 2019 and it is a must-do if you are a student and want to pursue software engineering.&lt;/p&gt;

&lt;p&gt;With that said I also started contributing to the ccNetViz library (with over 5 PRs merged!) and I must say the entire HelikarLab team is amazing, super supportive, helpful and resourceful.&lt;/p&gt;

&lt;p&gt;Finally, I would like to thank my mentors greatly for all their support.&lt;/p&gt;

</description>
      <category>gsoc</category>
      <category>react</category>
      <category>python</category>
    </item>
    <item>
      <title>Web Development on Windows</title>
      <dc:creator>Mohamed Shadab</dc:creator>
      <pubDate>Sun, 24 Mar 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/statebait/web-development-on-windows-4d64</link>
      <guid>https://dev.to/statebait/web-development-on-windows-4d64</guid>
      <description>&lt;p&gt;In popular belief, Windows is not preferred to do web development on and for that matter any kind of development. But honestly, this has changed over the years as Windows has matured into what it is today.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This article assumes you are using Windows 10, however since Windows offers a decent amount of&lt;br&gt;
backwards compatibility, you should be able to pull this off with an older version of Windows too.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Terminal
&lt;/h2&gt;

&lt;p&gt;Lets get started with the terminal. The terminal will be extensively used as you will be using a wholesome of different CLIs (Command Line Interfaces, like npm). Primarily you should be using PowerShell and bash (I’ll get to this) with a wrapper like &lt;a href="https://hyper.is/"&gt;hyper&lt;/a&gt;. Hyper is electron-based terminal built on HTML/CSS/JS. It has loads of extensions to add utility and themes to lavish your experience.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z9kWm4Qr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x48egesbs9hf6i5g1cdh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z9kWm4Qr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x48egesbs9hf6i5g1cdh.jpg" alt="terminal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’ve mentioned the use of bash. Yes, you can install bash on windows and no it’s not a gimmick or some half-baked thing, its the real deal. Meet the Windows Subsystem for Linux (This feature was added to one of the later versions of Windows 10). &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10"&gt;Here&lt;/a&gt; is how to install it. You should use bash whenever PowerShell is giving you unheeded trouble. Remember that when you run bash, its a completely different OS running somewhere on your windows and therefore you need to make fresh installations of all your CLIs using the appropriate commands(depends on which Linux installation you choose).&lt;/p&gt;

&lt;h2&gt;
  
  
  Handy Tools
&lt;/h2&gt;

&lt;p&gt;Moving on let’s install a command-line installer. This is quite handy for doing quick installs of different tools. The 2 most popular options on windows are &lt;a href="https://scoop.sh/"&gt;Scoop&lt;/a&gt; and &lt;a href="https://chocolatey.org/"&gt;Chocolatey&lt;/a&gt;. I personally prefer Scoop, because of its more minimal operation, but you couldn’t go wrong with either(installing both is also an option). These let you install things like Node, Python etc. in the blink of an eye.&lt;/p&gt;

&lt;p&gt;Next, we need to pick a good web package manager. Again the 2 most popular ones are npm and yarn. npm will be installed by default when you install Node.js. You can install yarn here. Yarn uses npm’s package repository, the only difference being is the way it handles dependencies and its performance (You can read more about the differences on its website). I personally use yarn, but you cannot go wrong with either. There is one more package manager which is not used anymore (but is maintained), but I think I’ll mention it anyway; bower.&lt;/p&gt;

&lt;p&gt;Also having Git installed is kind of necessary as it serve as the backbone of most modern web projects and for that matter any development project 😜(&lt;a href="https://medium.com/code-dementia/why-and-how-you-should-start-using-git-github-right-now-28617df72545"&gt;Here&lt;/a&gt; is a guide on Git and GitHub by Hemant Jain). Finally, you might come across a few errors due to missing build tools. These are the &lt;a href="https://www.npmjs.com/package/windows-build-tools"&gt;windows-build-tools&lt;/a&gt;, which are some modules necessary for compiling, running and building different stuff. While I’m not clear on exactly what modules this package contains, it has helped me avoid a lot of errors when I was trying out new stuff and is mandatory for a lot of different projects. You can simply install them by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--global&lt;/span&gt; windows-build-tools
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Or, if you are using Yarn:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn global add windows-build-tools
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Code Editor
&lt;/h2&gt;

&lt;p&gt;The Code Editor is one of the most important things in web development and as a matter of fact in any kind of development (yes, I have a habit of repeating phrases). Having a seamless experience during coding, debugging can help with all the frustration that comes along with it. Personally, I have used a lot of different code editors, some that come loaded with a plethora of features and some that just have the bare minimum. However, there was only one that stuck; VS Code (abbr. for Visual Studio Code). VS Code comes with a handful features out of the box which should be enough to get you started and as you proceed you can explore its vast extensions marketplace to enhance your experience. VS Code with a good set of extensions can easily replicate a modern full-fledged IDE and all that with exceptional performance. Currently, its the most popular code editor for a lot of different categories of developers and receives new updates and features every month.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xLH3X7Zp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/u9nbdql01o3xeyf4eswv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xLH3X7Zp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/u9nbdql01o3xeyf4eswv.png" alt="vscode"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enough VS Code, moving on we have other options like &lt;a href="https://atom.io/"&gt;Atom&lt;/a&gt;, &lt;a href="https://www.sublimetext.com/"&gt;Sublime&lt;/a&gt;, &lt;a href="http://brackets.io/"&gt;Brackets&lt;/a&gt; and &lt;a href="https://www.jetbrains.com/webstorm/"&gt;WebStorm&lt;/a&gt; etc. Atom is very similar to VS Code but the place it lacks mainly is performance, as you load new extensions in Atom, it slows down significantly. WebStorm is an industry level IDE with all the important features out of the box but it is not free (unless you are a student enrolled in a school).&lt;/p&gt;

&lt;p&gt;Alternatively, you could also use a Cloud IDE which basically are code editors running on the browsers. They come with a lot of handy features. Some of them are &lt;a href="https://codesandbox.io/"&gt;Code Sandbox&lt;/a&gt;, &lt;a href="https://www.gitpod.io/"&gt;GitPod&lt;/a&gt; and &lt;a href="https://coder.com/"&gt;Coder&lt;/a&gt; etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  API Tester
&lt;/h2&gt;

&lt;p&gt;Having an API Tester (for REST and GraphQL API’s)is really important as when you develop different API’s for your application in your back-end, the easiest way to test them are these. The 2 most popular ones are &lt;a href="https://www.getpostman.com/"&gt;Postman&lt;/a&gt; and &lt;a href="https://insomnia.rest/"&gt;Insomnia&lt;/a&gt;, the latter also has GraphQL support. I personally use Insomnia due to its easier to use interface and the free themes available. Postman on the other hands has a lot of different team features which are helpful when you are working on large projects with larger teams. You couldn’t go wrong with either of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  UI/UX Design
&lt;/h2&gt;

&lt;p&gt;Whether you like it or not, User Interfaces and User experiences are an integral part of web development. When developing the front-end of any web project it some times it helps a lot to start with creating mockups &amp;amp; prototypes of the interface. Some easy (and free) to use tools for this are &lt;a href="https://www.figma.com/"&gt;Figma&lt;/a&gt; and &lt;a href="https://www.adobe.com/in/products/xd.html"&gt;Adobe XD&lt;/a&gt;. I prefer using Figma, mainly because it has an option to easily export the CSS of any object created. Other than that you couldn’t go wrong with either.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Developing the Web on Windows has never been as easy as it is today, so let go of the myth that only Mac’s and Linux PC’s can do it and start developing on Windows today. 😃&lt;/p&gt;

</description>
      <category>windows</category>
      <category>development</category>
    </item>
    <item>
      <title>Mistakes I Made in My First React App</title>
      <dc:creator>Mohamed Shadab</dc:creator>
      <pubDate>Thu, 24 Jan 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/statebait/mistakes-i-made-in-my-first-react-app-5afd</link>
      <guid>https://dev.to/statebait/mistakes-i-made-in-my-first-react-app-5afd</guid>
      <description>&lt;p&gt;I decided to write this article for all the people starting out with new React projects, in hope that it helps them in some way.&lt;br&gt;
Why React? Its pretty simple, at this point in my life I was just stepping into the cosmos of Web, and React was the most popular front-end framework.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZT-VKBjy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gmvyt6fpevttxn690qyw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZT-VKBjy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gmvyt6fpevttxn690qyw.jpg" alt="react-universe"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The app I built is used for the Elections of the Student Body Government in my College and it took me approximately 2 months to complete it. Link to the GitHub repository: &lt;a href="https://github.com/shadxx7/elections-frontend"&gt;https://github.com/shadxx7/elections-frontend&lt;/a&gt;. So let’s begin:&lt;/p&gt;
&lt;h2&gt;
  
  
  State Management
&lt;/h2&gt;

&lt;p&gt;If you’ve learned React enough and for that matter any good JS front-end framework, you would know the importance of state management. Good state management is key to a scalable and flexible application.&lt;/p&gt;

&lt;p&gt;React allows you to use different state managing libraries, the most popular being Redux and as expected I also used it in this project but let me be clear, &lt;strong&gt;Redux is not always the answer&lt;/strong&gt;. Now don’t get me wrong, Redux is great, but &lt;em&gt;yes the infamous but&lt;/em&gt; its not meant for all projects. Redux, as it defines itself, is a “Predictable State Container”, which basically means that it enables you to maintain a global state throughout your React app and you can plug this state into any component you wish. All sounding great? The problem comes in when you realize the amount of overhead code you need to write to achieve this. Some would argue that what is the problem? The problem is that sometimes its just not necessary to maintain a global state and this, of course, varies with your use case, but I can’t tell how much time I would have saved if I decided to do things differently.&lt;/p&gt;

&lt;p&gt;So conclusion; don’t use Redux? No, its more like before deciding on a state library, its better to assess the needs of the app, study the different libraries like MobX or maybe even use React Context API and then finalize on what you want to use and where.&lt;/p&gt;
&lt;h2&gt;
  
  
  Testing
&lt;/h2&gt;

&lt;p&gt;Testing, this single word is able to spring hateful emotions in millions of developers around the world. However you feel, I made the terrible mistake of avoiding it until I finished most of the application. At first, it never seems apparent to write tests for every little UI/function you add in your application, but when you are finalizing your application and need to perform full tests, it is painful to do them manually and also humanly impossible to cover all the different test cases, especially when it comes to UI testing. This is when you realize writing tests alongside writing your components comes in really handy. Currently, to write my tests, I’m using the &lt;a href="https://testing-library.com/docs/react-testing-library/intro"&gt;react-testing-library&lt;/a&gt; and I found it great so far. Other libraries also exist, like Airbnb’s &lt;a href="https://airbnb.io/enzyme/"&gt;enzyme&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Class and Functional Components
&lt;/h2&gt;

&lt;p&gt;When starting out in React, everyone usually prefers class components over functional ones. I&lt;br&gt;
initially also used class components everywhere. Then again, it only makes sense to, as React&lt;br&gt;
life-cycle methods are only available to class components (this is assuming Hooks haven’t released),&lt;br&gt;
but the use of functional components is very important. This is because they are just faster in terms&lt;br&gt;
of performance as compared to class components. They can make quite the difference when your pages&lt;br&gt;
get component heavy and additionally they look more cleaner in terms of code, hence increasing code&lt;br&gt;
readability.&lt;/p&gt;
&lt;h2&gt;
  
  
  Nitty-gritties
&lt;/h2&gt;

&lt;p&gt;Now with the smaller problems and mistakes;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DHLbYzzv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7l32ip2g8wube9phyqgt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DHLbYzzv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7l32ip2g8wube9phyqgt.png" alt="react-child"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  a. Trying to render empty functions
&lt;/h3&gt;

&lt;p&gt;This mistake wasted hours of my life. Basically, when you try to render a class function like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;renderFields&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;currentCommittee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;poll&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentCommittee&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;currrentCommittee&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;render&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
              &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderFields&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It will return an error if the props haven’t loaded on the first render, meaning that if you are loading props with any kind of delay (for example — from your back-end) the above code, breaks. The quick fix for this is to use the lodash library’s ‘get’ function and make a quick check if the prop has loaded or not, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;render&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentCommittee&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;candidates&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderFields&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  b. Folder structure and Naming Scheme
&lt;/h3&gt;

&lt;p&gt;It’s necessary to have a good folder structure but wasting too much time on it is unnecessary. Simply deciding on the popular choices and then tweaking it a little according to your needs should do the job. The one I finally followed was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/src
  /assets
  /components
  /store
  /style
  /tests
/utils
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;/assets for images, icons etc. /components for all my components, /store for my Redux store and actions, /style for all css files, /tests for all the tests and /utils for some extra utility function files.&lt;/p&gt;

&lt;p&gt;I recommend not to put css files in an independent style folder, instead just drop them in their respective component folder.&lt;/p&gt;

&lt;p&gt;For naming component files and folders, I initially followed the Snake case (hello_world) naming method owing to the redundant python projects I’ve done. The problem in using this naming scheme in React projects is that it doesn’t sit well with the strict Pascal case (HelloWorld) used in naming React components in JSX. Therefore to avoid further confusion and to satisfy my OCD, I switched back all my component files and folders to Pascal case.&lt;/p&gt;

&lt;h3&gt;
  
  
  c. Using Modern React
&lt;/h3&gt;

&lt;p&gt;React is being frequently updated with new features and improvements and this shouldn’t be news as it is currently the most popular JavaScript front-end framework. Although the core React team rarely introduces breaking changes, its imperative to keep up with the newest changes as to have the best performing applications. On just the course of this project, there were over 10 releases of React. At this point in time, what I would call modern React would be the React Context API, React Suspense, React Hooks, React Concurrent etc. Primarily, I felt that I could’ve used the React Context API to replace most of the Redux I’ve used which would have saved a lot of my time.&lt;/p&gt;

&lt;h3&gt;
  
  
  d. Should’ve used Typescript? Maybe.
&lt;/h3&gt;

&lt;p&gt;So, at the time of writing this article, I’ve already learnt typescript and I see it’s importance clearly. There isn’t too much I can explain directly from the project, but here’s what I have to say; Typescript definitely helps a lot especially with larger projects. Yes, it does add a little bit of overhead code but writing that extra code is what you’ll prefer over a stream of errors related to types on which you’ll waste hours debugging.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Are these all the mistakes I made? No, of course not, there were many others, but I don’t think they are worth mentioning, mostly because they were either caused by my stupidity or were unavoidable.&lt;/p&gt;

</description>
      <category>react</category>
      <category>redux</category>
    </item>
  </channel>
</rss>
