zTools is a RESTful API built with .NET 8 that provides a collection of utility services for common development tasks: ChatGPT/DALL-E integration, email delivery, S3-compatible file storage, Brazilian document validation (CPF/CNPJ), and string manipulation utilities.
The project follows clean architecture with separated layers and is available as a NuGet package for consuming the API from other .NET projects with strongly-typed clients and DTOs.
- π€ ChatGPT Integration - Send messages, conversations, and custom requests to OpenAI's API
- π¨ DALL-E Image Generation - Generate images with basic and advanced options
- π§ Email Service - Send emails via MailerSend with email format validation
- π File Storage - Upload and retrieve files from S3-compatible storage (DigitalOcean Spaces)
- π Document Validation - Validate Brazilian CPF and CNPJ numbers with check digit verification
- π€ String Utilities - Slug generation, number extraction, and short unique ID generation
- π¦ NuGet Package - Consume the API from other .NET projects with typed clients and DTOs
- .NET 8.0 - Cross-platform framework for building web APIs
- ASP.NET Core - Web framework with Swagger/OpenAPI documentation
- AWS SDK for S3 (4.0.6.10) - S3-compatible storage (DigitalOcean Spaces, AWS S3)
- MailerSend API - Email delivery service
- OpenAI API - ChatGPT and DALL-E integration
- SixLabors.ImageSharp (3.1.11) - Image processing
- Newtonsoft.Json (13.0.3) - JSON serialization
- Stripe.NET (48.5.0) - Payment processing
- Swashbuckle.AspNetCore (9.0.4) - Swagger/OpenAPI docs
- NoobsMuc.Coinmarketcap.Client (3.1.1) - Cryptocurrency data
- xUnit (2.5.3) - Unit testing framework
- Moq (4.20.70) - Mocking library
- RichardSzalay.MockHttp (7.0.0) - HTTP client mocking
- Docker - Multi-stage containerization
- GitHub Actions - CI/CD with automated testing, deployment, and NuGet publishing
- GitVersion - Semantic versioning
zTools/
βββ .github/workflows/ # CI/CD pipelines
β βββ deploy-prod.yml # Production deployment via SSH + Docker
β βββ publish-nuget.yml # NuGet package publishing
β βββ version-tag.yml # Semantic version tagging
βββ zTools.API/ # API Layer
β βββ Controllers/ # 5 REST controllers
β β βββ ChatGPTController # AI text & image generation
β β βββ DocumentController # CPF/CNPJ validation
β β βββ FileController # S3 file operations
β β βββ MailController # Email & validation
β β βββ StringController # String utilities
β βββ Program.cs # Host configuration
β βββ Startup.cs # Middleware & DI setup
βββ zTools.Application/ # DI wiring layer
β βββ Initializer.cs # Service registration
βββ zTools.Domain/ # Business logic layer
β βββ Services/ # Service interfaces & implementations
β β βββ ChatGPTService # OpenAI API client
β β βββ FileService # S3 storage client
β β βββ MailerSendService # Email delivery client
β βββ Utils/ # Static utility classes
β βββ DocumentoUtils # CPF/CNPJ validation
β βββ EmailValidator # Email format validation
β βββ ShuffleEx # Fisher-Yates shuffle extension
β βββ SlugHelper # URL-friendly slug generation
β βββ StringUtils # Number extraction & unique IDs
βββ zTools.Tests/ # Test suite
β βββ ACL/ # Anti-corruption layer tests
β βββ Domain/ # Service & utility tests
βββ zTools/ # NuGet package (ACL + DTO)
βββ Dockerfile # Multi-stage build
βββ docker-compose.yml # Development environment
βββ docker-compose-prod.yml # Production environment
βββ .env.example # Environment variable template
βββ GitVersion.yml # Semantic versioning config
| Project | Type | Package | Description |
|---|---|---|---|
| zTools API | REST API | - | This project β utility API server |
| zTools | NuGet | ACL clients & DTOs for consuming the API |
zTools.API (REST API)
βββ zTools.Application β DI registration
βββ zTools.Domain β Business logic & services
β βββ zTools β ACL clients & DTOs (NuGet)
βββ zTools β ACL clients & DTOs (NuGet)
Want to consume this API from another .NET project? Install the zTools package to get strongly-typed clients and DTOs with full IntelliSense support.
cp .env.example .env# MailerSend Configuration
MAILERSEND_MAILSENDER=your-email@example.com
MAILERSEND_APIURL=https://api.mailersend.com/v1/email
MAILERSEND_APITOKEN=your-mailersend-api-token
# ChatGPT Configuration
CHATGPT_APIKEY=your-openai-api-key
CHATGPT_APIURL=https://api.openai.com/v1/chat/completions
CHATGPT_MODEL=gpt-5.2
CHATGPT_IMAGEAPIURL=https://api.openai.com/v1/images/generations
# DigitalOcean Spaces (S3) Configuration
S3_ACCESSKEY=your-digitalocean-spaces-access-key
S3_SECRETKEY=your-digitalocean-spaces-secret-key
S3_ENDPOINT=https://your-space-name.nyc3.digitaloceanspaces.com- Never commit the
.envfile with real credentials - Only the
.env.exampleshould be version controlled - Change all default values before deployment
# Build and start
docker compose up -d --build
# View logs
docker compose logs -f ztools-api
# Stop
docker compose downdocker compose -f docker-compose-prod.yml up -d --build| Service | URL |
|---|---|
| API Base | http://localhost:5001 |
| Swagger UI | http://localhost:5001/swagger |
| Health Check | http://localhost:5001/ |
| Action | Command |
|---|---|
| Start services | docker compose up -d |
| Start with rebuild | docker compose up -d --build |
| Stop services | docker compose stop |
| View status | docker compose ps |
| View logs | docker compose logs -f |
| Remove containers | docker compose down |
| Full rebuild (no cache) | docker compose build --no-cache && docker compose up -d |
- .NET 8.0 SDK
- MailerSend API account
- OpenAI API account
- DigitalOcean Spaces (or S3-compatible storage) account
dotnet restoredotnet builddotnet run --project zTools.APIThe API will be available at https://localhost:9001/swagger.
All tests:
dotnet testWith coverage:
dotnet test --configuration Release --collect:"XPlat Code Coverage"Single test class:
dotnet test --filter "FullyQualifiedName~zTools.Tests.Domain.Utils.SlugHelperTest"Single test method:
dotnet test --filter "FullyQualifiedName~zTools.Tests.Domain.Utils.SlugHelperTest.TestGenerateSlug"zTools.Tests/
βββ ACL/ # Anti-corruption layer client tests
βββ Domain/
βββ Services/ # ChatGPT, FileService, MailerSend tests
βββ Utils/ # SlugHelper, StringUtils, DocumentUtils,
# EmailValidator, ShuffleEx tests
Test patterns: [Fact] for single cases, [Theory] with [InlineData] for parameterized tests. Uses Moq for dependency mocking and RichardSzalay.MockHttp for HTTP client testing.
Interactive documentation is available via Swagger UI at /swagger when running the API.
| Method | Endpoint | Description |
|---|---|---|
| POST | /ChatGPT/sendMessage |
Send a single message to ChatGPT |
| POST | /ChatGPT/sendConversation |
Send multi-message conversation |
| POST | /ChatGPT/sendRequest |
Send custom request with full parameters (model, temperature, max tokens) |
| POST | /ChatGPT/generateImage |
Generate image with DALL-E |
| POST | /ChatGPT/generateImageAdvanced |
Generate image with advanced DALL-E options |
Example β Send Message:
POST /ChatGPT/sendMessage
{
"message": "What is the capital of France?"
}
// Response: "The capital of France is Paris."Example β Send Conversation:
POST /ChatGPT/sendConversation
[
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Explain REST APIs" }
]Example β Custom Request:
POST /ChatGPT/sendRequest
{
"model": "gpt-4o",
"messages": [
{ "role": "user", "content": "Hello" }
],
"temperature": 0.7,
"maxCompletionTokens": 500
}| Method | Endpoint | Description |
|---|---|---|
| POST | /Mail/sendMail |
Send email via MailerSend |
| GET | /Mail/isValidEmail/{email} |
Validate email format |
Example β Send Email:
POST /Mail/sendMail
{
"to": "recipient@example.com",
"subject": "Test Email",
"from": "sender@example.com",
"html": "<h1>Hello World</h1>"
}| Method | Endpoint | Description |
|---|---|---|
| GET | /File/{bucketName}/getFileUrl/{fileName} |
Get public URL of a stored file |
| POST | /File/{bucketName}/uploadFile |
Upload file to S3 bucket (100MB limit) |
Example β Upload File:
POST /File/my-bucket/uploadFile
Content-Type: multipart/form-data
file: [binary data]
| Method | Endpoint | Description |
|---|---|---|
| GET | /Document/validarCpfOuCnpj/{cpfCnpj} |
Validate Brazilian CPF or CNPJ |
Example:
GET /Document/validarCpfOuCnpj/12345678900
// Response: true/false
| Method | Endpoint | Description |
|---|---|---|
| GET | /String/generateSlug/{name} |
Convert text to URL-friendly slug |
| GET | /String/onlyNumbers/{input} |
Extract only numeric characters |
| GET | /String/generateShortUniqueString |
Generate short unique Base62 ID |
Examples:
GET /String/generateSlug/Hello World 123 β "hello-world-123"
GET /String/onlyNumbers/abc123def456 β "123456"
GET /String/generateShortUniqueString β "x4k9p2"
- Triggers: Push to
main, manual dispatch - Steps:
- Run tests (restore β build β test)
- SSH into production server
- Pull latest code
- Inject secrets from GitHub Secrets
- Build and deploy with Docker Compose
- Triggers: Push to
main - Steps: Runs GitVersion to create semantic version tags
- Triggers: After successful version tagging
- Steps: Build, pack, and publish
zToolspackage to NuGet.org
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Make your changes
- Run tests (
dotnet test) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Developed by Rodrigo Landim
This project is licensed under the MIT License - see the LICENSE file for details.
- Issues: GitHub Issues
β If you find this project useful, please consider giving it a star!