This repository contains the backend API implementation for the PCMS Outlook Add-In, built using .NET 8 with Clean Architecture principles. The API acts as a Backend-for-Frontend (BFF) and communicates with downstream PCMS Core APIs.
This service does not own a database. Instead, it focuses on:
- Authentication & Authorization (Advanced Identity / Keycloak JWT)
- Calling PCMS Core APIs and Microsoft Graph API
- Data mapping & transformation
- Caching (Redis cache-aside pattern)
- Document processing via Azure Service Bus
- Logging (Serilog + Application Insights)
- Resilience (Polly)
- Global exception handling
- DTO validation (FluentValidation)
- API Versioning
This project follows standard 4-layer Clean Architecture:
Presentation (API)
↓
Application (Services & Interfaces)
↓
Domain (Models, DTOs, Exceptions, Constants)
↓
Infrastructure (External Services, Caching, Auth, Repositories)
Key Rules:
- Domain has zero dependencies.
- Application depends only on Domain.
- Infrastructure implements Application interfaces.
- API references Application + Infrastructure.
PCMS.OutlookAddIn.sln
│
├── src/
│ ├── PCMS.OutlookAddIn.Api → Presentation Layer (Controllers, Middleware, DI, Auth config)
│ ├── PCMS.OutlookAddin.Application → Application Layer (Services, Interfaces, Mappers, Validators)
│ ├── PCMS.OutlookAddin.Domain → Domain Layer (Models, DTOs, Exceptions, Constants)
│ ├── PCMS.OutlookAddin.Infrastructure → Infrastructure Layer (HTTP clients, Redis, SQL repos, Graph API, auth)
│ └── PCMS.OutlookAddin.Functions → Azure Functions (Service Bus document processing)
│
└── tests/
├── PCMS.OutlookAddIn.Api.Tests
├── PCMS.OutlookAddIn.Application.Tests
├── PCMS.OutlookAddin.Domain.Tests
├── PCMS.OutlookAddIn.Infrastructure.Tests
└── PCMS.OutlookAddin.Functions.Tests
| Layer | Responsibility |
|---|---|
| API | Controllers, middleware pipeline, DI registration, API versioning, Swagger |
| Application | Business logic services, interface contracts, mappers, FluentValidation validators |
| Domain | Models, DTOs, domain exceptions, constants — no external dependencies |
| Infrastructure | PCMS Core API clients, Redis caching, SQL repositories (Dapper), Microsoft Graph API, Advanced Identity token validation, Service Bus publisher |
| Functions | Azure Function triggered by Service Bus — fetches email via Graph, posts to PCMS |
Core Framework
- .NET 8.0
- ASP.NET Core Web API
- C#
Azure Services
- Azure Functions (Isolated Worker) — Service Bus triggered document processing
- Azure Service Bus — Message queuing for async email saving
- Azure Key Vault — Secrets management (connection strings, client secrets)
- Application Insights — Monitoring and telemetry
- Azure Redis Cache — Cache-aside pattern for external API responses
Libraries & Patterns
- API Versioning (
Asp.Versioning) - FluentValidation — Request validation
- Serilog — Structured logging
- Polly — HTTP client resilience (timeouts)
- Dapper — Lightweight SQL data access
- MSAL (Microsoft.Identity.Client) — Graph API token acquisition
- StackExchange.Redis — Redis distributed cache
Testing
- xUnit — Unit testing framework
- Moq — Mocking framework
- FluentAssertions — Assertion library
Restore dependencies
dotnet restoreBuild the solution
dotnet buildRun the API project
dotnet run --project src/PCMS.OutlookAddIn.ApiRun unit tests
dotnet testSwagger UI is available at https://localhost:{port}/swagger when running in Development or QA environments.
| Project | Tests |
|---|---|
| Domain.Tests | 159 |
| Application.Tests | 249 |
| Api.Tests | 407 |
| Infrastructure.Tests | 486 |
| Functions.Tests | 44 |
| Total | 1,345 |