A comprehensive, production-ready .NET 8 Web API for a crowdfunding platform built with Clean Architecture principles.
- User Management: Registration, authentication, and role-based authorization
- Campaign Management: Create, update, and manage crowdfunding campaigns
- Pledge System: Support campaigns with flexible reward tiers
- Payment Processing: Simulated payment processing with success/failure scenarios
- Admin Panel: Administrative controls for platform management
- Clean Architecture: Separation of concerns with Domain, Application, Infrastructure, and API layers
- CQRS Pattern: Command Query Responsibility Segregation using MediatR
- JWT Authentication: Secure token-based authentication with refresh tokens
- Entity Framework Core: Code-first approach with SQL Server
- AutoMapper: Object-to-object mapping
- FluentValidation: Comprehensive input validation
- Serilog: Structured logging to console and files
- Swagger/OpenAPI: Interactive API documentation
- Docker Support: Containerized deployment
- Unit & Integration Tests: Comprehensive test coverage
CrowdfundingAPI/
βββ src/
β βββ CrowdfundingAPI.API/ # Controllers, Middleware, Program.cs
β βββ CrowdfundingAPI.Application/ # Services, DTOs, Commands/Queries, Handlers
β βββ CrowdfundingAPI.Domain/ # Entities, Interfaces, Enums
β βββ CrowdfundingAPI.Infrastructure/ # DbContext, Repositories, External Services
βββ tests/
β βββ CrowdfundingAPI.UnitTests/
β βββ CrowdfundingAPI.IntegrationTests/
βββ docker-compose.yml
βββ Dockerfile
βββ README.md
- .NET 8 - Latest .NET framework
- ASP.NET Core Web API - RESTful API framework
- Entity Framework Core - ORM for database operations
- SQL Server - Primary database
- JWT Bearer Authentication - Secure authentication
- AutoMapper - Object mapping
- MediatR - CQRS implementation
- FluentValidation - Input validation
- Serilog - Structured logging
- xUnit - Unit testing framework
- Moq - Mocking framework
- Docker - Containerization
- Swagger/OpenAPI - API documentation
- .NET 8 SDK
- SQL Server (or Docker for containerized setup)
- Docker Desktop (optional, for containerized deployment)
-
Clone the repository
git clone <repository-url> cd CrowdfundingAPI
-
Update connection string Edit
src/CrowdfundingAPI.API/appsettings.json
:{ "ConnectionStrings": { "DefaultConnection": "Server=localhost;Database=CrowdfundingDB;Trusted_Connection=true;TrustServerCertificate=true;" } }
-
Restore packages and build
dotnet restore dotnet build
-
Run database migrations
cd src/CrowdfundingAPI.API dotnet ef database update
-
Run the application
dotnet run
-
Access Swagger UI Navigate to
https://localhost:7001
orhttp://localhost:5001
-
Using Docker Compose (Recommended)
docker-compose up -d
This will start both the API and SQL Server containers.
-
Access the API
- API:
http://localhost:8080
- Swagger UI:
http://localhost:8080
- API:
POST /api/v1/auth/register
- Register new userPOST /api/v1/auth/login
- User loginPOST /api/v1/auth/refresh
- Refresh JWT tokenPOST /api/v1/auth/forgot-password
- Request password resetPOST /api/v1/auth/reset-password
- Reset passwordPOST /api/v1/auth/verify-email
- Verify email address
GET /api/v1/campaigns
- Get campaigns (with filtering and pagination)POST /api/v1/campaigns
- Create new campaignGET /api/v1/campaigns/{id}
- Get campaign by IDPUT /api/v1/campaigns/{id}
- Update campaignDELETE /api/v1/campaigns/{id}
- Cancel campaignPOST /api/v1/campaigns/{id}/pledge
- Create pledgeGET /api/v1/campaigns/{id}/pledges
- Get campaign pledgesPOST /api/v1/campaigns/{id}/updates
- Post campaign updateGET /api/v1/campaigns/{id}/analytics
- Get campaign analytics
GET /api/v1/pledges/my-pledges
- Get user's pledgesGET /api/v1/pledges/{id}
- Get pledge by IDPUT /api/v1/pledges/{id}
- Update pledgeDELETE /api/v1/pledges/{id}
- Cancel pledge
GET /api/v1/admin/campaigns/pending
- Get pending campaignsPUT /api/v1/admin/campaigns/{id}/approve
- Approve campaignPUT /api/v1/admin/campaigns/{id}/reject
- Reject campaignGET /api/v1/admin/users
- Get all usersPUT /api/v1/admin/users/{id}/ban
- Ban userGET /api/v1/admin/analytics/overview
- Platform analytics
dotnet test tests/CrowdfundingAPI.UnitTests/
dotnet test tests/CrowdfundingAPI.IntegrationTests/
dotnet test --collect:"XPlat Code Coverage"
Configure JWT authentication in appsettings.json
:
{
"JwtSettings": {
"Secret": "YourSecretKeyHere",
"Issuer": "CrowdfundingAPI",
"Audience": "CrowdfundingAPI",
"ExpiryInMinutes": 60
}
}
Serilog is configured to log to both console and files:
- Console output for development
- Rolling file logs in
/logs
directory - Structured JSON logging for production
The application includes seed data:
- Admin user:
admin@crowdfunding.com
- Campaign owner:
creator@example.com
- Regular user:
backer@example.com
- Sample campaign with reward tiers
- JWT Authentication with refresh tokens
- Role-based Authorization (User, CampaignOwner, Admin)
- Input Validation using FluentValidation
- SQL Injection Prevention through Entity Framework
- CORS Configuration for frontend integration
- HTTPS Enforcement in production
- Password Hashing using ASP.NET Identity
- Auto-calculate funding percentage
- Mark campaigns as "Funded" when goal is reached
- Auto-close campaigns past deadline
- Handle over-funding scenarios
- Validate pledge amounts against reward tiers
- Check campaign is still active before accepting pledges
- Simulate payment processing with random success/failure
- Update campaign current amount on successful pledges
- Search by title, description, creator name
- Filter by category, status, funding percentage
- Sort by creation date, deadline, funding amount
- Pagination with skip/take parameters
- Environment Variables: Use environment-specific configurations
- Database: Use managed SQL Server instance
- Logging: Configure centralized logging (e.g., Application Insights)
- Monitoring: Implement health checks and monitoring
- Security: Use HTTPS, secure JWT secrets, implement rate limiting
- Scaling: Consider load balancing and database optimization
The API includes health check endpoints:
/health
- Basic health check- Database connectivity check included
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Contact: support@crowdfunding.com
Built with β€οΈ using .NET 8 and Clean Architecture principles