Skip to content

Social media platform for sharing songs with friends, family, or strangers

Notifications You must be signed in to change notification settings

SongSwap-social/songswap-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

22 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation


songswap-app

Developed with the software and tools listed below

Docker Python Flask
postgresql Spotipy
apacheecharts bulma
Amazon RDS Amazon S3 Amazon EC2 Amazon CloudWatch


๐Ÿ“’ Table of Contents


๐Ÿ“ Overview

This repository is a Flask web application that provides users with the ability to register using their Spotify account, access their listening history, and view insights into their top tracks, artists, and genres.

Every hour, the user's listening history data is retrieved from Spotify from the songswap-airflow project and stored in an AWS-backed PostgreSQL database. Insights are acquired from the songswap-insights API.

The project's core functionalities include:

  • user registration using OAuth authentication with Spotify
  • periodic retrieving, storing and transforming user listening history
  • interactive charts and graphs for personalized insights per track, artist, user, or time period (last week/month/etc.)

This application aims to enhance the user's music discovery experience by analyzing their listening patterns and providing tailored insights. In the future, the project will allow users to create user groups and share their insights with other users, or even discover other users with similar listening patterns.

The goal is to intertwine Spotify Wrapped and Myspace to provide an experience for music discovery, where users can share their music tastes and discover new music through their friends.


โš™๏ธ Features

