The SGJ Consent Management API is a comprehensive .NET-based solution designed for Sagicor Group Jamaica Limited to manage various types of client consents, including data sharing consents, marketing consents, and data controller enrollments. This API provides a robust framework for tracking, managing, and validating consent operations in compliance with data privacy regulations.
- Framework: .NET 8.0
- Architecture: Clean Architecture with CQRS pattern (Command Query Responsibility Segregation)
- API Design: RESTful API with OpenAPI/Swagger documentation
- Database: Microsoft SQL Server with Entity Framework Core
- Authentication/Authorization: JWT-based authentication
- Messaging Pattern: Mediator pattern using MediatR
- Service Discovery: Consul integration
- Monitoring: Application Insights, Grafana, InfluxDB, Telegraf
- Containerization: Docker support with multi-stage builds
- Testing: xUnit for unit and integration tests
- Code Quality: SonarQube integration
- Deployment: Kubernetes (AKS) support
- Data Sharing Consent Management: Create, retrieve, update, and withdraw data sharing consents between entities
- Marketing Consent Management: Manage marketing preferences and consent for clients
- Data Controller Enrollment: Register and manage data controllers
- Entity Management: Track and manage entities involved in consent operations
- Client Management: Client registration and identification
- Audit Trail: Comprehensive tracking of all consent-related operations
- API Versioning: Support for API versioning to maintain backward compatibility
The project follows Clean Architecture principles with the following layers:
- Api: API controllers, middleware, and configuration
- Api.Application: Application services, commands, queries, and handlers (CQRS implementation)
- Api.Domain: Domain entities, repositories interfaces, and domain services
- Api.Infrastructure: Database context, repository implementations, migrations, and external service integrations
- Api.Crosscutting: Shared components, enums, constants, and error handling
- Api.Dto: Data transfer objects for API requests and responses
- Api.Test: Unit and integration tests
To start the application in development mode:
dotnet run --verbosity normal --project ./src/Api/Api.csprojAfter creating a new entity, add a DbSet<E> entry in ApplicationDatabaseContext for migrations to work.
Create the initial migration:
dotnet ef migrations add InitialCreate --project src/Api.Infrastructure/Api.Infrastructure.csproj --startup-project src/Api/Api.csprojAdd a new migration:
dotnet ef migrations add NameOfNewMigrationHere --project src/Api.Infrastructure/Api.Infrastructure.csproj --startup-project src/Api/Api.csprojApply database migrations:
dotnet ef database update --project src/Api.Infrastructure/Api.Infrastructure.csproj --startup-project src/Api/Api.csprojGenerate migration scripts:
dotnet ef migrations script --project src/Api.Infrastructure/Api.Infrastructure.csproj --startup-project src/Api/Api.csproj -o 0000-migration.sqlTo build the artifacts and optimize the application for production:
cd ./src/Api
rm -rf ./src/Api/wwwroot
dotnet publish --verbosity normal -c Release -o ./app/out ./Api.csprojThe ./src/Api/app/out directory will contain your application DLL and its dependencies.
Build a Docker image:
docker build -f ./Dockerfile -t consent-api .Run the Docker container:
docker run -p 8080:8080 consent-apiOr use Docker Compose:
docker compose -f ./docker/app.yml build
docker compose -f ./docker/app.yml upRun tests:
dotnet test --verbosity normalFormat the .NET code:
dotnet formatRun SonarQube in a container:
docker compose -f ./docker/sonar.yml up -dThen run the analysis script:
./SonarAnalysis.ps1Visit http://localhost:9001 to view the results.
Set up monitoring:
docker compose -f ./docker/monitoring.yml up -dAccess Grafana at http://localhost:3000
The project includes Kubernetes deployment configurations in the aks-deployment directory for deploying to Azure Kubernetes Service (AKS).
The API is documented using OpenAPI/Swagger. When running the application, access the Swagger UI at /swagger endpoint to explore and test the API endpoints.