Skip to content

Overview of platform

vaibhav-sinha edited this page Jul 24, 2016 · 1 revision

Philosophy

  1. Backend is for data only, not UI.
  2. Technologies are selected based on need, simplicity and resource availability.
  3. Frontend apps decide what features they want to use.
  4. Moving data and code from pendrive to Raspberry Pi and back should be seamless.
  5. Creating distribution for pendrive might not be seamless (until some time anyways :)

The servers

There are two implementations of the server available, both having the same codebase but functionality is changed based on the mode of operation

  1. Central: The central server, with it's MySQL database, provides the management interface and central storage of all of user's and application's data. This is where new modules and content can be added, user data can be migrated and a distribution can be generated for the pendrive. This server is also useful for hosting the APIs on web so that same applications deployed on Raspberry Pi can be made available to the world on internet too.

  2. Pi: The pi server is the one that will run on Raspberry Pi. It uses Sqlite3 as an embedded database since this server will run in a resource constrained environment.

The directory structure

On the Central server, the Pi server and on the Pendrive, there will always be a defined directory structure as follows

liberry/
├── code
│   ├── central-admin-app
│   ├── pi-admin-app
│   └── platform
├── content
└── output
    ├── central
    └── pi

The liberry directory may be named anything. This is the directory which will be referred as LIBERRY_ROOT.

The code directory will contain all the repositories from Github.

The content directory will have all the videos, files, etc. There is no structure enforced within this directory. Each entry in the Content table of the database will point to the path in this directory. This directory will be referred as CONTENT_ROOT.

Database

All the information about the categories, modules, content, etc is stored in the database. The database is populate through the central admin app. The data is then dumped into the pendrive through which it is imported into the Sqlite3 database running on the Pi. The tables migrated are Category, Module, Content, Playlist, PlaylistContent.

The actual content, though, is never stored within the database, and is instead served from the filesystem. The content is also moved from the Central server to the Pi through the Pendrive.

There is a reverse migration of database entries that happens from Pi to Central through Pendrive as well. That is needed because the user and user activity information is captured on the Pi and that needs to be made available on the Central server so that any meaningful insights can be gained from them. The tables migrated are User and Activity.

Creating a distribution for the Pendrive

  1. Log into the central admin app.
  2. If there are new categories, modules or playlists to be added, then create entries for them.
  3. If there is new content available, upload it on the server where it is available for download by all. Place the content somewhere within the CONTENT_ROOT directory on the Central server.
  4. Create new entries for the uploaded content through the admin app. The path field must be relative to the LIBERRY_ROOT. Hence paths would look like content/primary/khan-academy/maths/video1.mp4.
  5. Go to the Sync tab on the admin app and click on Create Pendrive Content. Now if you go to the LIBERRY_ROOT/output/central directory, you should see .sql files for each table.
  6. Ensure that the code in LIBERRY_ROOT/code directory is up-to-date. Go to each directory and run git pull and npm install.
  7. Now download the entire LIBERRY_ROOT directory from the server to your pendrive. This can be done using scp command or any other tool that you might prefer.

Uploading the content to Raspberry Pi

  1. Plug in your pendrive into Raspberry Pi
  2. Log in into the pi admin app
  3. Select your pendrive from the directory tree displayed
  4. Click on Sync button

Clicking on Sync button does all of the following:

  1. Copies everything in code and content directories on Pendrive to Pi
  2. Drops all tables from the database except User and Activity.
  3. Imports all data from sql files present in output/central directory.
  4. Dumps User and Activity tables into sql files in output/pi directory on Pendrive.
  5. Restarts the server so that any code changes that might have happened get picked.

Syncing the database to Central

Once the pendrive is back from the field, the data in sql files present in output/pi directory need to be imported into central database.

  1. Log into the central admin app.
  2. Connect your pendrive to your computer.
  3. Go to the Sync tab.
  4. Click on Select SQL File button and upload output/pi/user.sql file.
  5. Repeat the same for output/pi/activity.sql file.

Pending items

  1. Enable updation on nginx config on the Pi server.
  2. Enable reconfiguration of device.
  3. Enable auto-startup of server in event of power failure.