Feature Description
โš™๏ธ Architecture The codebase follows a typical Flask application architecture, with separate blueprints for different functionalities. It uses SQLAlchemy for database operations and Alembic for database migrations. The application can be deployed in a container using Docker.
๐Ÿ“– Documentation The codebase includes inline code comments in most files, providing explanations and details about the code. Some files have additional README files explaining their purpose and usage. However, more comprehensive documentation, like a detailed architectural overview or API documentation, could be beneficial.
๐Ÿ”— Dependencies The codebase has dependencies on Flask, SQLAlchemy, Alembic, spotipy, Pyecharts, and authlib libraries. Flask and SQLAlchemy handle the core components of the web application and database operations. Alembic is used for database migrations, spotipy for Spotify authentication, Pyecharts for visualizations, and authlib for OAuth integration.
๐Ÿงฉ Modularity The codebase is modular, with separate blueprints for different functionalities like authentication, insights, health checks, and history. Models, forms, routes, and helper functions are segregated into their respective blueprints, making the codebase more maintainable and extensible.
โœ”๏ธ Testing The codebase does not have front-end tests at the moment. The majority of the testing codebase focuses on testing the backend API and Airflow orchestration workflows.
โšก๏ธ Performance The code's performance benefits from the performance capabilities of the underlying WSGI server (Gunicorn) and Flask's lightweight nature. Performance improvements are achieved by caching strategies, optimizing database queries, and implementing load balancing techniques (on AWS's ElasticBeanstalk) for increased scalability.
๐Ÿ” Security The codebase incorporates the authentication mechanism using OAuth integration with Spotify's API, ensuring secure and authorized access to user data. Moreover, Alembic is used for database migrations, which assists in maintaining the integrity and security of the application's database schema and data.
๐Ÿ”Œ Integrations The codebase integrates with various external systems and services. It uses songswap-insights for user-specific insights data, authlib for OAuth integration with Spotify API, spotipy library for handling Spotify authentication flow, and Pyecharts for data visualization. These integrations enable seamless interaction with third-party systems and enrich the functionality.

๐Ÿ“‚ Project Structure

repo
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ app
โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”œโ”€โ”€ blueprints
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ auth
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ forms.py
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ models.py
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ providers.py
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ routes.py
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ health
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ routes.py
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ history
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ models.py
โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ routes.py
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ insights
โ”‚ย ย  โ”‚ย ย      โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”‚ย ย      โ”œโ”€โ”€ forms.py
โ”‚ย ย  โ”‚ย ย      โ”œโ”€โ”€ helpers.py
โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ routes.py
โ”‚ย ย  โ”œโ”€โ”€ database.py
โ”‚ย ย  โ”œโ”€โ”€ static
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ styles.css
โ”‚ย ย  โ””โ”€โ”€ templates
โ”‚ย ย      โ”œโ”€โ”€ auth_home.html
โ”‚ย ย      โ”œโ”€โ”€ base.html
โ”‚ย ย      โ”œโ”€โ”€ insights.html
โ”‚ย ย      โ”œโ”€โ”€ insights_global.html
โ”‚ย ย      โ”œโ”€โ”€ navbar.html
โ”‚ย ย      โ”œโ”€โ”€ register.html
โ”‚ย ย      โ””โ”€โ”€ unauth_home.html
โ”œโ”€โ”€ buildspec.yml
โ”œโ”€โ”€ config.py
โ”œโ”€โ”€ entrypoint.sh
โ”œโ”€โ”€ migrations
โ”‚ย ย  โ”œโ”€โ”€ README
โ”‚ย ย  โ”œโ”€โ”€ alembic.ini
โ”‚ย ย  โ”œโ”€โ”€ env.py
โ”‚ย ย  โ”œโ”€โ”€ script.py.mako
โ”‚ย ย  โ””โ”€โ”€ versions
โ”‚ย ย      โ”œโ”€โ”€ 35e0533671ef_create_trackpreviews_table.py
โ”‚ย ย      โ”œโ”€โ”€ 36d8ca5b553b_standardize_table_names_to_pascalcase_.py
โ”‚ย ย      โ”œโ”€โ”€ 4ba4facc166c_initial_db_migration.py
โ”‚ย ย      โ”œโ”€โ”€ 86cecbe1fd2b_create_new_image_popularity_genre_.py
โ”‚ย ย      โ”œโ”€โ”€ bdd4bb2eaf3c_add_history_track_artist_tables.py
โ”‚ย ย      โ”œโ”€โ”€ e381845baba9_remove_redundant_spotify_id.py
โ”‚ย ย      โ””โ”€โ”€ manual_add_cascade_delete_update.py
โ”œโ”€โ”€ render.html
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ run.py
โ””โ”€โ”€ scripts
    โ”œโ”€โ”€ flush_db.sh
    โ””โ”€โ”€ init_db.sh

11 directories, 46 files

๐Ÿงฉ Modules

Root
File Summary
run.py Initializes a Flask application using the "create_app" function from the "app" module. It then starts the application using the "run" method with the value of the "DEBUG" configuration as the debug mode.
config.py Loads environment variables, such as DEBUG, SECRET_KEY, and database connection URI, from a .env file. It also sets the API URL based on whether the application is running locally or in a Docker container.
Dockerfile This Dockerfile sets up a Python Flask application in a container. It installs dependencies, sets environment variables, performs database migrations, and runs the app using Gunicorn on port 80.
entrypoint.sh Upgrades, or initializes, the database using flask db upgrade and then executes the provided command.
Migrations
File Summary
script.py.mako Template for database migrations with Alembic. It generates a revision ID along with any revisions and dependencies. The code includes an upgrade() function for applying changes and a downgrade() function for reverting changes. The imports and revisions are parameterized for customization. It's a flexible and maintainable approach to managing database schema updates.
env.py This code snippet provides functionalities for running migrations using Alembic in a Flask application. It includes methods for running migrations offline and online, configuring the context, logging, and obtaining the engine URL.
README.md This code snippet provides minimal information about the database migrations, such as how they are performed.
App
File Summary
database.py The code snippet initializes a SQLAlchemy object called db for database operations in a Flask application.
Insights
File Summary
helpers.py Provides helper functions for retrieving and formatting data from the songswap-insights API. Functions are included to retrieve the top tracks, top artists, and top genres from the API. The functions execute GET requests to the API, handle the response, and return the requested data.
routes.py Two routes: "/insights" and "/insights_global". The "/insights" route retrieves the user's top tracks from the songswap-insights API, converts the track duration to minutes and seconds, and renders the data using the "insights.html" template. The "/insights_global" route retrieves various statistics from the songswap-insights API, including total and distinct listens, total listen time, top tracks, and top artists. This data is then rendered using the "insights_global.html" template.
Auth
File Summary
models.py Defines two database models: "Users" and "SpotifyTokens". Users model has columns for user details, a relationship with SpotifyTokens, and a relationship with History. SpotifyTokens model has columns for access and refresh tokens. The code also includes methods for Flask-Login integration and administrative interface. Overall, the code sets up the database schema for storing user and Spotify token information.
forms.py This code snippet defines a FlaskForm called RegistrationForm for user registration. It includes fields for username and email, with validation for required input and unique username/email.
providers.py Defines an abstract class for a music authentication provider, and implements a concrete class for Spotify authentication. It integrates with the spotipy library to handle Spotify authentication flow and provides methods for obtaining authorization URL, access token and user information.
routes.py This code snippet includes Flask routes and functions for Spotify OAuth authentication, user registration, and user login/logout functionalities for a web application. It uses the authlib library for OAuth integration and interacts with the Spotify API to obtain user information and access tokens. The code handles user creation if they don't exist and provides routes for authenticated and unauthorized users.
Health
File Summary
routes.py The provided code creates a route "/health" in a Flask Blueprint that performs a health check on the app, checking its critical functions. It returns a 200 status code and "OK" if everything is functioning properly.
History
File Summary
models.py This code snippet defines a set of SQLAlchemy models that represent different entities in a database. These entities include history, artists, tracks, artist tracks, track popularity, track features, track images, track previews, artist images, artist popularity, artist genres, and artist followers. The relationships between these entities are defined using foreign key constraints and cascading behavior.
routes.py This code snippet defines a Flask blueprint for handling user history. The /history route requires authentication, and when accessed, it returns the user's listening history.
Templates
File Summary
navbar.html This code snippet represents a navigation bar in HTML that allows users to navigate through different sections of a website. It includes features like displaying user-specific options, such as groups and insights, when a user is logged in. It also provides options for users to view their profile, account settings, report bugs, and sign out.
unauth_home.html The code snippet extends a base HTML template and defines a "content" block. It includes a title, description, and a button that enables a user to login with Spotify through a provided auth URL.
insights_global.html The code snippet is a template for displaying insights about all users. It shows the total number of tracks listened to, unique tracks and artists, and total listen duration. It also displays tables for the top 10 artists and tracks based on counts. The template includes scripts for charting and table functionality.
base.html This code snippet is for the base template of a web application. It includes the necessary HTML, CSS, and JavaScript code to create a responsive layout, handle flash messages, and provide functionality for dismissing those messages.
auth_home.html The provided code snippet extends a base HTML template and displays an authenticated homepage using the Bulma CSS framework. It features a hero section with centered text and a welcome message that includes the current user's username.
register.html The provided code snippet extends a base HTML template and creates a register form. It includes fields for username and email, and a submit button. The form captures user input and can be processed through a POST method.
insights.html The provided code snippet is a template for an insights page. It displays a table of the top 10 tracks and their respective details such as rank, track name, artist name, duration, and play count. Each track has a play button that toggles play/pause of a track preview. It also includes a modal for additional content display.
Scripts
File Summary
init_db.sh The provided code snippet initializes a database for a Flask application by creating the necessary migrations. After initializing, it performs the initial migration with a commit message and finally upgrades the database to reflect the changes.
flush_db.sh The provided code snippet clears the database file and removes all migration files for the application site.

๐Ÿš€ Getting Started

โœ”๏ธ Prerequisites

Before you begin, ensure that you have the following prerequisites installed:

  • โ„น๏ธ docker
  • โ„น๏ธ songswap-insights
  • โ„น๏ธ songswap-airflow

๐Ÿ“ฆ Installation

  1. Clone the songswap-app repository:
git clone [email protected]:SongSwap-social/songswap-app.git
  1. Change to the project directory:
cd songswap-app
  1. If running locally and not in Docker, install the dependencies:
pip install -r requirements.txt

๐ŸŽฎ Using songswap-app

  • Run the application locally, for testing or development purposes:
python main.py
  • Run the application in a Docker container:
docker build -t songswap-app .
docker run songswap-app

๐Ÿ—บ Roadmap

  • โ„น๏ธ Add Spotify OAuth authentication and user registration
  • โ„น๏ธ Generate charts and graphs for insights
  • โ„น๏ธ Migrate from local infra to hybrid AWS
  • โ„น๏ธ Add user groups and sharing functionality
  • โ„น๏ธ Add a search feature for users and groups
  • โ„น๏ธ Create public user profiles with a feed of their insights
  • โ„น๏ธ Allow users to post on their own and friends' profiles
  • โ„น๏ธ Create a homepage with a feed of friends' insights and posts
  • โ„น๏ธ Add a chat box feature

About

Social media platform for sharing songs with friends, family, or strangers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published