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.
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.
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
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
Navigate to project root folder and run:
npm test
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).
Express web framework is used to handle routing.
Socket.IO is used to handle WebSockets communication.
Prettier and ESLint with Airbnb style guide.