Skip to content

Media2A/CodeLogic.Libs

Repository files navigation

CodeLogic Libraries

CodeLogic Libraries

License: MIT

Production-ready .NET 10 library integrations for CodeLogic 4. Each library is a self-contained ILibrary implementation with auto-generated configuration, health checks, and lifecycle management.

Libraries

Package Version Description
CodeLogic.Common NuGet Hashing, caching, imaging (SkiaSharp), compression, file utilities
CodeLogic.MySQL2 NuGet MySQL ORM with LINQ query builder, table sync, migrations, result caching
CodeLogic.SQLite NuGet SQLite with connection pooling, LINQ queries, table sync
CodeLogic.PostgreSQL NuGet PostgreSQL with multi-database support and LINQ query builder
CodeLogic.Mail NuGet SMTP/IMAP email with HTML template engine
CodeLogic.StorageS3 NuGet Amazon S3 / Cloudflare R2 / MinIO object storage
CodeLogic.SocialConnect NuGet Discord webhooks + Steam Web API (profiles, bans, games)
CodeLogic.NetUtils NuGet DNS lookups, DNSBL blacklist checking, IP geolocation (MaxMind)
CodeLogic.GameNetQuery NuGet Game server queries — Valve RCON, Source UDP, Minecraft
CodeLogic.SystemStats NuGet Cross-platform CPU, memory, process monitoring
CodeLogic.GitHelper NuGet Git repository management via libgit2
CodeLogic.TwoFactorAuth NuGet TOTP 2FA with QR code generation

All packages target .NET 10 and depend on CodeLogic 3.x or 4.x (range [3.2.0, 5.0.0)).

Quick Start

1. Install

# Install the core framework
dotnet add package CodeLogic

# Install the libraries you need
dotnet add package CodeLogic.MySQL2
dotnet add package CodeLogic.Mail

2. Load in your application

var result = await CodeLogic.InitializeAsync(opts =>
{
    opts.FrameworkRootPath = "data/codelogic";
    opts.AppVersion = "1.0.0";
});

// Load the libraries you installed
await Libraries.LoadAsync<MySQL2Library>();
await Libraries.LoadAsync<MailLibrary>();

CodeLogic.RegisterApplication(new MyApplication());
await CodeLogic.ConfigureAsync();
await CodeLogic.StartAsync();

3. Configure

On first run, each library auto-generates its config file under data/codelogic/Libraries/:

data/codelogic/Libraries/
├── CL.MySQL2/config.mysql2.json        ← database connection
├── CL.Mail/config.mail.json            ← SMTP settings
└── ...

Edit the JSON files to configure. Validation runs on startup — invalid config stops the boot with a clear error.

4. Use

// MySQL2 — LINQ query builder with optional result caching
var users = await db.Query<UserRecord>()
    .Where(u => u.IsActive && u.Role == "admin")
    .OrderBy(u => u.Name)
    .WithCache(TimeSpan.FromMinutes(5))
    .ToPagedListAsync(page: 1, pageSize: 20);

// Mail — send templated email
await mailService.SendAsync("user@example.com", "Welcome!", "templates/welcome.html", model);

// Storage — upload to S3/R2
var url = await storage.UploadAsync("avatars", "user-123.webp", stream, "image/webp");

// Health — check all loaded libraries
var report = await CodeLogic.HealthCheckAsync();

How Libraries Work

Every CodeLogic library follows the same pattern:

  1. ILibrary implementation — defines the lifecycle hooks
  2. Config model (ConfigModelBase) — auto-generated JSON, validated on startup
  3. Service classes — the actual functionality, accessed via the library instance
  4. Health check — reports Healthy/Degraded/Unhealthy via HealthCheckAsync()

Libraries are loaded before your application starts and stopped after it stops. This guarantees your application code can always rely on database connections, mail services, etc. being available.

// Access a loaded library anywhere in your code
var mysql = Libraries.Get<MySQL2Library>();
var repo = mysql.GetRepository<UserRecord>();

Documentation

Requirements

License

MIT — see LICENSE

About

CodeLogic3 library suite — CL.* integrations for MySQL, PostgreSQL, SQLite, S3, Mail, SystemStats, TwoFactorAuth, SocialConnect, NetUtils, and more

Resources

License

Stars

Watchers

Forks

Contributors

Languages