Build Your Own Social Network with Diaspora*: An Introduction

By Ahmed Refaat Tawfik

What’s Diaspora*?

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.

Why Diaspora?

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.example
  • application.yml.example

In 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.

Diaspora Codebase

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 app/models folder.


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

Directory Structure

Here is what the code base for our Diaspora* app looks like:

├── app
│   ├── controllers
│   │   ├── activity_streams
│   │   │   └── photos_controller.rb
│   │   ├── admins_controller.rb
│   │   ├── apis_controller.rb
│   │   ├────────────
│   │   ├── people_controller.rb
│   │   ├── photos_controller.rb
│   ├── helpers
│   │   ├── application_helper.rb
│   │   ├── aspect_global_helper.rb
│   │   ├────────────
│   │   ├── error_messages_helper.rb
│   │   ├── getting_started_helper.rb
│   ├── mailers
│   │   ├── diaspora_devise_mailer.rb
│   │   ├── notification_mailers
│   │   │   ├── also_commented.rb
│   │   │   ├── base.rb
│   │   ├────────────
│   │   │   ├── reshared.rb
│   │   │   └── started_sharing.rb
│   │   └── notifier.rb
│   ├── models
│   │   ├── account_deleter.rb
│   │   ├── account_deletion.rb
│   │   ├── tag_following.rb
│   │   ├────────────
│   │   ├── user_preference.rb
│   │   └── user.rb
│   ├── presenters
│   │   └── user_presenter.rb
│   ├── uploaders
│   │   ├── processed_image.rb
│   │   └── unprocessed_image.rb
│   └── views
│       ├── admins
│       │   ├── _admin_bar.haml
│       │   ├── correlations.haml
│       │   ├── stats.html.haml
│       │   ├── user_search.html.haml
│       │   └── weekly_user_stats.haml
│       ├────────────
│       ├── apps
│       │   └── show.html.haml
│       └── users
│           ├── edit.html.haml
│           ├── getting_started.haml
│           ├── logged_out.haml
│           └── privacy_settings.html.haml
├── Capfile
├── config
├── db
├── lib
├── log
├── public
│   ├── images
│   ├── javascripts
│   │   ├── app
│   │   │   ├── collections
│   │   │   ├── helpers
│   │   │   ├── models
│   │   │   ├── templates
│   │   │   └── views
│   │   ├── helpers
│   │   ├── pages
│   │   ├── vendor
│   │   └── widgets
│   ├── stylesheets
│   └── uploads
├── script
├── spec
└── tmp

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 public/javascript/app. It will your mission, should you choose to accept it, to take a look over them until the next tutorial, where we will customize Diaspora to build our social network with some specific features.

  • Karim Husseiny

    Great one, thank you for writing this great Article.

  • Wazery

    Great and helpful article, can’t wait for the next one :)

  • Agent.K

    great idea :)

  • Shane

    This is great. I have been looking for something like this that used Ruby/Rails for a while.

    I’m really looking forward to part two of the series.

    • Ahmd Refat

      Thank you, I’m working on the next one and I hope to be helpful.

  • Mark

    Hello all!

    I did not have any issues until this part:

    mark@meldola:~/diaspora$ bundle install –without test heroku
    ERROR: Gem bundler is not installed, run `gem install bundler` first.
    mark@meldola:~/diaspora$ gem install bundler
    ERROR: Error installing bundler:
    bundler requires RubyGems version >= 1.3.6

    Anybody got any ideas? Thank a lot if you can help ;-)


    • Glenn Goodrich

      Mark, do you know what version of ruby gems you’re running?


      gem -v

      at the command line. If it’s not 1.3.6 (or if gem isn’t a recognized command) you need to update rubygems.

      hope this helps…

  • Mel Riffe

    Ahmd, thanks for the article. Like Shane mentioned, I can’t wait for the 2d article. Diaspora* looks really nice and opens a ton of possibilities.


    • Ahmd Refat

      Diaspora is a really promising project and will make a great Impact sooner or later

  • Mark

    Thanks a lot for trying to help me out. The problem seems to be coming from path variables I think. I’m not a Linux expert so the solution could be trivial but unknown to me. Here is the message I get when trying to change to the diaspora directory before running the: bundle install –without test heroku command listed in the article.

    mark@meldola:~$ cd diaspora
    Using /home/mark/.rvm/gems/ruby-1.9.2-p290 with gemset diaspora
    Removing old Rubygems files…
    Installing rubygems-1.8.17 for ruby-1.9.2-p290@diaspora …
    Error running ‘GEM_PATH=”/home/mark/.rvm/gems/ruby-1.9.2-p290@diaspora:/home/mark/.rvm/gems/ruby-1.9.2-p290@global:/home/mark/.rvm/gems/ruby-1.9.2-p290@global” GEM_HOME=”/home/mark/.rvm/gems/ruby-1.9.2-p290@diaspora” “/home/mark/.rvm/rubies/ruby-1.9.2-p290/bin/ruby” “/home/mark/.rvm/src/rubygems-1.8.17/setup.rb”‘, please read /home/mark/.rvm/log/ruby-1.9.2-p290@diaspora/rubygems.install.log
    Installation of rubygems did not complete successfully.
    mark@meldola:~/diaspora$ bundle install –without test heroku
    ERROR: Gem bundler is not installed, run `gem install bundler` first.
    mark@meldola:~/diaspora$ gem -v
    mark@meldola:~/diaspora$ gem install bundler
    Successfully installed bundler-1.1.2
    1 gem installed
    Installing ri documentation for bundler-1.1.2…
    Installing RDoc documentation for bundler-1.1.2…
    mark@meldola:~/diaspora$ bundle install –without test heroku
    ERROR: Gem bundler is not installed, run `gem install bundler` first.

    I can’t figure this one…damn


  • Ahmd Refat

    Mark, I think you should try to remove the [.rvmrc] file from the diaspora folder and try again

    • Mark

      Thanks a lot (I almost said thanks a bundle) and yes it worked. Well, for the most part it worked. I removed the .rvmrc file from the diaspora folder and tried the:
      bundle install –without test heroku command again. It was sailing along installing until it reached typhoeus (0.3.3) where it ailed; I received the message ERROR: Failed to build gem native extension. I won’t paste in everything here but apparently extconf.rb failed. I will try to figure this out, but I’m playing a bit of catch up here…not experienced with the Ruby world. Anyway, thanks for helping – I owe you one!

  • Julian K

    Is it true that because of the license Diaspora uses, I’ll have to publish any changes/tweaks I make for the community?

    • Wazery

      Diaspora is under AGPL, so if you make changes to it and you released your project with these changes you will need to publish the Diaspora changes you made, and obviously if you don’t released your project you can keep the changes :)

  • Jason

    I’m definitely looking forward to more tutorials on Diaspora.

  • Andy R.

    Great! Will definitely dig into Diaspora until the next article comes up!

  • chembian

    Is it possible to build a pheed type social network using diaspora?

Get the latest in Ruby, once a week, for free.