Skip to content

DelvinBa/Bazaarly

Repository files navigation

Bazaarly

Bazaarly is an E-Commerce platform similar to Amazon and AliExpress, where users can purchase products across several categories, and vendors can list their products to expand their reach and grow their business.

Built With

  • Backend: .NET 9
  • Frontend: Angular
  • Database: PostgreSQL
  • Message Queue: RabbitMQ

1 Installation

To set up the Bazaarly project locally, ensure you have the following prerequisites installed:

Development Environment

Install any of the following IDEs with the required components:

Required Components

  • .NET 9 SDK
  • Node.js (version ^18.19.1)
  • Git for Windows
  • .NET Aspire
  • Docker (or Podman)

2 Setting Up the Project

  1. Clone the Repository
    Clone the project repository to your local environment using Git.

  2. Execute setup dotnet commands Before running the application, the following commands must be ran.

   dotnet restore
   dotnet tool restore
   dotnet dev-certs https --trust
  1. Run Docker
    Start Docker (or Podman) to ensure that containers will be available for the project. If the container runtime is not started or Resource Saver mode is enabled, Aspire will be unable to start the docker containers

  2. Run the Bazaarly.AppHost Project
    After running Docker, you can run the Bazaarly.AppHost project from your chosen development environment. This can be done by clicking the run button in your IDE or by running:

   dotnet run --project .\src\Bazaarly.AppHost\ --launch-profile https

The AppHost project takes care of the orchestration of the Bazaarly project, including the running of the Docker containers. Thereby replacing Docker Compose. When the application starts, it will either:

  • Automatically open in your default browser with the .NET Aspire interface
  • Display the Aspire AppHost address in the terminal, which you can copy and paste into your browser

Seeded user accounts

The following accounts are seeded into the database: Vendor:

  • Username: bob
  • Password: Pass123$

Customer:

  • Username: alice
  • Password: Pass123$

Admin:

  • Username: jack

  • Password: Pass123$

    Running on macos

    If you use VS Code on a Mac and encounter the error: "The JSON-RPC connection with the remote party was lost before the request could complete," check your installed .NET SDKs. You likely have a .NET 8 SDK installed as well. Delete the current .NET 8 SDK and install the latest version of the .NET 8 SDK. Ensure that you have both the latest .NET 8 SDK and .NET 9 SDK installed.

  1. Accessing the .NET Aspire Dashboard
    The .NET Aspire dashboard should look like this:
    .NET Aspire Dashboard

    On this dashboard, you’ll see all the running Docker containers associated with the Bazaarly project.

3 Database Setup

The database is initialized by the migration services. These services will run before the actual projects are started and will apply the migrations, made by EntityFramework Core, to the databases. With the microservice architecture, each service has its own database. So each service has its own migration service.

Creating EF Core Migrations

Before starting, make sure you ran the following command in the terminal:

   dotnet tool restore

If you need to add EF Core migrations, then use the following steps and/or commands:

  1. Go to the project you want to create a migration for.
  2. Run the following command, if the C# project is a class library, then the parameter --startup-project must be used to specify the project that contains the Program.cs file.
  dotnet ef migrations add `<Migration name>`

Example with parameters:

   dotnet ef --startup-project ../Bazaarly.ApiService migrations add <Migration name>

EntityFramework Core integration with .NET Aspire

In a non .NET Aspire project the command dotnet ef update-database can be executed, however with .NET Aspire the database most likely unavailable since it runs in a docker container. To update the databases, Bazaarly makes use of so called migration-services. These migration-services apply all existing migrations to the database for a specified project. This also makes it possible to seed the database with test data.

If there is no migration service yet for the project you want to create the migration for.

  1. Then you need to create a worker service in the src directory and add it to the solution (see Bazaarly.IdentityService.MigrationService as example).
  2. The migration service must reference the Bazaarly.ServiceDefaults and Bazaarly.<for this project is the MigrationService> projects.
  3. Then copy & paste the code in program.cs and worker.cs from an existing migration service project, change the database context and database name.
  4. Add the project to the Bazaarly.AppHost project and configure the WaitForCompletion and References methods in the Program.cs file.
  5. Profit from the migration service.

4 Viewing the Bazaarly Application

Once the database is set up, open the webangular project from the Aspire dashboard to view the Bazaarly application in your browser.

5 Testing

The project includes multiple test projects located in the test folder to ensure the quality and functionality of the code. These tests cover the unit, integration, and acceptance tests of the application. To run the tests, follow the instructions below:

Restore the NuGet packages by running the following command in the Package Manager:

  dotnet restore

Run the tests using the following command:

  dotnet test

Running E2E tests

Before running end-to-end tests first you should run the project and create a customer account with (username: mahdirhd and password:123456) as it is needed to have an account for some of them (for example adding a product to the basket or ordering a product). If you want to run end-to-end tests, you need to first go to PlaywrightTests directory in your terminal and then run each test class individually(click on the play button on top of each test class next to the class name to run the test).

6 Deploying to the cloud

Bazaarly can't be deployed to the cloud in the current state. A conflict occurres due to the service discovery resulting in Angular not finding the right environmental variables. The API endpoints all work in when deployed to Azure Container Apps.

A deployment can be done by running the following command:

  azd up

or

  azd provision
  azd deploy

You need to be authenticated with Azure and have the Azure Developer ClI installed. Authentication can be done by running the following command:

  azd auth login

7 Upgrading to a Newer .NET Version

With the upgrade to the latest .NET (Current latest is .NET 9), you may need to update your existing projects to use the new SDK. To do this, follow these steps:

The SDK contains the ASP.NET runtime which is required to run the project.

8 Explanation of our folder structure

├── Bazaarly.ApiService
│   ├── Endpoints                # Defines API endpoints for external communication.
│   ├── Middleware               # Contains custom middleware for request handling.
│   └── Utils                    # Utility functions used across the API layer.
├── Bazaarly.AppHost             # Manages application hosting and configuration settings.
├── Bazaarly.Application
│   ├── Products                 # Contains product-related business logic and application services.
│   ├── Other entities           # Contains business logic for other entities in the application.
├── Bazaarly.Application.Contract
│   ├── Product                  # Defines product-related contracts (DTOs, interfaces).
│   ├── Other entities           # Defines contracts for other entities.
├── Bazaarly.Domain
│   ├── Product
│   │   ├── Exceptions           # Handles exceptions related to the product domain.
│   │   ├── Services             # Contains domain services specific to the product.
│   ├── Other entities           # Domain logic for other entities, including business rules and validation.
├── Bazaarly.Framework
│   ├── Domain                   # General domain-related components shared across layers.
│   ├── Exceptions               # Global exception handling utilities.
│   ├── Infrastructure           # General infrastructure services (e.g., logging, caching).
├── Bazaarly.IdentityServer      # Configurations for managing identity and authentication.
├── Bazaarly.IdentityServer.MigrationService  # Manages database migrations for IdentityServer.
├── Bazaarly.Infrastructure.EFCore
│   ├── Mappings                 # Database entity-to-model mappings (e.g., EF Core configurations).
│   ├── Migrations               # Handles database migrations for persistence.
│   ├── Repositories             # Implements repositories for database access.
├── Bazaarly.Infrastructure.StorageManager  # Services related to file and data storage management.
├── Bazaarly.ServiceDefaults     # Contains default service configurations (e.g., DI, settings).
├── Bazaarly.Web                 # Our Angular Frontend.
├── Integration                  # Integration tests to validate interaction between components.
├── Unit                         # Unit tests + Property Based Tests
├── Acceptance                   # Acceptance tests to validate the full application workflow.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 6