Skip to content

Repository files navigation

ParcelTracking

Modern parcel tracking API built with ASP.NET Core, Entity Framework Core, and a layered architecture across API, application, domain, and infrastructure projects.

Overview

ParcelTracking is a backend service for registering shipments, tracking parcel progress, estimating deliveries, recording delivery confirmations, and exposing operational analytics.

Highlights

Architecture

The solution is organized as a clean layered application in ParcelTracking.slnx.

ParcelTracking.API # HTTP endpoints, middleware, auth, OpenAPI
ParcelTracking.Application # business logic, DTOs, validators, services
ParcelTracking.Domain # entities and enums
ParcelTracking.Infrastructure # EF Core, PostgreSQL, migrations, seeding
tests/ # unit and integration tests

Features

Core parcel operations

Address management

Tracking history

Delivery workflows

Analytics and operations

Tech stack

  • .NET 10 from ParcelTracking.API.csproj
  • ASP.NET Core Web API
  • Entity Framework Core
  • PostgreSQL via Npgsql
  • FluentValidation
  • OpenAPI + Scalar
  • xUnit, FluentAssertions, Moq
  • DotNet.Testcontainers for integration testing

Getting started

Prerequisites

  • .NET 10 SDK
  • PostgreSQL 15+ running locally or remotely
  • Optional: Docker for test and local database workflows

Local configuration

Development settings are defined in appsettings.Development.json.

Example development values:

  • Connection string: Host=localhost;Port=5432;Database=parceltracking;Username=parcel;Password=parcel123
  • API key: dev-test-key-12345

Run the API

dotnet restore
dotnet run --project ParcelTracking.API

In development, the API enables OpenAPI and Scalar through app.MapOpenApi() and app.MapScalarApiReference().

Seed demo data

Use the built-in seed mode implemented in Program.cs:

dotnet run --project ParcelTracking.API -- --seed

This populates the database with sample addresses, parcels, tracking events, content items, delivery confirmations, and parcel watchers using DataSeeder.

API access

Most endpoints require authorization through the X-Api-Key header as configured in Program.cs.

Example request header:

X-Api-Key: dev-test-key-12345

Base route

API controllers use versioned routes such as [Route("api/v{version:apiVersion}/[controller]")].

Typical base URL:

https://localhost:{port}/api/v1

Useful endpoints

AreaEndpointDescription
ParcelsPOST /api/v1/ParcelsRegister a parcel
ParcelsGET /api/v1/Parcels/{id}Get parcel details
ParcelsGET /api/v1/ParcelsSearch parcels
ParcelsPATCH /api/v1/Parcels/{id}Update status with JSON Patch
ParcelsPOST /api/v1/Parcels/{trackingNumber}/delivery-confirmationRecord delivery confirmation
AddressesGET /api/v1/AddressesList addresses
AddressesPOST /api/v1/AddressesCreate address
TrackingGET /api/v1/parcels/{parcelId}/eventsParcel event history
TrackingPOST /api/v1/parcels/{parcelId}/eventsAdd tracking event
EstimatesGET /api/v1/DeliveryEstimate?id={parcelId}Get delivery estimate
EstimatesPUT /api/v1/DeliveryEstimate/recalculate?id={parcelId}Recalculate estimate
AnalyticsGET /api/v1/Analytics/parcel-count-by-statusStatus breakdown
AnalyticsGET /api/v1/Analytics/delivery-performanceDelivery performance metrics
HealthGET /healthAggregated health report
HealthGET /health/liveLiveness probe
HealthGET /health/readyReadiness probe

Operational concerns

The API includes several production-oriented capabilities configured in Program.cs:

  • Problem details responses for errors
  • Custom exception handlers
  • HTTP request/response logging
  • CORS policy split by environment
  • Response caching for analytics and real-time endpoints
  • Fixed-window rate limiting with 429 Too Many Requests

Testing

The repository contains both unit and integration tests, with additional notes in tests/README.md.

Run all tests

dotnet test ParcelTracking.slnx

Run application unit tests

dotnet test tests/ParcelTracking.Application.Tests

Run API integration tests

dotnet test tests/ParcelTracking.API.IntegrationTests

Integration tests use PostgreSQL and DotNet.Testcontainers, while unit tests use the EF Core in-memory provider in ParcelTracking.Application.Tests.csproj.

Notes

  • Development secrets should not be committed; sensitive config files are ignored in .gitignore.
  • Current configuration is optimized for development visibility, including SQL logging and sensitive data logging in Program.cs.
  • The project already generates XML API documentation from ParcelTracking.API.csproj, which helps keep OpenAPI output descriptive.

Solution projects

About

Modern parcel tracking API built with ASP.NET Core, Entity Framework Core, and a layered architecture across API, application, domain, and infrastructure projects

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages