This is the backend app for music library that is built using FastAPI which provides a robust and scalable API service.
- It can log required information into files.
- It has a structured application Setup.
- It can be used in a containerized setup.
To run this application, you need to set the following environment variables:
APP_ENV
: The environment in which the app is running (e.g.,DEV
,PROD
).DATABASE_URL
: The URL of the database to connect to.LOG_LEVEL
: The logging level (e.g.,DEBUG
,INFO
,WARNING
,ERROR
).ALLOWED_ORIGINS
: This specifies allowed origins.
Example .env
file:
APP_ENV=DEV
DATABASE_URL=sqlite:///./test.db
LOG_LEVEL=DEBUG
ALLOWED_ORIGINS=http://127.0.0.1:3000
Follow these steps to initialize the application:
-
Clone the repository:
git clone https://github.com/raghavwahi/music-library-backend cd music-library-backend
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Upgrade pip and install dependencies:
python -m pip install --upgrade pip pip install -r requirements.txt
-
Set up the environment variables: Create a
.env
file in the root directory and add your environment variables as described above. -
Run the database migrations:
python app/scripts/initialize_db.py
-
Start the FastAPI application:
uvicorn app.main:app --reload
FastAPI automatically generates interactive API documentation using Swagger. To access the Swagger UI, follow these steps:
- Start the FastAPI application using the initialization steps above.
- Open your web browser and go to
http://127.0.0.1:8000/docs
.
Here, you can explore the API endpoints, send test requests, and see the API responses.
To maintain code quality and consistency, please follow these guidelines:
- Follow PEP 8: Ensure that your code follows the PEP 8 style guide.
- Write Docstrings: Document all functions and classes with appropriate docstrings.
- Type Annotations: Use type annotations for function arguments and return values.
- Linting: Use a linter (e.g., black, isort) to check your code for style issues before committing.
- Testing: Write unit tests for your code and ensure that they pass before pushing changes.
- Commit Messages: Use clear and concise commit messages. Follow the convention of starting with a capital letter.
Raghav Wahi - raghavwahi7@gmail.com