Tunify is a comprehensive music streaming platform that allows users to create and manage playlists, explore a diverse library of songs, albums, and artists, and enjoy personalized recommendations based on their preferences. The platform supports multiple subscription types, catering to various user needs. Tunify aims to deliver an exceptional music experience through a user-friendly interface and robust backend infrastructure.
The Tunify platform's database is designed with several entities to efficiently manage and store information related to users, subscriptions, playlists, songs, albums, and artists. Below is an overview of the relationships between these entities:
-
Users and Subscriptions
- Users are linked to Subscriptions through a foreign key relationship. Each user has a
SubscriptionIdthat references theIdof a subscription plan. This relationship ensures that each user is associated with a specific subscription type, which defines their access level and features on the platform. - One-to-Many Relationship: One subscription can have multiple users, but each user can only have one subscription.
- Users are linked to Subscriptions through a foreign key relationship. Each user has a
-
Users and Playlists
- Users can create multiple Playlists. Each playlist is linked to a user through a foreign key (
UserId). - One-to-Many Relationship: One user can have multiple playlists, but each playlist is associated with one user.
- Users can create multiple Playlists. Each playlist is linked to a user through a foreign key (
-
Playlists and Songs
- The relationship between Playlists and Songs is managed through a join table called
PlaylistSongs. This table contains the foreign keys for both playlists and songs, allowing a many-to-many relationship. - Many-to-Many Relationship: One playlist can contain multiple songs, and one song can appear in multiple playlists.
- The relationship between Playlists and Songs is managed through a join table called
-
Songs and Albums
- Each Song belongs to an Album. The
AlbumIdin the Songs table references theIdin the Albums table. - One-to-Many Relationship: One album can have multiple songs, but each song belongs to one album.
- Each Song belongs to an Album. The
-
Songs and Artists
- Each Song is created by an Artist. The
ArtistIdin the Songs table references theIdin the Artists table. - One-to-Many Relationship: One artist can create multiple songs, but each song is created by one artist.
- Each Song is created by an Artist. The
The Repository Design Pattern decouples data access logic from the business logic in the application, promoting modularity and testability.
In this project, repositories were created for managing data access for the Users, Playlist, Song, and Artist entities. These repositories encapsulate CRUD operations and any additional data access logic, making the application easier to maintain and extend.
- Separation of Concerns: Keeps data access logic separate from business logic.
- Testability: Allows for mocking data access during unit tests.
- Flexibility: Facilitates changes in data access strategy without affecting business logic.
In this lab, we introduced advanced navigation and routing functionalities to improve the user experience within the Tunify Platform. These enhancements include:
- Dynamic Routing: Routes are dynamically generated based on user actions such as playlist creation or artist selection.
- Nested Routing: Certain pages, such as songs within a playlist or albums by an artist, use nested routes to keep the URL structure clean and meaningful.
- Parameterized Routing: Routes now accept dynamic parameters for accessing specific resources. For example:
/playlists/:id/songsfor viewing songs in a playlist./artists/:id/songsfor viewing songs by a particular artist.
- Lazy Loading: Implemented lazy loading for certain modules to improve performance, loading only the necessary components when they are needed.
```javascript
{
path: 'playlists/:id/songs',
component: PlaylistSongsComponent,
},
{
path: 'artists/:id/songs',
component: ArtistSongsComponent,
}
Swagger UI has been integrated into this project to provide an interactive interface for testing and documenting the API endpoints. This allows developers to easily explore the API's functionality, test requests, and view responses directly from the browser.
- Run the Application
-
Open a terminal or use Visual Studio to run the application. The app will run on
http://localhost:5002/by default.Using the terminal:
dotnet run
-
- Open Swagger UI
-
Open your browser and navigate to:
Using the terminal:
http://localhost:5002/
-
The Swagger UI will display a list of all available API endpoints along with the supported HTTP methods (GET, POST, PUT, DELETE).
-
This section covers the Identity Management implementation in the Tunify Platform. It includes user authentication, role management, and session handling using ASP.NET Core Identity.
- User Registration: Allows new users to sign up with their details.
- User Login and Logout: Provides authentication and session management for users.
- Role Management: Supports user roles and claims for authorization.
- Session Management: Handles user sessions and token-based authentication.
-
Install Package
- Install the
Microsoft.AspNetCore.Identity.EntityFrameworkCorepackage. - Ensure other required packages (e.g.,
Microsoft.EntityFrameworkCore.SqlServer) are also installed if using SQL Server.
- Install the
-
Extend
AppDbContext- Ensure
AppDbContextextendsIdentityDbContext<IdentityUser>.
- Ensure
-
Create DTOs
- Create Data Transfer Objects (DTOs) for user management, such as
RegisterDtoandLoginDto.
- Create Data Transfer Objects (DTOs) for user management, such as
-
Create the Interface
- Define an interface (e.g.,
IAccount) for account-related operations.
- Define an interface (e.g.,
-
Create the Service
- Implement the service (e.g.,
IdentityAccountService) that adheres to theIAccountinterface and handles authentication logic.
- Implement the service (e.g.,
-
Create the Controller
- Implement a controller that handles registration, login, and optionally password management.
-
Update
Program.cs- Add the following services and configuration:
builder.Services.AddScoped<IAccount, IdentityAccountService>(); builder.Services.AddIdentity<IdentityUser, IdentityRole>() .AddEntityFrameworkStores<AppDbContext>(); app.UseAuthentication();
- Add the following services and configuration:
-
Run Migrations
- Execute the following commands to create and apply migrations:
dotnet ef migrations add InitialCreate dotnet ef database update
- Execute the following commands to create and apply migrations:
This guide provides the steps needed to set up ASP.NET Core Identity in your project, covering installation, configuration, and database setup.
- Install
Microsoft.AspNetCore.Authentication.JwtBearerpackage. - Configure JWT authentication in
Program.cs. - Implement
JwtTokenServicefor token creation and validation.
- Add
[Authorize]attributes to secure API endpoints. - Use role-based and policy-based authorization as needed.
- Seed initial roles and a default admin user in
TunifyDbContext. - Assign roles and claims to users and secure endpoints based on these roles.
