Skip to content

brandongregoryscott/arthistory

Repository files navigation

arthistory

code style: prettier TypeScript Commitizen friendly

Web application for viewing historical Spotify artist data.

Quick Start

The app can be accessed at arthistory.brandonscott.me.

About

The Spotify API provides the current follower count and a popularity score for an artist, but does not provide any historical data. I always wanted to track how my favorite artists were growing over time, so maybe you'll find this app useful too.

How it works

Artist data is synced and pushed to a SQLite database stored on S3 with scripts from the scripts package in the repo. This database is pulled down and bundled with the API server on build.

Not every artist on Spotify is tracked, but new artists can be requested through the web UI.

Development

Database

The API requires a SQLite database to query. A small sample database is included in the repo: _spotify-data.db.

Spotify API keys

The /v1/artists and /v1/artists/search endpoints in the API hit the Spotify API, so you'll need API keys to run them. See the Spotify API documentation on signing up for developer access.

Setup

# Edit the environment file to add your Spotify API keys and path to the SQLite database file
cp apps/api/.env.example apps/api/.env

# The environment file for the web app probably doesn't need to be changed.
cp apps/web/.env.example apps/web/.env

# Install packages (ensure you are using Node v20+, run `nvm use` if you have `nvm` installed.)
npm i

# Run a build (This ensures sqlite is built and placed in the right location in the monorepo)
npm run build

# Run the development servers for the web app and API
npm run dev

# Now, open http://localhost:3000 in your browser to view the app.

Issues

If you find a bug, feel free to open up an issue and try to describe it in detail with reproduction steps if possible.

If you would like to see a feature, and it isn't already documented, feel free to open up a new issue and describe the desired behavior.

Debugging and server maintenance

Install the service
sudo systemctl enable /home/brandon/arthistory/arthistory-cron-service.service
Start the service
sudo systemctl start arthistory-cron-service.service
Show the service status (active, memory, cpu)
sudo systemctl status arthistory-cron-service.service
List service logs with service-level start/stop/restart events, and stdout/stderr
sudo journalctl --catalog --unit arthistory-cron-service.service
List service stdout/stderr logs
sudo journalctl --no-pager --unit arthistory-cron-service.service
List last 1000 lines from the logs and follows the logs

See manpage: journalctl > PAGER CONTROL OPTIONS

sudo journalctl --pager-end --follow --unit arthistory-cron-service.service
Restart the service daemon & service
sudo systemctl daemon-reload && sudo systemctl restart arthistory-cron-service.service
Updating the production database

Ensure you're using the correct node version

nvm use

Download all of the working snapshots from the spotify-data bucket

npm run download-dbs

Merge all of the working snapshots into one file

npm run merge-dbs

Stop the NodeJS process manager running the API instances - if the database file is replaced while it is running, it will crash loop

pm2 stop arthistory-api

Move the merged database file to the production filename

mv merged-spotify-data.db _spotify-data.db

Start the NodeJS process manager running the API instances

pm2 start arthistory-api
Updating API key permissions to include additional buckets (403 Access Denied error when trying to upload objects)

About

Web application for viewing historical Spotify artist data.

Topics

Resources

License

Stars

Watchers

Forks