Skip to content

GrydReports Module ​

GrydReports is a comprehensive report generation module for .NET applications. It provides on-demand and scheduled report generation in multiple formats (PDF, Excel, CSV) with pluggable templates, data sources, delivery channels, and multi-tenancy support.

✨ Features ​

FeatureDescription
📄 Multi-Format OutputGenerate formats for registered renderers; shipped renderers provide PDF, Excel, and CSV
🧩 Pluggable TemplatesCode-first template definition with type-safe data and parameters
📊 Data SourcesTyped data sources feed a materialized result to renderers; the streaming interface is not consumed by the generation path
⏱️ GenerationOn-demand synchronous generation and optional recurring background schedules
📅 Scheduling (Optional)Cron-based recurring generation via optional GrydReports.Scheduling.GrydJobs integration
📬 DeliveryBuilt-in webhook; email is a placeholder unless the host supplies a delivery provider
💾 File StorageGenerated files stored in GrydFiles: server-side hash and type check, retention, short-lived download URLs
🏢 Multi-TenancyTenant filtering for executions and schedules; generated files retain execution tenant ownership
🔍 ObservabilityOpenTelemetry metrics and activity tracing
🎣 Lifecycle FiltersChain-of-responsibility hooks at every stage of generation

The Permissions and GlobalReports option declarations do not currently enforce template authorization or bypass tenant filters. Apply host authorization policies and retain explicit tenant ownership. The report-definition registry is shared; generated execution and file records retain tenant scope.

📦 Packages ​

GrydReports follows Clean Architecture with modular packages:

📦 GrydReports
├── GrydReports.Core                  # Domain entities, abstractions, DTOs
├── GrydReports.Application           # CQRS commands, queries, MediatR handlers
├── GrydReports.Infrastructure        # EF Core, generation, GrydFiles storage, webhook and email placeholder
├── GrydReports.Scheduling.GrydJobs   # Optional recurring scheduling integration with GrydJobs
├── GrydReports.Infrastructure.QuestPdf   # QuestPDF renderer
├── GrydReports.Infrastructure.ClosedXml  # ClosedXML (Excel) renderer
├── GrydReports.Infrastructure.CsvHelper  # CsvHelper (CSV) renderer
├── GrydReports.API                   # REST controllers (15 endpoints)
└── GrydReports (meta-package)        # All packages combined

🚀 Quick Start ​

Installation ​

bash
# Install Reports core stack and the PDF renderer (without requiring Jobs)
dotnet add package GrydReports
dotnet add package GrydReports.Infrastructure.QuestPdf
bash
# Core abstractions only
dotnet add package GrydReports.Core

# With specific renderers
dotnet add package GrydReports.Infrastructure.QuestPdf
dotnet add package GrydReports.Infrastructure.ClosedXml
dotnet add package GrydReports.Infrastructure.CsvHelper

# Optional: only if you need recurring schedules with GrydJobs
dotnet add package GrydReports.Scheduling.GrydJobs

Basic Setup ​

Use the maintained gryd-api template for the complete host composition, including API versioning, authentication, GrydFiles, middleware, and migrations. Add the Reports registrations inside its service-registration section:

csharp
using Gryd.Infrastructure.Extensions;
using GrydReports;
using GrydReports.Core.Configuration;
using GrydReports.Infrastructure.QuestPdf;
using GrydFiles;
using GrydFiles.Infrastructure.ClamAv;
using Microsoft.EntityFrameworkCore;

// Generated files use the host's GrydFiles profile and object-storage configuration.
builder.Services.AddGrydObjectStorage(builder.Configuration);
builder.Services.AddGrydFiles(builder.Configuration);
builder.Services.AddGrydFilesClamAv(builder.Configuration);
builder.Services.AddGrydReportsQuestPdf();

builder.Services.AddGrydReports(
    builder.Configuration,
    db => db.UseNpgsql(builder.Configuration.GetConnectionString("GrydReports")));
builder.Services.Configure<GrydReportsOptions>(options =>
    options.TemplateAssemblies.Add(typeof(Program).Assembly));

The complete host setup and application pipeline are in the maintained gryd-api template. Recurring schedules are optional and require GrydJobs plus the GrydReports.Scheduling.GrydJobs package.

