• Social Networking Patterns - A Book about
  • Repetitive Structures in Social Networks

Social Networking Patterns

Introduction for the book Social Networking Patterns

Social Networking Patterns Introduction 

Welcome to the future. This book has formed through innovation processing and creative ideas, structures and building up new innovative services. 

Each chapter in this book has it's own source code that you can download, run and use for your own innovation processing and programming. The architecture in the source code is defined by the new set of ideas formed from the Microservice and component model way of working as a programmer. So we plan to go beyond Microservices and create a new platform architecture in the end. My history goes with 30 years of working and playing with computer programming languages. The first ones with BASIC GOTO sentences, Visual Basic, C64, Turbo Pascal, running an PcBoard BBS, Javascript in all it's obscure forms, Java etc. I vaguely remember of programming a Game of Life replica when I was around 10 years old with Turbo Pascal. New ideas are the key to this book... and so we continue.

 Patterns in Nature

It all begins with an interesting question: What are patterns? The explanation and exploration has continued for ages of civilizations. Different patterns can be found in nature, paintings, music, buildings, structures, space... the list goes on and on. In this book we are looking for patterns used in technology and more specifically in Social Networks. These patterns are the best practices used in different services and are widely used among these beautiful services. 

Let's get familiar with different kind of patterns found in nature. One of the most interesting patterns is described in the Stephen Wolfram's book A New Kind of Science. Stephen describes cellular automata rules as patterns that are found and based in nature. As you can see in the following illustration. 

Wolfram Alpha's Cellular Automata Rule 362

What do these patterns then mean? What is the ultimate question that these patterns could eventually answer? As we can see the simple rule can produce complex results. This same principle is applied to the John Conway's Game of Life rules. In the Game of Life the simple rules create complex environments. Stephen Hawking has also explained the foundations of life to be applied in a similar manner. With a simple set of rules that interact with it's environment. In nature where are all of these rules hidden? In a similar way we can look for patterns in nature by looking at ourselves, humans. The brain's neurons interact in a similar way as described before. They have a set of rules stored and they interact with the environment. Each neuron is connected to other neurons and holds a set of rules. This application is multidimensional as the cellular automata is two dimensional.


Read full chapter

Content marking pattern summary

  • Talk about Coding

How to build and run a backend API service and connect a mobile client to it

Content marking pattern chapter summary

How to build, run and connect to a hashtag messaging API

In this chapter we described a social networking pattern called content marking pattern and implemented an API and client for it. We will show you in more details later on how to use the API service and how to extend it.

Hashtag messaging server backend API tutorial with Spring Boot + JPA + H2

  • Download Source code for the application and run as Spring Boot application

Hashtag messaging DevOps Docker tutorial running the backend with Docker container

  • Launch the API inside a Docker container

Hashtag messaging mobile application tutorial with JQuery mobile 

  • Create a mobile application client that connects to the API, requests for messages, parses hashtags and adds a new message

Emoji messaging mobile application tutorial with Angular and Ionic

  • Create a mobile application client that uses API to convert words to emojis with Angular and Ionic

API endpoint actions and a beta test endpoint API

Application interface API can be found at http://api.weall.com/v0.1/messages

Get Fresh messages API

HTTP GET /v0.1/messages

Read full chapter

Content Marking Pattern

  • Talk about Coding

How Hashtags work - Hashtags as Content Marking Pattern

Content Marking Pattern

The first one of our Social Networking Patterns includes a pattern to give the text content more depth. It's like highlighting the most important words in a complex content. Your eyes will fix on the words in a glimpse and your brain will understand the meaning faster. 

The Content Marking has become popular through the use of hash tags. The hashtag symbol in front of a word # is used to simply mark the word for indexed content. This marking is called meta tags. Meta tags were widely used in webpage header tags to give search engines a faster glimpse for the keyword in the text content, but when the search engines have developed so have the webpage meta keyword tags been missing. 

So why are hash tags so popular? One reason is that the content is more searchable through hashtags.

This chapter presents a new pattern that's widely used in social networks for browsing, following and searching content. The pattern Content Marking Pattern consists of the following components:

 

Image of Message and Hashtag many to many relation.

The Content Marking Pattern describes the relationship between a message and its corresponding hash tag. One message can have multiple hashtags and one hashtag can be included in multiple messages. 

This relation gives us two lists: a list of Messages with hashtags and a list of hashtags. 

Read full chapter

How to program Hashtags

  • Talk about Coding

Read and understand how to program Hashtags - Hashtags explained

