How I created a basic learning platform with Sinatra — Part I : Project Architecture
Sinatra is a Back End framework that allows its users to create Web Application with Ruby. It is based on Rack a simpler Ruby web application framework . In my journey of becoming a Full-Stack Web Developer I learned Sinatra on Flatiron School online boot camp and as a final project for their Sinatra Section, I created a simple learning platform. My goal with that article is to describe the process I used to create that web app. The web app is available on GitHub.
First, the learning platform we will create allows a super-user to post courses, manage them and the users. Then simple users (that are not admins) are able to read lessons and mark them as passed and reset their progress.
To create the app, of course, the first thing to do is to set up the project architecture and this will be the goal of this article. Just create a folder on your computer (if you would like to use GitHub as a host to your remote repository you should start by creating the repository and clone it to your computer) then name if whatever you want. Then give it this architecture:
Assuming you have bundle installed, typing bundle
will create a Gemfile file that will hold all the external packages (called gems) you need for the project.
Here’s the packages I used to create the project:
Don’t bother about the test group. You don’t really need it to get the project going, except if you will be writing test (which is good practice). Then after putting all of the gems that you need in the Gemfile get back on your terminal and type bundle
. This will actually install the packages and create a Gemfile.lock (different them Gemfile). See the difference between the two.
For the packages, themselves here’s their use: sinatra
just gives you the structure for the web app routes, sessions, cookies, templates, layout etc. active-record
gems helps you to create the database and access it through ruby objects and sinatra-activerecord
extends Sinatra with ActiveRecord helper methods and Rake tasks. sqlite3
is the database engine. Then comes bcrypt
that helps securing passwords, rack-flash3
that creates flash messages for the user in the controller to display them later. rerun
will helps restart your server automatically when there’s a change. Just type rerun rackup config.ru
in your terminal.
No that we’re done, the next step is to design the database! (But that will be another article) :D