Payroll Engine Backend
Part of the Payroll Engine open-source payroll automation framework.
Full documentation at payrollengine.org.
The Backend is the ASP.NET Core REST API server at the core of the Payroll Engine. It exposes the full payroll object model over HTTP, compiles and executes C# payroll scripts via Roslyn, processes payrun jobs asynchronously, and persists all results in a SQL Server database.
Contents
Prerequisites
| Requirement |
Minimum |
| .NET |
10.0 |
| SQL Server |
2019 (or Azure SQL) — or MySQL 8.4 LTS |
| Database collation |
SQL_Latin1_General_CP1_CS_AS (SQL Server) · utf8mb4_unicode_ci (MySQL) |
| Database isolation |
READ_COMMITTED_SNAPSHOT ON (SQL Server only) |
Setup
1. Create the database
SQL Server — run the provided script:
Commands\Db.ModelCreate.cmd
Or use Docker Compose (recommended for first-time setup):
see Container Setup.
Verify database settings after creation:
SELECT name, collation_name, is_read_committed_snapshot_on AS rcsi
FROM sys.databases WHERE name = 'PayrollEngine';
MySQL 8.4 LTS — run the provided script:
Database\CreateModel.MySql.cmd
This executes Create-Model.mysql.sql, which contains tables, indexes, functions, and stored procedures in the correct dependency order.
2. Configure the connection string
SQL Server — set the connection string via environment variable (recommended):
# Windows
set PayrollDatabaseConnection=Server=localhost;Database=PayrollEngine;Integrated Security=SSPI;
# Docker / Linux
export PayrollDatabaseConnection="Server=localhost;Database=PayrollEngine;User Id=sa;Password=...;TrustServerCertificate=True;"
MySQL — set connection string and provider:
set PayrollDatabaseConnection=Server=localhost;Port=3306;Database=PayrollEngine;User=root;Password=...;CharSet=utf8mb4;
set PayrollServerConfiguration__DbProvider=MySql
Or add to appsettings.json (for local development only):
{
"ConnectionStrings": {
"PayrollDatabaseConnection": "Server=localhost;Database=PayrollEngine;Integrated Security=SSPI;"
}
}
Store sensitive configuration in User Secrets for local development.
3. Start the server
# Run from the binary output folder
dotnet PayrollEngine.Backend.Server.dll --urls=https://localhost:44354/
# Run from the project folder (Backend.Server/)
dotnet run --urls=https://localhost:44354/
# Visual Studio
Open PayrollEngine.Backend.sln and start with the debugger
The API is accessible at the configured URL. When EnableSwagger is set to true, the Swagger UI is available at /swagger.
Open API
The Payroll Engine API supports the Open API specification and describes the interface to the Swagger tool. The document REST Service Endpoints describes the available endpoints.
Payroll Engine swagger.json
Key Endpoints
| Endpoint |
Method |
Description |
.../payruns/jobs |
POST |
Start a payrun job (asynchronous, returns HTTP 202 with location header) |
.../payruns/jobs/preview |
POST |
Synchronous single-employee payrun preview without persisting results |
.../employees/bulk |
POST |
Bulk employee creation via SqlBulkCopy for high-throughput import |
API Versioning
Starting with the 1.0 release, no version header is required in the HTTP request. Future major versions will require the HTTP header X-Version with the version number.
API Content Type
The Payroll REST API supports HTTP requests in JSON format.
Authentication
The API supports three authentication modes, configured via Authentication:Mode in appsettings.json:
None — No authentication. All requests are accepted. Development/internal use only.
ApiKey — Static API key. The client must send the key in the Api-Key HTTP header. The key is resolved in the following order:
- Environment variable
PayrollApiKey
- Configuration value
Authentication:ApiKey in appsettings.json
OAuth — OAuth 2.0 / JWT Bearer token. Requires Authority and Audience configuration. The client must send a valid Bearer token in the Authorization header. Authority and audience are validated at startup to prevent token confusion.
When authentication is active and Swagger is enabled, Swagger UI requires the corresponding credentials.
Application Settings
The server configuration file appsettings.json contains the following settings:
General
| Setting |
Description |
Type |
Default |
StartupCulture |
Culture of the backend process (RFC 4646) |
string |
System culture |
HttpsRedirection |
Enable HTTPS redirection |
bool |
false |
LogHttpRequests |
Log HTTP requests to log file |
bool |
false |
Serilog |
Logger settings |
Serilog |
file and console log |
Swagger / OpenAPI
| Setting |
Description |
Type |
Default |
EnableSwagger |
Enable Swagger UI and JSON endpoint 1) |
bool |
false |
DarkTheme |
Use Swagger dark theme |
bool |
false |
VisibleControllers |
Visible API controllers 2) 3) |
string[] |
all |
HiddenControllers |
Hidden API controllers 2) 3) |
string[] |
none |
XmlCommentFileNames |
XML documentation files for Swagger |
string[] |
none |
Authentication
| Setting |
Description |
Type |
Default |
Authentication:Mode |
Authentication mode: None, ApiKey, OAuth |
enum |
None |
Authentication:ApiKey |
Static API key (only for mode ApiKey) |
string |
none |
Authentication:OAuth:Authority |
Token authority / issuer URL |
string |
none |
Authentication:OAuth:Audience |
Expected audience claim |
string |
none |
Authentication:OAuth:RequireHttpsMetadata |
Require HTTPS metadata discovery |
bool |
true |
Authentication:OAuth:ClientSecret |
OAuth client secret for Swagger UI token flow 9) |
string |
none |
Audit Trail
| Setting |
Description |
Type |
Default |
AuditTrail:Script |
Audit trail for scripts |
bool |
false |
AuditTrail:Lookup |
Audit trail for lookups and lookup values 4) |
bool |
false |
AuditTrail:Input |
Audit trail for cases, case fields and case relations |
bool |
false |
AuditTrail:Payrun |
Audit trail for collectors and wage types |
bool |
false |
AuditTrail:Report |
Audit trail for reports, templates and parameters |
bool |
false |
Scripting & Compilation
| Setting |
Description |
Type |
Default |
InitializeScriptCompiler |
Initialize Roslyn at startup to reduce first execution time |
bool |
false |
DumpCompilerSources |
Store compiler source files to disk 5) |
bool |
false |
ScriptSafetyAnalysis |
Static safety analysis of scripts during compilation 8) |
bool |
false |
AssemblyCacheTimeout |
Timeout for cached script assemblies |
timespan |
30 minutes |
Database & Timeouts
| Setting |
Description |
Type |
Default |
DbCollation |
Expected database collation, verified on startup 10) |
string |
SQL_Latin1_General_CP1_CS_AS |
DbCommandTimeout |
Database command timeout |
timespan |
2 minutes |
DbTransactionTimeout |
Database transaction timeout |
timespan |
10 minutes |
WebhookTimeout |
Webhook HTTP request timeout |
timespan |
1 minute |
WebhookTracking |
Webhook message tracking: None, Notification (notification webhooks), All (plus scripting webhook calls, diagnostics only) |
enum |
Notification |
DataProtectionKeyPath |
Persistent key ring directory (encrypts the webhook secrets) |
string |
host default |
FunctionLogTimeout |
Timeout threshold for logging long function executions 11) |
timespan |
off |
Payrun Processing