This repository contains the backend codebase for the CPT202 Music Platform. It provides the RESTful API services required by the frontend application for music sharing, discovery, user management, and administrative tasks.
The backend is built using Java and the Spring Boot framework, leveraging a layered architecture for maintainability and scalability. It handles business logic, data persistence, and integration with external services like cloud storage.
The backend exposes a comprehensive set of APIs covering:
- User registration with email verification
- Secure login using JWT or session-based authentication (needs verification)
- User profile retrieval and updates
- Password management (change/reset)
- User role management (admin vs. regular user)
- Upload: Secure upload of music files (MP3, WAV, FLAC, etc.) to Tencent Cloud COS.
- Metadata Extraction: Automatic extraction of audio metadata using JAudioTagger.
- Listing & Searching: Paginated listing of music files with filtering by name, category, tags, user, etc.
- Details: Retrieval of detailed information for a specific music file.
- Management: Deletion of music files.
- Review System: Endpoints for admin review (approve/reject) of uploaded music, including storing review status and messages.
- Tagging/Categorization: Management of music categories and tags.
- Sending verification emails for registration.
- Potentially used for password resets or notifications.
- Endpoints within controllers likely restricted to admin roles for:
- Music review and approval
- User management (viewing users, changing roles)
- System configuration overview (if applicable)
- Abstraction layer for interacting with Tencent Cloud Object Storage (COS).
- Handles file uploads, deletions, and URL generation.
- Core Framework: Spring Boot 2.7.6
- Language: Java 17
- Build Tool: Apache Maven
- Database: MySQL
- ORM: MyBatis Plus
- Caching: Redis
- File Storage: Tencent Cloud COS (Cloud Object Storage)
- API Documentation: Knife4j (Swagger/OpenAPI enhancement)
- Utilities: Lombok, Hutool, Apache Commons Lang3
- Audio Metadata: JAudioTagger
- Email: Spring Boot Mail Starter
- Containerization: Docker (Dockerfile included)
- Testing: Spring Boot Test, JUnit 5
- JDK 17 or later
- Maven 3.6+ or use the included Maven Wrapper (
mvnw) - MySQL Server 8.x
- Redis Server
- Tencent Cloud COS account and credentials (Bucket Name, Secret ID, Secret Key, Region)
-
Clone the repository:
git clone [repository-url] cd MusicRepo -
Configure
application.yml:- Navigate to
src/main/resources/application.yml. - Update the following sections with your credentials:
spring.datasource(MySQL URL, username, password)spring.redis(host, port, password if applicable)tencent.cos(secret-id, secret-key, region, bucket)spring.mail(host, port, username, password)
- Recommendation: Use environment variables or Spring profiles for sensitive credentials instead of hardcoding in
application.ymlfor production environments.
- Navigate to
-
Database Setup: See the Database Setup section below.
-
Build the project (using Maven Wrapper):
./mvnw clean package -DskipTests
(Use
mvnw.cmdon Windows) -
Run the application:
java -jar target/CPT202Music-0.0.1-SNAPSHOT.jar
Alternatively, run directly from your IDE (e.g., IntelliJ IDEA, Eclipse) by running the
Cpt202MusicApplicationmain class.
The application should start and be available, typically on port 8080 (check application.yml for server.port).
A Dockerfile is provided for containerizing the application.
-
Build the Docker image:
docker build -t cpt202-music-backend . -
Run the Docker container (ensure MySQL and Redis are accessible from the container, and pass configuration via environment variables or volume mounts):
docker run -p 8080:8080 \ -e SPRING_DATASOURCE_URL=jdbc:mysql://<db_host>:3306/<db_name> \ -e SPRING_DATASOURCE_USERNAME=<db_user> \ -e SPRING_DATASOURCE_PASSWORD=<db_pass> \ -e SPRING_REDIS_HOST=<redis_host> \ # Add other necessary environment variables (COS, Mail, etc.) cpt202-music-backend
MusicRepo/
├── src/
│ ├── main/
│ │ ├── java/org/example/cpt202music/
│ │ │ ├── Cpt202MusicApplication.java # Main entry point
│ │ │ ├── annotation/ # Custom annotations
│ │ │ ├── aop/ # Aspect-Oriented Programming (logging, auth checks)
│ │ │ ├── common/ # Common classes, enums
│ │ │ ├── config/ # Spring configurations (Beans, Security, CORS, etc.)
│ │ │ ├── constant/ # Application constants
│ │ │ ├── controller/ # API Controllers (REST endpoints)
│ │ │ ├── dto/ # Data Transfer Objects
│ │ │ ├── exception/ # Custom exception handling
│ │ │ ├── manager/ # External service interaction (e.g., CosManager)
│ │ │ ├── mapper/ # MyBatis Plus data mappers (DAO layer)
│ │ │ ├── model/ # Data models (Entities, Value Objects)
│ │ │ └── service/ # Business logic layer
│ │ └── resources/
│ │ ├── application.yml # Main application configuration
│ │ └── generator/ # (Potentially MyBatis code generator config)
│ └── test/ # Unit and integration tests
├── sql/
│ └── create_table.sql # Database schema setup script
├── target/ # Build output (JAR file)
├── .mvn/ # Maven Wrapper configuration
├── Dockerfile # Docker build instructions
├── mvnw / mvnw.cmd # Maven Wrapper scripts
├── pom.xml # Maven project configuration
└── README.md # This file
The project uses Knife4j to provide enhanced Swagger/OpenAPI documentation.
- Once the application is running, access the API documentation UI at:
http://localhost:8080/doc.html(or your configured host/port +/doc.html)
This interface allows you to explore all available API endpoints, view request/response models, and test the APIs directly from your browser.
Key configuration is managed in src/main/resources/application.yml.
- Server: Port, context path.
- Database: Datasource URL, credentials, connection pool settings.
- Redis: Host, port, database index, password.
- MyBatis Plus: Mapper locations, type aliases, global configuration.
- Tencent Cloud COS: Credentials (Secret ID, Secret Key), region, bucket name.
- Spring Mail: SMTP server details, authentication.
- Logging: Log levels, output formats.
Consider using Spring Profiles (application-{profile}.yml) to manage different configurations for development, testing, and production environments. Environment variables are often preferred for sensitive data in production.
- Ensure your MySQL server is running.
- Create a database for the application (e.g.,
cpt202_music). - Connect to your MySQL server using a client (e.g., MySQL Workbench,
mysqlCLI). - Execute the script
sql/create_table.sqlagainst the created database to set up the necessary tables.(Adjust the path as necessary)USE cpt202_music; SOURCE /path/to/MusicRepo/sql/create_table.sql;
- Verify that the tables have been created successfully.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature-name). - Make your changes.
- Write unit tests for new functionality.
- Ensure all tests pass (
./mvnw test). - Commit your changes (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature/your-feature-name). - Open a Pull Request against the
mainbranch.
Please adhere to the existing code style and provide clear commit messages.
[Specify your license here, e.g., MIT License]