Skip to content

A clean architecture Music Library API using Golang (Gin) and MongoDB, supporting track/playlist CRUD, MP3 uploads, search, and simple MP3 streaming.

Notifications You must be signed in to change notification settings

TuanTran0168/golang-music-library-management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🎵 Music Library Management

A clean architecture Music Library Management application built with Golang (Gin) and MongoDB.
It supports:

  • CRUD operations for tracks and playlists
  • MP3 uploads using GridFS
  • Image uploads using Cloudinary
  • Search functionality
  • Simple MP3 streaming

🚀 Run with Docker (Recommended)

1️⃣ Go to project folder

cd music-library-api

Important: Make sure you are in the root folder of the project where docker-compose.yml exists before running any docker-compose commands.

2️⃣ Start MongoDB + Backend APIs

docker-compose up -d

This will automatically:


💾 MongoDB Backup & Restore

Important: Ensure the backups/ folder exists and is correctly mounted in the MongoDB container before running any backup or restore commands.

📦 Dump (Backup) the database

docker exec music_mongo_prod sh -c "mongodump --db music_library --username root --password Admin@123 --authenticationDatabase admin --archive=/dump/music_library_$(date +%Y%m%d_%H%M%S).gz --gzip"

📌 Example output file

./backups/music_library_20251130_123456.gz

🔄 Restore MongoDB Backup

Important: Replace the backup_file_name below with the actual backup file you want to restore.

💡 Example Backup File Name (you can repalce): music_library_20251130_114415.gz

docker exec -i music_mongo_prod sh -c "mongorestore --username root --password Admin@123 --authenticationDatabase admin --archive=/dump/<backup_file_name>.gz --gzip --db music_library --drop"

🎧 Streaming APIs

▶ Stream a track (.mp3)

GET /api/tracks/{id}/stream

📁 Project Structure

├── backups/
│   └── *.gz
├── cmd/
│   └── main.go
├── configs/
├── docs/
├── internal/
│   ├── dto/
│   ├── handlers/
│   ├── mappers/
│   ├── models/
│   ├── repositories/
│   ├── routers/
│   └── services/
├── pkg/
│   ├── databases
│   └── utils
├── uploads/
│   ├── *.mp3
├── Dockerfile
├── Dockerfile.local
├── docker-compose.yaml
├── docker-compose-local.yaml
└── run.sh

🧹 Cleanup Docker System

🛑 Stop containers

docker-compose down

🗑 Remove containers, volumes, networks

docker-compose down -v
docker compose down -v --rmi all --remove-orphans

⭐ Done! ✔

Just run docker-compose and everything works out of the box.

🔧 Tech Stack

  • Golang 1.25.1 🟦
  • Gin ⚡ (HTTP web framework)
  • MongoDB 🗄 (mgm v3, GridFS)
  • Cloudinary ☁️ (Image upload)
  • Swagger 📑 (API docs)
  • Docker & Docker compose 🐳 (Containerization)
  • Audio Processing 🎵 (tag, go-mp3)

About

A clean architecture Music Library API using Golang (Gin) and MongoDB, supporting track/playlist CRUD, MP3 uploads, search, and simple MP3 streaming.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages