Version 1.0 • A backend-heavy, full-stack music streaming application
Built with FastAPI, Flutter, PostgreSQL etc.
This is a backend heavy Music Streamer made with FastAPI + PostgreSQL + SQLAlchemy that allows three user groups (Superusers aka admin, Singers and Listeners)
This small-scale music streaming platform is for artists and listeners. It’s designed to run entirely on free cost cloud services but scalable so that it can still grow if needed. The stack is selected to balance simplicity, cost efficiency, maintainability, and ease of scaling later.
The project although would have a frontend, would be backend heavy, especially relying on FastAPI and its features, hopefully exploring most if not all of its beginner to intermediate features.
| 🏗️ FastAPI | Async Python web framework. High-performance & ASGI-based. |
|---|---|
| 🛡️ Pydantic | Data validation using Python type hints. Validates request/response models. |
| 🧱 SQLAlchemy | ORM and SQL toolkit for handling database models and queries. |
| 🐘 PostgreSQL | Relational database for storing application data. |
| 🧬 Alembic | Database migration tool used alongside SQLAlchemy. |
| 🧪 Pytest | Testing framework for writing backend tests. |
| 📦 Poetry | Dependency & virtualenv manager for Python. |
| 📱 Flutter | Natively compiled mobile/web UI from a single codebase |
This project is using poetry as package manager and SqlAlchemy for version control of its database, which is using PSQL.
First, we need to clone the repo, open a terminal and go to your desired directory and run the following command to clone the source code from the repository.
git clone https://github.com/myndaaa/MusicPlayer-FastAPI.git
Note: a prerequisite for the above is to have git added to your system path, if you dont have it follow instructions in accordance to your development machines OS.
Next up, ensure you have the correct dependencies installed.
- Poetry
- Postgresql
before installing please read and go through the process once having a clear picture of how poetry functions.
Depending on whether you are in a Mac device or Windows, run the following commands:
Mac
brew install poetryWindows via curl (can also use pip)
curl -sSL https://install.python-poetry.org | python -Once done. Add it to the path and then verify your installation with poetry --version for both mac and windows.
Changing to the correct interpreter
If we have opened the folder where poetry was initiated then visual studio on its own would detect the environment created by poetry and change the interpreters. But if we are not in the folder where poetry was initiated, for example this project. where the folder directory looks like - root folder : music_streamer and we have music_streamer/backend/poetry.toml
In such case we have to manually change the interpreter so the frameworks that are installed via Poetry would be detected.
- Get all poetry env list
poetry env info --path sample output: /Users/mlbd-XX/Library/Caches/pypoetry/virtualenvs/music_streamer-fastapi-abc123-py3.11
- Press
Cmd + Shift + P(orCtrl + Shift + Pon Windows) - Search:
Python: Select Interpreterclick it and then clickEnter interpreter path - now type the env path found earliar and add
/bin/pythonto
Make Poetry always create virtual envs inside project. This makes it easier to find the venv:
This must be run before doing poetry init
poetry config virtualenvs.in-project trueThen future virtual environments will be created inside .venv in the subfolder, like backend/.venv/bin/python
Then we can set interpreter to:
backend/.venv/bin/pythonIf running this mid project then:
# enable project venv
poetry config virtualenvs.in-project true
# remove current global venv no data loss
poetry env remove python
# make a fresh `.venv/`
poetry installThis project uses PostgreSQL as the database. Follow these steps to install it on your machine.
For Mac, install using Homebrew:
brew install postgresqlStart the PostgreSQL service:
brew services start postgresql
Connect to the default postgres database:
psql postgresVerify installation with
psql --versionFor installing PSQL on Windows, follow these steps
-
Download the installer from official PostgreSQL site.
-
Run the installer:
- Choose your version.
- Set a superuser password (remember this for your
.envfile).
-
After installation, you can:
- Use pgAdmin (the included graphical tool) to manage your database.
- Or open the psql shell to run commands.
Verify installation with
psql --versionCopy .env.example to .env and update values as needed:
cp .env.example .envThen update the variables as needed so the application (alembic and fastapi) understands it
Install dependencies and activate Poetry shell
poetry install # Installs project dependencies added via poetry add <dependency_name>poetry shell # Activates the virtual environmentInside the psql shell, we can run all commands directly, this shell is the virtual env shell for poetry, else, we can run poetry commands by setting it as the interpretor on vsCode and using commands as follows:
poetry run alembic upgrade head
poetry run uvicorn app.main:app --reload
poetry run pytestLogin to PostgreSQL
psql -U postgres- Create the database and user if you haven’t already:
CREATE USER mynda WITH PASSWORD 'dev';
CREATE DATABASE music_stream OWNER mynda;
GRANT ALL PRIVILEGES ON DATABASE music_stream TO mynda;Initialize Alembic (already done if cloning repo) Run migrations to create tables
From the project root (where alembic.ini is located):
alembic upgrade headThis will apply all migration scripts and create all necessary tables. Verify tables are created
Use psql or any PostgreSQL client to check:
psql -U mynda -d music_stream
\dtInstall Docker for your OS. Verify with the following commands
docker --version
docker-compose --versionSimply launching the Docker Desktop application will automatically start the Docker daemon.
Look at the root folder and make sure it contains the following file docker-compose.yml
Then change directory to said root folder and run the following command:
docker-compose up --buildAlternatively check the health of the containers via
docker compose psSample output:
NAME COMMAND STATE HEALTH PORTS
music-db-1 "docker-entrypoint.s…" Up 30 seconds healthy 5432/tcp
music-web-1 "uvicorn app.main:ap…" Up 10 seconds starting 0.0.0.0:8000->800
Further details about the system can be found on topic specific markdown files. Based on the requirement kindly click the links below to redirect to the correct document to get explanation of the system in detail.