weAll.com Blog - Popular services explained. The first blog entry 3rd January 2016

The use of Hashtags explained

 

The first episode of Popular services explained will today reveal Hashtag's core functionalities and you have a possibility to find out about the functionalities in depth on code level yourself. This blog is created for developers and those who are learning development and wish to know more. 

 

For example many social application's core functionalities are based on the usage of # hashtags. Users can input hashtags inside 140 character messages and those hashtags are used to group and sort messages, search messages and to categorize these messages. Applications also use hashtags in their content organization and searches. By concept Hashtags are database indexed words that are attached to a message. 

 

How hashtags are then built?

 

As a coding example we have the code written in Java. And you can familiarize yourself with the coding examples. 

Read full chapter

How to validate and escape API messages with twitter—text and custom validator

  • Talk about Coding

How to validate API messages with a either a twitter-text Open Source validator, spring-data or a custom validator.

By going on a path of microservice architecture we have more options to choose how we build and bind services together. The initial proposition for this book was to build services as separate microservices that would be bound together by a proxy layer. The proxy layer would be before calling the service layer and it would handle the security, validation and escaping of the characters before calling the services. 

In the current service configuration it is better to have the validation in each of the service components. Here we present how to validate the messaging API messages with

  • twitter-text component that is released as Open Source under Apache 2 License for Java here Twitter-text
  • Spring validation using Java validators for example the @Size validator in the API controller class
  • Custom validation for the Control character validation in the message
  • Spring HtmlUtils to escape the HTML characters before passing the message forward to the hashtag handler
  • The HashtagParserUtil utility class is designed to remove special characters from the hashtag words so that hashtag #f-ree will become #free and #free is used to index the hashtag. Also the escaped strings are removed eg. > < strings

How to validate text message with twitter-text validation

Let's start with the twitter-text validation, it has validation for 140 characters and also data validation. The validation JAR dependency can be added by adding the following configuration to the POM.xml file. You can choose the version accordingly from twitter-text Gitbub tags

<dependency>
<groupId>com.twitter</groupId>
<artifactId>twitter-text</artifactId>
<version>1.14.3</version>
</dependency>

After that you can add the call for the message validation for example

Validator messageTextValidator = new Validator();

if (!messageTextValidator.isValidTweet(message)) {

throw new InputValidationException("Message is not valid");

}

How to validate REST API Reqeuest parameters in Spring Boot with Java Size validator

Read full chapter

Download Messaging application using Hashstag Component Tutorial

  • Talk about Coding

Understand and learn how Messaging using hashtags works as a backend application, download and run the application for your own Social Networking innovation

How to program a Messaging application using Hashtag component working as a Microservice. Download the code in January 2017 for free, run it and learn by doing.

Now that you have a good understanding in how the hashtag component functions we can continue to look it's structure in the coding level. In this chapter you can find a complete downloadable Messaging application that you can use as a component for your own personal learning purposes. The Messaging application works also as a base for any message delivery component. By putting it simply it parses the message, extracts the hashtags and stores both. It also opens up an API to find messages with certain hashtags.

 

The messaging application component is intended to be run inside a secured host machine. The data validation and application security are done before calling the Messaging application interface. So in this application we handle only verified requests. If you need to restrict access and validate the input messages more, do it before calling this internal messaging application API.

 

Learn Java, Spring Framework, Spring Boot, Databases, JSON REST API development

The downloadable project is created with Spring Framework Spring Boot technology and the hashtag component structure is created using Java with Hibernate language (JPA Java Persistent API) and Java Persistence Query Language (JPQL). The Spring Boot application runs Tomcat Servlet container web server with Default settings. And the data is stored in memory inside a H2 Database Engine. When the messaging component application starts it creates a new database in memory. When the service is shut down the data in memory is lost. The persistent database storage instructions will be offered to you in the following chapters.

 

Learn Docker containers and how to build an architecture using microservices

 

In the following chapter we will also introduce Docker container that you can easily use to start a new virtual host server running the messaging application using hashtags. This is the future architecture of Social Networking and in the following chapters we will introduce this new architecture in more depth.

 

How to start programming with Java, what will you need

 
Read full chapter

Running Hashtag Messaging application inside a Docker container

  • Talk about Coding

Learn how to use a Docker container with downloadable tutorial Hashtag Messaging container application

How Docker works with Spring Boot?

In this chapter we introduce a new way of running the Java Spring Boot microservice: Inside a Docker container. You will get to download the source code, compile the service and launch it inside an own virtualized server that runs inside your host machine. Docker is currently our choise of technology for launching the service. Docker is an architecture that can be utilized for running a new virtualized computer instances. This means that it has it's own memory and disk where the service will be installed in. 

Requirements for running an application inside a Docker container

These instructions are tested only on a Windows host machine, they may apply also to Mac and Unix based systems. The commands running the container should apply to all environments.

You have to have the following setup installed on your host machine. 

https://docs.docker.com/engine/installation

Oralce VirtualBox On Window machines. This is required to start a virtual machine.

https://www.virtualbox.org/wiki/Downloads

You will also need the source code project from the end of the article to compile, run and install as a microservice inside the container.

Hashtag Messaging application setup for Docker

Code Build and Run a new Microservice Spring boot application

Read full chapter

How to build a Hashtag Messaging mobile and web application

  • Talk about Coding

Learn how to build a web and mobile Android and iOS hybrid application that uses the Hashtag Messaging API

Mobile application development technology choices 

Good that you made it through the previous chapters. Now it's time to focus on mobile application development and how to leverage the API that was created in the previous chapters. So how are we going to continue with the client development? The mobile application development has multiple variations and choices that need to be made. The thing that matters the most is always the choice between technologies, in this case hybrid application or native application.

To choose a hybrid or native mobile application to develop

The hybrid application is run inside the mobile phone browser with JavaScript. By choosing this way you are able to build an application that runs with a platform that can run JavaScript. The JavaScript makes call through Cordova libraries to the native device libraries, usually either Andoid or iOS. By choosing this way there is more limited way of what you can do with your application. The limitation comes from the browser and what interfaces does the Cordova version offer. And it also affects on the speed of the application, a hybrid application is slower than the native application because the calls are made through JavaScript to the native libraries of the mobile phone.

The native application is run inside the device platform usually on Android or iOS and it connects to the device through it's own native device libraries. This has much more freedom and speeds up the application.

There is a benefit for the hybrid application development and that is the code amount needed to build an application. In this chapter we are going to show you, how to build a hybrid mobile application for Android, iOS and other platforms.

Technology choices to help building applications faster

Ah.. the flaming battlefield of coders: What technology to choose for your application. And of course if you choose a technology that will not last then you are in trouble. So how to minimize the development effort on this? You can choose between various platforms that help in building an application. There are quite many choices that are listed for example here:

https://www.quora.com/What-are-the-top-frameworks-tools-used-for-cross-platform-mobile-app-development

Appery.io application development platform

Our choice for this article is http://appery.io because this platform has an excellent web based IDE, Appery JavaScript libraries and lots of features. We are focusing now only in the features of building a mobile application. 

The Appery platform offers different libraries to connect the Cordova and mobile phone native libraries with the user interface and JavaScript. At the moment in 2017 there is JQuery + JQuery Mobile, Angular v1 + Bootstrap and Ionic framework. For this application we have chosen JQuery + JQuery Mobile but the application is made so that it's quite easy to convert the libraries to a different one.

Connect a mobile application to a API service interface

Read full chapter

How to build Emoji Chat application using AngularJS and Ionic

  • Talk about Coding

AngularJS is widely popular framework for building next generation applications. Let's dive deeper into the world of AngularJS.

Now it's time to look into the popular AngularJS framework (AngularJS version 1.4.3) and how it binds together with Ionic framework (Ionic version 1.2.4). This chapter shows how to leverege the Angular features easily using Appery.io service. You can import the service with the Appery.io trial mode for free.

In the previous chapter we used JQuery to print the UI elements and hashtag messages on the screen, now we use Angular directives to create components on the screen. AngularJS binds also the UI components to the scope model.

This fun little chat application demonstrates also how to use emojis as hashtags. Hope you have a good time in trying out the application.

Create new Angular and Ionic application 

In Appery.io you can create a fresh new application or create an application from a backup that is included in the end of this chapter. The following will show you how to create a new application.  

Image in Appery IDE, Create a new Ionic application using Angular.

Then go to the Appery API Express and create the hashtag messaging API services. You can either import the services or create new services as described in the previous chapter. Note that you have to add limit, offset and convertEmojis URL parameters to the services getFreshMessages and getMessagesByHashtag. These parameters are already added in the API backup file in the end of this chapter.

When you have the API Express services created you can import the api.weall.com services in Appery IDE with Create new / API Express Service. Select all API services.  

Read full chapter

Connecting Pattern

  • Talk about Coding

What are verified connections and how to build and manage them.

