Skip to content

Playground project implementing a music library RESTful API

Notifications You must be signed in to change notification settings

arisgk/music-library-api

Repository files navigation

Music Library Backend

Playground project implementing a music library backend (RESTful API + Socket.io server). Built with Node.js.

The API currently serves a single route, /songs, which returns the list of all available songs in the library.

Songs are uploaded to Amazon S3 and served using Amazon CloudFront.

Quick Start

Prerequisites

Define an .env file at the root directory of the project containing all the environment variables needed. You can find the keys needed for the env vars key-value pairs in the configuration file.

Using Docker

You can use Docker to start the app locally. The Dockerfile and the docker-compose.yml are already provided for you. Navigate to project root folder and run the following command to start the server:

docker-compose up

Using npm

You will need to download and install Node.js and npm in order to use this method. Navigate to project root folder and run the following commands to start the server:

npm install
npm start

Testing

Navigate to project root folder and run:

npm test

Architectural Decisions

The app is designed to use a layered architecture. The architecture is heavily influenced by the Clean Architecture. It aims to separate concerns and make the app easier to test and maintain. This also makes it easier to replace a routing framework or a data store, as the core business rules are independent of these layers implementation. Specifically, the following simple division is applied in the app structure:

  • domain folder contains modules defining the core entities (models) and business rules (services) of the app. They are the least likely to change when something external (e.g database, routing) changes and thus do not depend on external components. In our use case, this layer will not change if songs are fetched from an external API instead of a JSON file. This increases extensibility and maintainability.

  • router folder contains modules concerned with HTTP routing (routes, HTTP specifics like requests, responses, headers, params validation etc). Routing is implemented using Express.js but we can easily swap it with another framework.

  • websockets folder contains modules concerned with WebSockets interface. Socket.IO is used to handle WebSockets communication.

  • data folder contains modules (repositories) concerned with data fetching and posting tasks. There are examples for fetching data from both a JSON file and an external service (Amazon S3).

Routing

Express web framework is used to handle routing.

WebSockets

Socket.IO is used to handle WebSockets communication.

Code Style

Prettier and ESLint with Airbnb style guide.

Possible Extensions

  • Complete the songs CRUD and add artists and album support
  • Add users and access management / authentication mechanism. Song URLs can be signed in order to only be available to authorized users.
  • Document the API using Swagger
  • Add continuous integration and deployment (e.g deploy using CircleCI)