Skip to content

Hub module

The Hub module represents a separate bounded context within the Cargonerds solution. It manages shipments, ports and organisations independently of the main application and can be developed and deployed either together with the main system or as a standalone module. Like the Cargonerds module, it follows ABP’s layered architecture【405741767768697†L799-L846】.

Projects and responsibilities

Each folder under modules/hub/src corresponds to one layer of the Hub module. The table below summarises the purpose of each project.

Project Purpose
Hub.Domain.Shared Contains shared constants, localisation resources (HubResource) and error codes specific to the Hub context. It also defines translation settings and supported languages. This project has no dependencies and is referenced by all other Hub projects【405741767768697†L799-L808】.
Hub.Domain Defines the core domain entities such as Shipment, Organization, Port, Association and CodeEntity. These classes express the business rules for shipments (dates, ports, cargo details) and organisations, and they extend base classes from ABP (e.g. Entity<Guid>). The domain project also contains domain services, query filters and interfaces for repositories【405741767768697†L810-L819】.
Hub.Application.Contracts Declares the application service interfaces (e.g. IShipmentAppService, IHubOrganizatioAppService) and DTOs used to transfer data to and from the UI. It also defines permission names (HubPermissions) and filter request DTOs. As with the main module, this layer exposes contracts without revealing implementations【405741767768697†L822-L833】.
Hub.Application Implements the application services. For example, ShipmentAppService exposes methods to query shipments with paging and filtering and to perform CRUD operations. HubOrganizationAppService handles organisation queries. These services use ABP’s repository abstractions to interact with the domain. Application services depend on the domain layer and the contracts layer【405741767768697†L836-L846】.
Hub.EntityFrameworkCore Provides the data access layer using Entity Framework Core. It defines the HubDbContext and maps each domain entity to a table in the database. Additional query filters and helper classes implement multi‑tenancy and organisation filtering. Repository implementations live here and are injected into the application services【405741767768697†L848-L855】.
Hub.HttpApi Contains API controllers for the Hub. While ABP can auto‑generate controllers for most services, this project includes custom controllers when necessary and configures module routing. The controllers call the application services defined in Hub.Application.
Hub.HttpApi.Client Provides C# client proxies for the Hub APIs. These proxies can be used by other modules (for example the Cargonerds Blazor app) to call Hub services without writing HTTP client code manually【405741767768697†L899-L914】.
Hub.UI Implements the user interface for the Hub module using Blazor components. There are Razor components such as ShipmentCard, ShipmentDetailsView and pages for listing and editing shipments. The UI depends on the Hub.HttpApi.Client to call the backend APIs and uses ABP’s Blazor UI libraries.
Hub.Installer A helper project used by ABP’s installer to configure the module when it is added to a host application. It registers default menus, routes and static assets for the Hub UI.

Domain overview

The Hub domain revolves around shipments and organisations. A Shipment entity includes properties for ports of loading and discharge, estimated and actual dates (cargo ready, pickup, departure and arrival), cargo descriptions, CO₂ emissions and packaging counts. Each shipment may have multiple associated ShipmentAddress records for pickup and delivery addresses. Ports are represented by the Port entity and organisations are represented by the Organization entity. Domain services and filters enforce rules such as filtering shipments by organisation.

Application services

The application layer provides the entry point for clients. The ShipmentAppService offers methods to query shipments with paging and sorting, apply filters and perform CRUD operations (create, update, delete). The HubOrganizationAppService exposes similar operations for organisations. These services use ABP’s IRepository<T> to access the database and are protected by permissions declared in HubPermissions. The HttpApi layer exposes these services as REST and gRPC endpoints, and the HttpApi.Client layer generates proxies for consuming them.

User interface

The Hub UI is built with Blazor. It defines reusable components such as ShipmentCard.razor and ShipmentDetailsView.razor for presenting shipment data, and pages such as Shipments.razor for listing shipments. The UI depends on the HttpApi.Client proxies and automatically handles authentication via the main AuthServer. Menu contributions and routes are registered in UIMenuContributor.cs, ensuring that the Hub pages appear in the main navigation when the module is integrated into the host application.

Integrating the Hub module

Because the Hub module follows ABP’s modular design, it can be added to any ABP solution by referencing the Hub.HttpApi and Hub.Application projects in the host’s module class. In the Cargonerds solution the Hub module is compiled into the same solution and loaded via the CargonerdsDomainSharedModule and CargonerdsDomainModule dependencies. The module’s DbContext is registered with the main database in Cargonerds.EntityFrameworkCore, so all Hub tables are created alongside the Cargonerds tables when the DbMigrator runs. For information on running the system and deploying it, see the deployment guide.

Localization and translations

Like the main module, the Hub module includes a Localization/Hub folder under Hub.Domain.Shared with JSON files for each supported culture. New localization keys should be added to the default language file (en.json) and translated using Resourcetranslator.Cli. A translation.options.json file specifies the translator endpoint, API key, target cultures and output format. To generate translations, run

resourcetranslator translate --options modules/hub/src/Hub.Domain.Shared/translation.options.json --input modules/hub/src/Hub.Domain.Shared/Localization/Hub/en.json --output modules/hub/src/Hub.Domain.Shared/Localization/Hub

The tool will create or update files such as de-DE.json, fr.json and others according to the TargetCultures list. These resource files are loaded automatically by ABP at runtime.

Code generation with Nextended.CodeGen

DTOs and mapping extensions in the Hub module are generated at build time by Nextended.CodeGen. The CodeGen.config.json file in Hub.Domain defines where to output the DTOs (../Hub.Application.Contracts/Generated) and the mapping extensions (../Hub.Application/Extensions/Generated). When you build the solution, the generator inspects the domain entities and produces DTO interfaces and classes (e.g. ShipmentDto.g.cs) as well as a MappingExtensions.g.cs file containing extension methods to map between domain entities and DTOs. These generated files make it easy to expose domain data to the UI without writing repetitive mapping code.