Our world is built with connections and they are everywhere. Our economy, ecosystem, values and standards use connections to structure the world around us, you are a result of your connections. In real world you can look at your phone and you will find connections, you can look for connections in friend's list, email box and social applications. You can also look at your education, workplace and social circles to find connections. These connections bring value to the table, you can reach them and ask them questions or state your opinions. This is a social network that is built around your connections. You also have other different kind of connections, to the things that you own, subjects that you are interested in and know about.

This network is information that represents your personal connections. These connections come to life only when you act with the actual person or object through this information.

Networking has different structures for connection building. Two of the mostly used ways to build new connections are verified connections and connections to follow.

As we see in many today's services in 2017 the verified connections means that the connection is built only when the both connection parties have confirmed the connection.

The connections to follow means that the connection endpoint allows other parties to follow his/hers/it's actions. This means that connections you follow are not same as your verified connections.

In a computer network the verified connection also means a connection that has gone through a handshake so that the client and the host have both verified the connection as established. In networking this requires that the communication protocol is identified and accepted in both ways. The verification itself does not guarantee that the both parties can rely on the information that flows between them. It verifies that the parties have accepted the connection and have a relation between each other.

Now we get to an interesting point in the book. We examine connections and how to build and manage them. Connections are relations between entities that enable communication or state changes between two or more entities.

As we discussed earlier in the introduction there are input connections and output connections for a single entity and these are the base for the connecting pattern. We focus in the structure of a single connection entity. With the entity word we mean any programmable object that has an unique identifiable key. The entity is used in many contexts, we have taken it from the Hibernate database terminology.

Read full chapter

How to program verified connetions

  • Talk about Coding

We look at how to code verified connections that can be used in friend lists, phonebook or match list

We will show you in detail how to program a connecting backend API that can be used to build verified connections between connectables meaning objects that are able to connect using their identification names.

Modelling Connecting pattern to a datamodel

The application is modelled around a connection that works in two directions, the initial connection from the owner to the endpoint and as reversed connection from the endpoint to the owner. Both of these connections have a state and an object type for each endpoint.

This chapter uses initial connection term for the connection from the owner to the endpoint. And reversed connection term for the connection from the endpoint to the connection owner. The initiator of the initial connection is the owner who makes the connection request to either accept or decline the connection. The initiator in the reversed connection is the connection endpoint.

Modeling the relation between connectable and connection

Here's an actual example about the terms and how the database tables will look.

 

 

Image of the connectable relation to the connection as relational UML model.

Read full chapter

Download Connecting API

  • Talk about Coding

Download Connecting application microservice component and run it as Docker container with MySQL database

In the end of this chapter you can download the Connecting API Java source code, connect it to MySQL database, build and run it as Docker container.

The Connecting API microservice is intended to work as a Beta Test version as a backend service. You can call the Connecting API inside a secured application server where your application calls the REST service.

The Connecting API works similarly as the Messaging API except that the database client has been changed to use MySQL or MariaDB database server to create the database tables. This means that there is a persistent database where the data is written to the filesystem, opposed to the H2 database that is stored only in memory.

So to run the Connecting API you need the following

  • Install MySQL or MariaDB database

  • Create new database for your application and create application user inside the database

  • Update the Connecting API application.yml properties file with your database application user

Install MySQL or MariaDB database

When you are doing local development one of the best ways is to install a new database with Docker. You can follow these instructions from the official MariaDB site

Read full chapter

Create a contact list application to manage your friends devices or matches

  • Talk about Coding

Create a mobile or web Angular and Ionic app for managing contacts, friends or matches

In this chapter we are focused on connections, especially this connecting pattern is highly popular in many social networking applications and can be used in all kinds of applications and use cases.

Below is the view to the mobile application that you will be creating. To test the application write your name in the first field using @ prefix, like @jack. Write the name you want to connect to to the second input box. Then click on the Right arrow in between the boxes to send a new friend request and create a new connection. Below in the lists click on the name buttons to switch the user's view. This represents that you login as a different test user. Click on the Accept or Decline button or the Trashcan to see what happens.

This application works as an example mobile application to show the features of the Connecting API. The application interface is anonymous, open and unsecured. It is meant to be that way in the beta version 0.1.

Connect API mobile and web Html5 hybrid client application running with Angular.

This version is a Beta Test version and by logging in and aquiring share points you get to read this whole article on how to create this client application.

The client component has the following lists that are fetched from the Connecting API service endpoints.

How to build a list of accepted connections

My friends lists users that you are connected to. Each user has a trashcan icon that you can use to call the discard interface. The user list is fetched by calling the Connecting API interface with the following parameters.

Read full chapter