Skip to content
Axel Penin edited this page Mar 20, 2015 · 9 revisions

What ?

This section describes how AIOMedia has been built and which technologies/standards has been used. You will also learn why the application has been designed this way, and if needed, the pros and cons this architecture.

Who ?

For developers who wants to :

  • learn more about how it works internally.
  • develop features for their instance of AIOMedia
  • integrate AIOMedia to their existing Media/Home Improvement system
  • replace some parts of the application by their own implementation (e.g. replace the server or the user interface)
  • contribute to the core of AIOMedia

Introduction

Technologies

What are the features we need

How to do this ?

Project architecture

Basically, this application is an aggregate of two applications : the Server and the Client.

Whole file structure

|- bin/
|  `- www
|- client/
|  |- public/
|  |  |- css/
|  |  |- fonts/
|  |  |- images/
|  |  |- js/
|  |  |- less/
|  |  `- favicon.ico
|  |- src/
|  `- index.html
`- server/

Server Application

It is a RESTful API provided by Node.js.

Files and directories of the Server are :

  • bin/ contains the application commands
    • www start command of the Server
  • server/ contains the Server application

Client Application

It is an HTML/AngularJS user interface completely independent from the Server. It will call the Server API with AJAX to retrieve JSON data. As it's just HTML & JavaScript, it doesn't require any server side process to run.

Files and directories of the Client are :

  • client/ contains the Client application
    • public/ contains all public assets (css, images, js, less, favicon, etc.)
    • src/ contains AngularJs source files
    • index.html entry point of the Client

Internationalization & Localization

Why ?

Server API

Response

The API implements a Response object which is returned to the client in JSON format.

A response MUST contain at least :

  • a status code : a specific status code for the application mapped to an HTTP status code (see list below)
  • a message : a human-readable message that give additional information about what has been occurred on server

It can also contains additional fields (depending on Response type), like data (e.g. a collection, a specific item) or metadata (e.g. pagination, number of results). See Response types for more information about what is contained in each Response type.

Application status codes list

Application status are mapped on the HTTP status codes, and have some others for those who lack (which are also mapped to existing HTTP codes). This is the exhaustive list of built in status and their respective HTTP status and their default message.

Status Key Status Code HTTP Status Code Message Description
OK 200 200 OK
NO_RESULT 200 200 No result
UPDATED 200 200 Updated
CREATED 201 201 Created
ACCEPTED 202 202 Accepted
BAD_REQUEST 400 400 Bad Request
INVALID 400 400 Invalid Data
NOT_FOUND 404 404 Not found
UNAUTHORIZED 401 401 Unauthorized
FORBIDDEN 403 403 Forbidden
SERVER_ERROR 500 500 Internal Server Error
UNAVAILABLE 503 503 Service Unavailable

Response types

AIOMedia comes with a pre-built set of Response types.

Response types are shorthands to create the correct Response Object (with the correct status and message) for the most common responses you need. This permits a normalization of the API Responses and avoid you to rack your brains to know which status use for your response.

All Response constructors accept a custom message, if you want to provide more detailed information about what occurred on server (e.g. User Created instead of Created).

Below you'll find the list of Response types and when to use it.

Default OK Responses

new Response.Default([message]);
new Response.Accepted([message]);

Data Responses

new Response.Data.Item(data, [message]);
new Response.Data.Collection(data, [message]);
new Response.Data.Created(data, [message]);
new Response.Data.Updated(data, [message]);
new Response.Data.NoResult([message]);
new Response.Data.NotFound([message]);
new Response.Data.Invalid(data, errors, [message]);

Error Response

new Response.Error.NotFound([message]);
new Response.Error.Unauthorized([message]);
new Response.Error.Forbidden([message]);
new Response.Error.Internal([message]);
new Response.Error.Unavailable([message]);

User Interface