A RESTful API backend for an online radio station application built with Spring Boot. This application provides endpoints for user authentication, radio station search, and favorite management.
- User Authentication: JWT-based authentication with registration and login
- Radio Station Search: Search and filter radio stations by name, country, language, or tags
- Favorites Management: Add, remove, and retrieve favorite radio stations
- API Documentation: Interactive Swagger/OpenAPI documentation
- Health Monitoring: Spring Boot Actuator for health checks and monitoring
- Database Support: H2 (development) and PostgreSQL (production)
- Security: Spring Security with JWT tokens
- Java 17
- Spring Boot 3.5.7
- Spring Security - Authentication and authorization
- Spring Data JPA - Database access
- PostgreSQL - Production database
- H2 Database - Development database
- JWT (jjwt) - Token-based authentication
- SpringDoc OpenAPI - API documentation
- Maven - Build tool
- Lombok - Boilerplate code reduction
- Java 17 or higher
- Maven 3.6+ (or use the included Maven wrapper)
- PostgreSQL 12+ (for production)
- Docker (optional, for containerized deployment)
git clone https://github.com/Chrisdanyk/eradio.git
cd eradio/backendCreate a .env file in the root directory:
# Spring Profile
SPRING_PROFILES_ACTIVE=dev
# Server Configuration
SERVER_PORT=8080
# Database Configuration (Production)
DB_URL=jdbc:postgresql://localhost:5432/eradio
DB_USERNAME=your_username
DB_PASSWORD=your_password
# JWT Configuration
JWT_SECRET=your-512-bit-secret-key-must-be-at-least-64-characters-long-for-hs512-algorithm-in-production-use-please-change-this
JWT_EXPIRATION=86400000
# Radio Browser API
RADIO_BROWSER_API_URL=https://de1.api.radio-browser.info
# Anthropic AI API (for AI-powered recommendations)
ANTHROPIC_API_KEY=your-anthropic-api-key-here
# Swagger/API Documentation (optional, defaults to false in production)
SWAGGER_ENABLED=falseNote: For production, use a strong, randomly generated JWT secret key.
./mvnw clean installOr with Maven installed:
mvn clean install./mvnw spring-boot:runThe application will start on http://localhost:8080 (or the port specified in SERVER_PORT).
Set the profile to prod in your .env file:
SPRING_PROFILES_ACTIVE=prodEnsure PostgreSQL is running and configured, then start the application:
./mvnw spring-boot:rundocker build -t eradio-backend:latest .docker run -d \
--name eradio-backend \
-p 8080:8080 \
--env-file .env \
eradio-backend:latestCreate a docker-compose.yml:
version: '3.8'
services:
backend:
build: .
container_name: eradio-backend
ports:
- "8080:8080"
env_file:
- .env
environment:
- SPRING_PROFILES_ACTIVE=prod
- DB_URL=jdbc:postgresql://postgres:5432/eradio
depends_on:
- postgres
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/actuator/health"]
interval: 30s
timeout: 3s
retries: 3
start_period: 40s
postgres:
image: postgres:15-alpine
container_name: eradio-postgres
environment:
- POSTGRES_DB=eradio
- POSTGRES_USER=${DB_USERNAME}
- POSTGRES_PASSWORD=${DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5432:5432"
volumes:
postgres_data:Run with Docker Compose:
docker-compose up -dOnce the application is running, access the interactive API documentation:
- Swagger UI: http://localhost:8080/swagger-ui.html
- OpenAPI JSON: http://localhost:8080/v3/api-docs
POST /api/auth/register- Register a new userPOST /api/auth/login- Login and get JWT token
GET /api/stations/search- Search radio stations (requires authentication)GET /api/stations/{id}- Get station by ID (requires authentication)
GET /api/favorites- Get user's favorites (requires authentication)POST /api/favorites/{stationId}- Add station to favorites (requires authentication)DELETE /api/favorites/{stationId}- Remove station from favorites (requires authentication)
Most endpoints require JWT authentication. Include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>
Run tests:
./mvnw testThe application includes health check endpoints via Spring Boot Actuator:
backend/
├── src/
│ ├── main/
│ │ ├── java/cg/xis/eradio/
│ │ │ ├── config/ # Configuration classes
│ │ │ ├── controller/ # REST controllers
│ │ │ ├── domain/ # Entities and repositories
│ │ │ ├── dto/ # Data Transfer Objects
│ │ │ ├── exception/ # Exception handlers
│ │ │ ├── infrastructure/ # External API clients
│ │ │ ├── security/ # Security configuration
│ │ │ └── service/ # Business logic
│ │ └── resources/
│ │ ├── application.yml # Main configuration
│ │ ├── application-dev.yml # Development profile
│ │ └── application-prod.yml # Production profile
│ └── test/ # Test files
├── .dockerignore
├── .gitignore
├── Dockerfile
├── pom.xml
└── README.md
- JWT tokens for stateless authentication
- Password encryption using BCrypt
- Spring Security for endpoint protection
- CORS configuration for cross-origin requests
| Variable | Description | Default | Required |
|---|---|---|---|
SPRING_PROFILES_ACTIVE |
Spring profile (dev/prod) | dev |
No |
SERVER_PORT |
Application port | 8080 |
No |
JWT_SECRET |
Secret key for JWT signing | - | Yes |
JWT_EXPIRATION |
JWT expiration time (ms) | 86400000 |
No |
DB_URL |
Database connection URL | - | Yes (prod) |
DB_USERNAME |
Database username | - | Yes (prod) |
DB_PASSWORD |
Database password | - | Yes (prod) |
RADIO_BROWSER_API_URL |
Radio Browser API base URL | https://de1.api.radio-browser.info |
No |
ANTHROPIC_API_KEY |
Anthropic API key for AI recommendations | - | Yes (for AI features) |
SWAGGER_ENABLED |
Enable Swagger UI | false |
No |
Important: .env files are NOT committed to GitHub (they're in .gitignore). In CI/CD pipelines, environment variables are set differently:
-
Set up GitHub Secrets:
- Go to your repository on GitHub
- Navigate to: Settings → Secrets and variables → Actions
- Click New repository secret
- Add each sensitive variable:
JWT_SECRETANTHROPIC_API_KEYDB_USERNAME(for production)DB_PASSWORD(for production)- Any other sensitive values
-
Use secrets in workflow files:
env: JWT_SECRET: ${{ secrets.JWT_SECRET }} ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
-
For non-sensitive variables, set them directly in the workflow:
env: SPRING_PROFILES_ACTIVE: prod SERVER_PORT: 8080 RADIO_BROWSER_API_URL: https://de1.api.radio-browser.info
- GitLab CI: Use CI/CD variables
- Jenkins: Use Credentials
- CircleCI: Use Environment variables
- AWS CodePipeline: Use Parameter Store or Secrets Manager
-
Copy the example template (create
.env.examplein your repo):# .env.example (safe to commit) SPRING_PROFILES_ACTIVE=dev SERVER_PORT=8080 DB_URL=jdbc:postgresql://localhost:5432/eradio DB_USERNAME=your_username DB_PASSWORD=your_password JWT_SECRET=your-secret-key-here JWT_EXPIRATION=86400000 RADIO_BROWSER_API_URL=https://de1.api.radio-browser.info ANTHROPIC_API_KEY=your-anthropic-api-key-here SWAGGER_ENABLED=false -
Create your local
.envfile:cp .env.example .env # Then edit .env with your actual values
Security Note: Never commit
.envfiles to version control. Always use secrets management in CI/CD pipelines.
If port 8080 is already in use, change it in your .env file:
SERVER_PORT=8081- Ensure PostgreSQL is running
- Verify database credentials in
.env - Check database URL format:
jdbc:postgresql://host:port/database
- Ensure
JWT_SECRETis set and at least 64 characters long - Check token expiration time
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License.
Chrisdanyk
- GitHub: @Chrisdanyk
- Radio Browser API for radio station data
- Spring Boot community
- All contributors and users
For more information, visit the API Documentation when the application is running.