The shipped PDF, Excel, and CSV packages register renderers. ReportFormat.Html is an enum value; this release does not ship an HTML renderer. A format is usable only when its renderer is registered. The SalesDataSource below uses an application-owned AppDbContext with a Sales DbSet.

Create Your First Report ​

csharp
using GrydReports.Core.Abstractions;
using GrydReports.Core.Enums;
using GrydReports.Core.Models;
using Microsoft.EntityFrameworkCore;

// SalesData, SalesParameters, SaleItem and AppDbContext belong to the host.
// 1. Define the data model
public class SalesData
{
    public string Period { get; set; }
    public List<SaleItem> Items { get; set; }
    public decimal Total { get; set; }
}

// 2. Implement the data source
public class SalesDataSource : IReportDataSource<SalesData, SalesParameters>
{
    private readonly AppDbContext _db;

    public SalesDataSource(AppDbContext db) => _db = db;

    public async Task<SalesData> FetchDataAsync(
        SalesParameters parameters, CancellationToken ct)
    {
        var items = await _db.Sales
            .Where(s => s.Date >= parameters.FromDate && s.Date <= parameters.ToDate)
            .ToListAsync(ct);

        return new SalesData
        {
            Period = $"{parameters.FromDate:MMM yyyy}",
            Items = items,
            Total = items.Sum(i => i.Amount)
        };
    }
}

// 3. Define the template
public class MonthlySalesTemplate : IReportTemplate<SalesData>
{
    public string TemplateId => "monthly-sales";
    public string DisplayName => "Monthly Sales Report";
    public string? Description => "Summarizes sales by period";
    public IReadOnlyList<ReportFormat> SupportedFormats =>
        [ReportFormat.Pdf];

    public ReportMetadata GetMetadata(SalesData data) => new()
    {
        Title = $"Sales Report - {data.Period}",
        Author = "Finance Department"
    };
}

// Register app-owned data-source and template services for ReportTemplateRegistry.
builder.Services.AddScoped<IReportDataSource<SalesData, SalesParameters>, SalesDataSource>();
builder.Services.AddSingleton<IReportTemplate<SalesData>, MonthlySalesTemplate>();

See Getting Started for the full walkthrough.

🏗️ Architecture ​

┌────────────────────────────────────────────────┐
│                GrydReports.API                 │
│     ReportsController  SchedulesController     │
├────────────────────────────────────────────────┤
│             GrydReports.Application            │
│       Commands + Queries (MediatR/CQRS)        │
├────────────────────────────────────────────────┤
│               GrydReports.Core                 │
│  Abstractions │ Entities │ DTOs │ Enums        │
├────────────────────────────────────────────────┤
│           GrydReports.Infrastructure           │
│  EF Core │ FileStore │ Delivery │ Scheduling   │
├──────────┬──────────────┬──────────────────────┤
│ QuestPDF │  ClosedXML   │    CsvHelper         │
│  (PDF)   │   (Excel)    │     (CSV)            │
└──────────┴──────────────┴──────────────────────┘

📋 API Endpoints ​

MethodEndpointDescription
GET/api/v1/reportsList available report templates
GET/api/v1/reports/historyPaginated execution history
GET/api/v1/reports/{id}Get execution details
POST/api/v1/reports/generateGenerate report synchronously
POST/api/v1/reports/generate-asyncBuilt-in response: 503 unavailable; hosts may provide a durable handler
GET/api/v1/reports/{id}/downloadDownload generated file
DELETE/api/v1/reports/{id}Delete execution & file
GET/api/v1/reports/schedulesList schedules
GET/api/v1/reports/schedules/{id}Get schedule details
POST/api/v1/reports/schedulesCreate recurring schedule
PUT/api/v1/reports/schedules/{id}Update schedule
DELETE/api/v1/reports/schedules/{id}Delete schedule
POST/api/v1/reports/schedules/{id}/triggerTrigger immediate execution
POST/api/v1/reports/schedules/{id}/pausePause schedule
POST/api/v1/reports/schedules/{id}/resumeResume schedule

Released under the MIT License.