Skip to content

Project Structure

Joe Schmitt edited this page Jun 28, 2017 · 10 revisions

Libby is a NodeJS function written to be deployed as an Amazon Lambda function in response to events from the Alexa Skills Kit SDK.

Source Files

The project source files are contained in the src/ directory. All source files are written in ES6/ES2017, and compiled down to code that can run on the version of NodeJS on Lambda using Babel. Babel outputs the compiled js files to the dist/ directory, and it is this directory that is actually pointed to whenever the application runs.

Babel will automatically compile the current source whenever you run npm install, as well as whenever you run unit tests using npm test, whenever you test your changes using npm start, as well as when you package the app using npm run package. If you'd like to manually run this compilation step outside of these scenarios, you can do so by running the build script using npm run build.

API

The API directory contains the necessary modules needed for communicating with the various PVR providers.

Glossary of Terms

  • Provider: A provider is the PVR service being used to track movies and TV shows, for example Sonarr or Couch Potato.
  • Provider Type: Movies or TV Shows. A provider type is linked to a single provider, so that the application can request the API for "movies" and it'll get the correct PVR provider.

API Modules

  • config.js: This module is responsible for reading the configuration settings set in the config JSON files. It also handles inheriting server settings in all of the providers. It exports a function that simply returns a JSON object with the config needed to initialize an API instance based on what provider
  • getProvider.js: This module is responsible for returning the correct instance of an API provider given a provider type. You give it a type such as "movies", and it'll return the correct API service used to load movies from your PVR server based on the config file.
  • index.js This lists the currently active API providers that are available. If the API isn't listed here, it's not supported. The keys here must match the value set in the config, so if you're trying to add a new PVR provider, keep that in mind.

The rest of the files in this directory are the individual API provider modules. They all conform to the same Interface, meaning they all have the exact same list of functions and return the exact same structured data. This allows the rest of the code to not care if it's calling "search" on Couch Potato or Radarr, it just cares that it gets back an Object with a title. All API provider modules must expose the following functions:

  1. default -- The default function returns an instance of the API provider. This is mostly used internally.
  2. list -- The list function simply lists out the media currently available on the PVR server. It takes an optional parameter which allows you to filter the list by title.
  3. search -- The search function searches for new media not currently on the PVR server. It takes a query parameter.
  4. add -- The add function adds new media to the PVR server.

Handlers

Responses

Models

The models/ contains files used to generate the Interaction Models the ASK uses to interpret what you've asked Alexa to do. The primary way this works is through the use of sample utterances, which are phrases you provide to Alexa that shows how you should parse what the user is asking for.

Alexa works best by giving it as many different phrases and wordings as possible. Since it can get wholly unmanageable to hand-write a bunch of variations of the same phrases, we instead use the alexa-utterances project to take a model template and use it to generate a huge list of sample utterances. The template model used to generate each slot can be found in models/schemas/. Contributions to these models is highly encouraged, as the more variation we have the more accurate Alexa will be.

Unit Tests