Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/mich31/scoreplay-media-api

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/mich31/scoreplay-media-api

  • v0.0.0-20241120101925-776d16c5e9bd
  • Source
  • Go
  • Socket score

Version published
Created
Source

ScorePlay Media API

Description

This project is an implementation of a REST API providing endpoints to manage media assets & tags. It provides the following functionalities:

  • Create a tag
  • List all tags
  • Search tags by name
  • Delete tag
  • Create a media
  • Search medias by tag

Architecture

This application has been implemented with Go and Fiber which is a famous framework for easily building REST APIs in Go.

It uses a PostgreSQL database. PostgreSQL is easy to use as a SQL database and handles well the logic of this application. Any other SQL database like MySQL or NoSQL like MongoDB could have been use in this case. This database includes 3 tables: media (media entities), tags (tag entities), media_tags(manage many-to-many association between medias and tags).

GORM manages interactions between the application and the database. This ORM library is easy to use and provides a straightforward documentation.

MinIO is used here as a storage service to manage & store media files created. It seems more relevant to use a dedicated storage service for media management than use a database for scalability, security and cost-effectiveness concerns. MinIO provides a pretty simple Go SDK, similar functionalities than Amazon S3 or any other famous cloud storage service (GCP, Azure Blob Storage), a WEBUI (available at http://127.0.0.1:9001 if you run it via a Docker) and an API (available at http://127.0.0.1:9000 if you run it via a Docker). You can find the credentials (MINIO_ROOT_USER & MINIO_ROOT_PASSWORD) in .env.example file.

For simplicity and effectiveness, both the PostgreSQL database and MinIO will be run as Docker containers.

P.S: You may need to create an access key via MinIO WebUI (available at http://127.0.0.1:9000 if you run it via a Docker) if you get an error (The Access Key Id you provided does not exist in our records) when running the application. This case is handled through the instructions set in the docker-compose.yaml file.

How to run

Prerequisites

  1. Install Docker and Docker Compose
  2. Install Go 1.23+
  3. Clone this repository

Environment Setup

  1. Open a terminal and go to the root folder of this repository
cd scoreplay-media-api
  1. Create a copy of .env.example file and name it .env:
cp .env.example .env

Run the service

  1. Run the database and storage service using Docker Compose
docker compose up -d
  1. Install the dependencies
go mod tidy
  1. Build & generate the artifact
go build
  1. Run the service
./scoreplay-media-api

The service is running on http://localhost:3000.

API documentation is available in docs/swagger.yaml or http://localhost:3000/swagger.

Testing

Run tests

go test ./...

Technologies

Improvements

  • Logging: More structured logs need to be added with different log levels (DEBUG, INFO, ERROR) for better monitoring and debugging.
  • Testing: The current tests suite covers the controllers logic and an integration with the services. Test coverage needs to be improved with more unit and integration tests. An in-memory database could even be used to test end-to-end integrations and rely less on mocks.
  • Pagination & Filtering: Pagination needs to be implemented for scalability and better performance. Additional filters can be added to provide limiting & sorting capabilities.
  • Storage: MinIO is a nice solution for prototyping. In a long run, the integration with a production-ready service like Amazon S3, Google Cloud Storage or Azure Blob Storage can be implemented.
  • API documentation: Swaggo helps to generate swagger documentation with annotations but there is room for improvement on the result. In my opinion, it is interesting to use this library to get a 1st draft version and then improve it.
  • File management:
    1. A limit can be set for the input file size on POST /api/medias endpoint. It depends on the product requirements but it could help to control resource consumption and service availability.
    2. File processing can be improved by delegating file upload to a messaging service
    3. It might be useful to implement file compression and thumbnail generation. This will help to manage costs especially for large files if the storage is managed by a cloud service.
    4. File type checks should be implemented for security concerns.
  • Caching: Caching can be implemented for the most used tags & medias using a technology like Redis. It could help to maintain a good performance on a system which may have to handle a large amount of medias & tags.

FAQs

Package last updated on 20 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc