Skip to content
/ dotnet-boilterplate Public template

A modern boilerplate for authentication and session management using ADO.NET and PostgreSQL.

License

Notifications You must be signed in to change notification settings

Xjectro/dotnet-boilterplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

31 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

.NET Boilerplate

A production-ready .NET 10 boilerplate with microservices architecture, featuring Cassandra, Redis, RabbitMQ, and comprehensive service implementations.

πŸš€ Features

  • βœ… RESTful API with Swagger/ReDoc documentation
  • βœ… Apache Cassandra for distributed NoSQL storage
  • βœ… Redis for high-performance caching
  • βœ… RabbitMQ for asynchronous message processing
  • βœ… JWT Authentication for secure API access
  • βœ… Rate Limiting with multiple strategies (Fixed Window, Token Bucket, Sliding Window)
  • βœ… Mail Service with queue-based async sending
  • βœ… Media Service with MinIO object storage and ImageSharp optimization
  • βœ… Worker Service for background job processing
  • βœ… Logging with Serilog and Seq dashboard
  • βœ… Docker containerization with Docker Compose
  • βœ… Health Checks for all services
  • βœ… BCrypt password hashing
  • βœ… Repository Pattern with dependency injection

πŸ“‹ Prerequisites

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Client    │────▢│   API    │────▢│ Cassandra β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”
                    β”‚           β”‚
              β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”
              β”‚  Redis   β”‚ β”‚ RabbitMQ β”‚
              β”‚  Cache   β”‚ β”‚  Queue   β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
                    β”‚           β”‚
              β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
              β”‚  MinIO   β”‚ β”‚  Worker   β”‚
              β”‚  Media   | β”‚  Service  β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Using Docker (Recommended)

# Clone the repository
git clone https://github.com/Xjectro/dotnet-boilterplate.git
cd dotnet-boilterplate

# Start development environment
make dev

# Access the application
# API: http://localhost:5143
# Swagger: http://localhost:5143/swagger
# MinIO Console: http://localhost:9001 (minioadmin/minioadmin123)
# RabbitMQ Management: http://localhost:15672 (admin/admin123)

Local Development

# Restore dependencies
dotnet restore

# Run the application
dotnet run

# Or use the Makefile
make run

πŸ“š Documentation

Comprehensive documentation is available in the Documentation folder:

πŸ› οΈ Configuration

Environment Variables

Key configuration can be set via environment variables:

# JWT
JwtSettings__Secret=your-secret-key
JwtSettings__ExpiryMinutes=60

# Redis
Redis__Host=redis:6379

# Cassandra
Cassandra__ContactPoints=cassandra
Cassandra__Port=9042
Cassandra__Keyspace=default_keyspace

# RabbitMQ
RabbitMq__Host=rabbitmq
RabbitMq__Port=5672
RabbitMq__Username=admin
RabbitMq__Password=admin123

# Media (MinIO)
Media__Endpoint=http://minio:9000
Media__AccessKey=minioadmin
Media__SecretKey=minioadmin123
Media__BucketName=uploads
Media__PublicUrl=http://localhost:9000
Media__MaxFileSize=10485760

# Mail
Mail__SmtpHost=smtp.gmail.com
Mail__SmtpPort=587
Mail__SmtpUsername=your-email@gmail.com
Mail__SmtpPassword=your-app-password

See appsettings.Development.json for all available options.

πŸ“‘ API Endpoints

Health Check

GET /health

Mail Service

POST /api/mail/send
Content-Type: application/json

{
  "to": ["user@example.com"],
  "subject": "Welcome!",
  "body": "<h1>Hello World</h1>",
  "isHtml": true
}

Media Service

# Upload file
POST /api/media/upload?folder=images&generateThumbnail=true
Content-Type: multipart/form-data

# Get file
GET /api/media/{fileName}

# Delete file
DELETE /api/media/{fileName}

# List files
GET /api/media/list?folder=images

Client Management

GET /api/client
POST /api/client
PUT /api/client/{id}
DELETE /api/client/{id}

Visit /swagger for complete API documentation.

πŸ—οΈ Project Structure

β”œβ”€β”€ Source/
β”‚   β”œβ”€β”€ Configurations/      # Configuration classes
β”‚   β”œβ”€β”€ Controllers/         # API controllers
β”‚   β”œβ”€β”€ DTOs/               # Data transfer objects
β”‚   β”œβ”€β”€ Extensions/         # Service extensions
β”‚   β”œβ”€β”€ Models/             # Database models
β”‚   β”œβ”€β”€ Repositories/       # Data access layer
β”‚   └── Services/           # Business logic
β”‚       β”œβ”€β”€ BCryptService/
β”‚       β”œβ”€β”€ CassandraService/
β”‚       β”œβ”€β”€ JwtService/
β”‚       β”œβ”€β”€ MailService/
β”‚       β”œβ”€β”€ RabbitMqService/
β”‚       β”œβ”€β”€ RedisService/
β”‚       └── WorkerService/
β”œβ”€β”€ Docker/                 # Docker compose files
β”œβ”€β”€ Documentation/          # Detailed documentation
β”œβ”€β”€ Api.csproj             # Project file
β”œβ”€β”€ Program.cs             # Application entry point
└── README.md

πŸ”§ Development

Build

dotnet build

Run Tests

dotnet test

Format Code

dotnet format

🐳 Docker Commands

# Start development environment (with build)
make dev

# Start production environment (detached with build)
make prod

# View logs
docker compose -f Docker/docker-compose.dev.yml logs -f

# Stop services
docker compose -f Docker/docker-compose.dev.yml down

# Stop and remove volumes
docker compose -f Docker/docker-compose.dev.yml down -v

πŸ“Š Services

Cassandra

  • Port: 9042
  • Keyspace: default_keyspace
  • Replication: SimpleStrategy (Dev)

Redis

  • Port: 6379
  • Persistence: AOF enabled

RabbitMQ

API

πŸ” Security

  • JWT token-based authentication
  • BCrypt password hashing
  • Environment variable configuration
  • Docker secrets support
  • HTTPS ready

🚦 Health Checks

All services include health checks:

# API Health
curl http://localhost:5143/health

# Docker health status
docker ps --format "table {{.Names}}\t{{.Status}}"

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENCE file for details.

πŸ“§ Contact

For questions or support, please open an issue on GitHub.

πŸ™ Acknowledgments

  • .NET Team for the amazing framework
  • Docker for containerization
  • Apache Cassandra for distributed database
  • Redis for caching
  • RabbitMQ for message queuing

Built with ❀️ using .NET 10