Build Your Own Social Network with Diaspora*: An IntroductionBy Ahmed Refaat Tawfik
Diaspora can be viewed from two different perspectives: first, from an end user’s, who could find Diaspora much similar to other social networks like Google+, Facebook, or even Twitter. I used to think that Diaspora was different, having some unique features until Google+ came and included many of these features.
The other angle sees Diaspora is from a developer’s perspective, as a Social Networking Engine. It is possible to build a social network with sophisticated features and a very simple and elegant UI in few weeks, or even days, depending on your experience.
Diaspora is open source and distributed which means you could connect your deployed instance with other deployed instances and make a huge social network fully connected, all while maintaining your data on your servers. Also, it’s written in Ruby on Rails and the UI uses Backbone.
With the introduction out of the day, let’s see Diaspora in action. First, you need to install some dependencies:
Ruby: you can find all you need in this tutorial Installing Ruby with RVM on Ubuntu
Rails: these two tutorials are helpful for installing rails Rails Intro, Deep Dive: Installing Rails, Part One, and this one Loccasions: Installing Rails Part 2
MySQL: at least for development purposes, you will need MySQL so this commands will install it for you and to run MySQL server
Git: you need git to clone the diaspora repository, despite that you can download it from the repository page but you will need git anyway, so you have to install it, and if want to setup git to work with your github account, you should read this also from github help pages for linux
Diaspora: now you need to get diaspora source to work with, so we going to clone it from the project git repository and switch to the diaspora directory
You almost now have a working environment to run Diaspora, but we have just a few steps before running the server.
Run the following command from the root directory of diaspora project itself. For example, if your project was in your home directory, the root directory of the project will be at ~/diaspora/
Now, go to the
config/ folder and remove the
[.example] from the following files:
database.yml, you need to configure MySQL server entries to match your environment.
Last commands to start the project are
Open your broser and go to
[ localhost:3000 ] and follow the directions to create a user. If you want this new user to have admin privileges, you can edit that in
config/application.yml by adding the username to the
admins section. You can actually do a lot of configuration in this file, which we will discuss in the next tutorial.
The typical Disapora code directory structure is below. Take a moment to familiarize yourself with the code base.
Let’s start our familiarization with the Diaspora object model. You can find the source for these objects in the
A User object represents the private information and capabilities of a user on that server. The user object is able to friend people, post updates, and update his profile. A User has a Person.
A Person is a User viewed from the outside. When a user friends another user, they friend that user’s Person object. Person objects are replicated across servers, and they are where a User’s public key lives. A Person has many Posts. A Person has a Profile.
This contains information about the person. Currently, a profile looks the same to anyone looking at it.
A Contact is a “proxy” object for every person a User is friends with, means that to initialize any relationship with any other user you need a contact object to make the link.
This contains a list of people and posts which are for that aspect. Aspects are private to Users, and we might embed the Aspect documents in the User document.
A Post belongs to a Person. This is a parent class for different types of posts, it contains comment ids and a few other attributes common to all Posts.
A comment belongs to a Post
Here is what the code base for our Diaspora* app looks like:
Okay, what’s next?
We only covered the very basic of Diaspora. There are many more pieces to the puzzle, like Controllers, Views and the Backbone part of the UI which you can find in the