Jump To …

The app directory

Return to the main rstat.us index

The app directory contains so much that it gets its own index. Rails uses the MVC architecture so there are directories for the controllers, models, and views. We're also starting to use the Decorator pattern for view logic, so there's a directory of decorators.

The assets directory contains rstat.us' images, uncompressed javascript (and coffeescript), and uncompiled SCSS stylesheets.

assets/

Controllers do things like handling authentication, asking models for data, and providing that data to the appropriate view for the request.

controllers/

The Application Controller defines controller methods that are useful for many of the other controllers, like current_user and set_params_page.

The Auth Controller handles external OAuth requests.

The Feeds Controller shows a Feed, which is important for PubSubHubbub support.

The Salmon Controller helps implement the Salmon Protocol for distribution of non-content-based interaction, such as following someone or replying to someone.

The Searches Controller handles searching.

The Sessions Controller is for logging in and logging out with a username and password.

The Static Controller just goes to the pages on rstat.us that just show information and don't have much interactivity to them.

The Subscriptions Controller is in charge of following and unfollowing.

The Updates Controller is what does the posting and displaying of statuses.

The Users Controller is what gets called when someone signs up for an account, edits their profile, requests a password reset, or resets their password. It also shows an individual user profile as well as a user's following and followers pages.

The Webfinger Controller is what implements the Webfinger protocol, which is a way to figure out user information from an identifier like username@rstat.us.

The decorators directory holds View Model objects that use the draper gem. They help us to generate some of the HTML in an object-oriented way, rather than the more procedural helper functions do. There's a great RailsCast on this subject.

decorators/

This is a decorator that the other decorators inherit from. It contains methods that are applicable to multiple decorators.

The author decorator handles display items for authors of statuses displayed on rstat.us, whether or not they are users on rstat.us. An example is an author's avatar.

The author json decorator handles the json representation of an author. This decorator makes use of some of the author decorator methods.

The time decorator has the logic needed for displaying time attributes and markup with different time formats for updates.

The update json decorator creates the json representation of an update. It calls the author json decorator to embed the author.

The user decorator contains only display items that users who have accounts on rstat.us should see. It also has an associated author decorator.

The classes in models are the business objects of the system. If you are familiar with Rails, you will notice that these objects do not inherit from ActiveRecord::Base like most Rails models do-- instead, they include MongoMapper::Document. This is because rstat.us uses MongoDB (a NoSQL database) and MongoMapper to interface with Rails.

models/

An Author is an entity that produces Updates. Authors may have corresponding rstat.us Users as well, but they may also be users on another OStatus site.

An Authorization is an ability of a User to log in to rstat.us. Currently, the only ways an Authorization is created are if a User logs in to rstat.us with Twitter or a User associates their Twitter account with their existing rstat.us username account.

Feeds are representations of PuSH enabled Atom feeds. Each rstat.us User has a Feed of their updates, and rstat.us keeps a local Feed for each remote Feed that an rstat.us User subscribes to.

Notifier is a class that sends emails to Users such as password reset links or email confirmation links.

The salmon author model is a non-database model. It's a wrapper around an author that is returned from a Salmon response through the OStatus gem. This class makes it easier to treat an author from a Salmon response in the same way as an rstat.us Author without needing to know about OStatus authors' structure.

The salmon interpreter model is another non-database model that does a lot of the work of carrying out the actions that a Salmon notification tells us about.

An Update is an individual status posted either by an rstat.us User or a remote user being followed by someone on rstat.us.

A User is someone who has signed in to rstat.us. All Users have Authors and Feeds associated with them.

This object is responsible for looking up users by webfinger identifier. The Webfinger class is only a business logic object; there are no instances of Webfingers in the database.

Views are templates for rendering HTML. Rstat.us uses haml as its templating language instead of the Rails default of erb. The subdirectories loosely correspond to the controllers' actions, plus common outer HTML in layouts and common repeated HTML in shared.

views/