music-library

module
v0.0.0-...-a1990c1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2024 License: MIT

README

Music Library

Go Version

The Music Library project is the result of a test assignment.


C4 Architecture Visualization

Level 2: Containers

C4 Level 2

Level 3: Components

C4 Level 3


Features

  • Adding information about music tracks.
  • Updating information about existing tracks.
  • Deleting tracks from the library.
  • Retrieving song lyrics with support for pagination by verses.
  • Retrieving library content with support for filtering across all fields and pagination.
  • Working with data through a REST API (API documentation is available in Swagger).
  • Integration with Prometheus for collecting and storing application metrics.

Potential Improvements

  • Separate lyrics Table: Create a dedicated table for storing song lyrics, as a single song may have multiple lyrics associated with it.
  • Optimize Update Method: Modify the current update method to perform data updates using a single query. (Refer to the documentation for postgres.Repository.UpdateSong() for the reasoning behind the current implementation.)
  • Add Metrics Collection: Implement metrics collection for infrastructure layer packages to monitor performance and resource usage.

Installation and Setup

  1. Make sure you have the following installed:

  2. Clone the repository:

    git clone https://github.com/FlutterDizaster/music-library
    cd music-library
    
  3. Configure the application (see Configuration). The application can read configuration parameters from the env file, but environment variables have a higher priority. So for launching using docker compose, all configuration will take place in it. Please remember to provide the correct details server address.

  4. Start the application containers:

    docker compose up -d
    

    If you use a port other than the default, you will need to make edits to the docker-compose.yaml.

  5. To stop the application:

    docker compose down
    

The application will be available at http://<HTTP_ADDR>.


Configuration

The application loads configuration parameters from the .env file, which must be created in the project root directory, or from environment variables. Available configuration parameters are listed below:

Variable Name Description Required
HTTP_ADDR Service address (default: ":8080") true
DATABASE_DSN Database connection string (default: none) true
DB_RETRY_COUNT Number of retries for DB (default: 3) false
DB_RETRY_BACKOFF Time between DB reconnect retries (default: "1s") false
MIGRATIONS_PATH Path to migrations folder (default: "/migrations") false
DETAILS_SERVER_ADDR Address of the details server (default: "http://localhost:8081") true
DETAILS_SERVER_RETRY_COUNT Number of retries for details server (default: 3) false
DETAILS_SERVER_RETRY_BACKOFF Time between retries for details server (default: "1s") false
DETAILS_SERVER_MAX_RETRY_BACKOFF Max time between retries for details server (default: "10s") false
Example .env file content:
HTTP_ADDR=:8080
DETAILS_SERVER_ADDR=http://localhost:8081
DATABASE_DSN=postgres://user:pass@localhost:5432/dbname?sslmode=disable

Make sure all parameters are correctly set before starting the application.


Project Structure

.
├── cmd
│   └── main.go
├── docs
│   └── images
│       ├── c2.png
│       └── c3.png
├── internal
│   ├── apperrors
│   │   └── apperrors.go
│   ├── application
│   │   ├── application.go
│   │   ├── config
│   │   │   └── config.go
│   │   └── service
│   │       └── service.go
│   ├── domain
│   │   ├── interfaces
│   │   │   ├── details_repository.go
│   │   │   ├── music_repository.go
│   │   │   └── music_service.go
│   │   └── models
│   │       ├── filter.go
│   │       ├── library.go
│   │       ├── library_easyjson.go
│   │       ├── lyrics.go
│   │       ├── lyrics_easyjson.go
│   │       ├── pagination.go
│   │       ├── song.go
│   │       ├── song_detail.go
│   │       ├── song_detail_easyjson.go
│   │       ├── song_easyjson.go
│   │       ├── song_title.go
│   │       └── song_title_easyjson.go
│   ├── infrastructure
│   │   ├── http
│   │   │   └── detailsclient
│   │   │       └── detailsclient.go
│   │   ├── metrics
│   │   │   ├── metrics.go
│   │   │   └── metrics_registry.go
│   │   └── persistance
│   │       ├── migrator
│   │       │   └── migrator.go
│   │       └── postgres
│   │           ├── postgres_repository.go
│   │           └── queries.go
│   └── presentation
│       ├── handler
│       │   ├── handler.go
│       │   └── music.go
│       ├── middleware
│       │   ├── logger.go
│       │   ├── memory_writer.go
│       │   ├── metrics.go
│       │   └── middleware.go
│       └── server
│           └── server.go
├── migrations
│   ├── 001_create_songs_table.down.sql
│   └── 001_create_songs_table.up.sql
├── swagger
│   ├── docs.go
│   ├── swagger.json
│   └── swagger.yaml
├── Dockerfile
├── docker-compose.yaml
├── LICENSE
├── Makefile
├── README.md
├── go.mod
└── go.sum

API

API documentation is available in the following files:

To view the documentation in a convenient interface, you can use Swagger UI or any other compatible tool.


License

This project is licensed under the MIT License. See LICENSE for more details.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL