Быстрый старт
Relevant source files
The following files were used as context for generating this wiki page:
The Music Subscription Service is a backend REST API built with Go, designed to emulate platforms like Spotify or Yandex Music. It provides a robust foundation for music streaming, user management, and subscription-based access control. Sources: README.md:1-5
This guide provides the necessary steps to set up the environment, launch the services using Docker or local tools, and understand the basic configuration required to get the system operational. Sources: README.md:7-10
Environment Requirements
To run the service, ensure the following software is installed on your system:
- Docker & Docker Compose: For containerized deployment and dependency management (PostgreSQL, Redis).
- Go 1.21+: Required for local development and running tests. Sources: README.md:11-13, cmd/app/main.go:42
Deployment Options
Docker Compose Setup
The fastest way to start the service is using Docker Compose, which orchestrates the application, the database, and the cache.
# Clone the repository
git clone <repo-url>
cd music-service
# Build and start all services
docker-compose up --build
Sources: README.md:15-22, docker-compose.yml:1-5
The application will be available at http://localhost:8080, and the Swagger documentation can be accessed at http://localhost:8080/swagger/index.html. Sources: README.md:24-25
Local Development Setup
For developers who prefer running the application binary directly, follow these steps:
- Install dependencies:
go mod download. - Configure environment:
cp .env.example .env. - Start infrastructure:
docker-compose up postgres redis -d. - Apply migrations:
make migrate-up. - Run application:
make run.
Sources: README.md:27-41
Configuration and Environment Variables
The application relies on environment variables for database connections, security secrets, and business logic limits.
| Variable | Default Value | Description |
|---|---|---|
APP_PORT | 8080 | Server listening port |
DB_HOST | localhost | PostgreSQL host |
DB_PORT | 5432 | PostgreSQL port |
JWT_ACCESS_SECRET | - | Secret key for Access Tokens |
FREE_DAILY_PLAY_LIMIT | 10 | Daily song limit for FREE tier |
FREE_PLAYLIST_LIMIT | 3 | Playlist limit for FREE tier |
Sources: README.md:43-62, internal/core/config/config.go:31-50
System Architecture and Data Flow
The application follows a modular architecture where the main.go entry point initializes core components (Logging, DB, Redis) and injects dependencies into feature-specific services. Sources: cmd/app/main.go:50-120
Initialization Flow
The following diagram illustrates the startup sequence of the application:
The startup process ensures that all infrastructure dependencies are healthy before the HTTP server begins accepting requests. Sources: cmd/app/main.go:53-145
Database Schema
The system uses a relational schema to manage the music catalog and user interactions. Key entities include Users, Tracks, Playlists, and History.
Sources: migrations/001_init.up.sql:1-92
Infrastructure Components
The service depends on several specialized containers defined in the orchestration layer:
- app: The Go backend service.
- postgres: Relational database (PostgreSQL 16) for persistent data.
- redis: In-memory store (Redis 7) for caching and rate limiting.
- postgres-migrate: Utility for applying SQL migrations.
Sources: docker-compose.yml:5-82, README.md:144-155
Management and Admin Operations
Creating an Admin User
Admin privileges are required for managing the track catalog. This can be done via SQL:
INSERT INTO users (email, username, password_hash, role, subscription_type)
VALUES ('admin@example.com', 'admin', '<bcrypt_hash>', 'ADMIN', 'PREMIUM');
Alternatively, use the Makefile command: make create-admin EMAIL=admin@example.com PASSWORD=secret. Sources: README.md:112-124
Deployment to Fly.io
The project includes configuration for Fly.io deployment, utilizing a release command to automatically run migrations during the deployment process.
Sources: fly.toml:1-25, README.md:175-185
Summary
The "Быстрый старт" process is designed to get the Music Subscription Service running with minimal friction using Docker. By following the environment configuration and deployment steps, developers can quickly access the API, explore the Swagger documentation, and begin interacting with the music catalog. Sources: README.md:230-245