A production-ready, enterprise-level Customer Relationship Management (CRM) and Task Management API built with .NET 8, following Clean Architecture principles and implementing the CQRS (Command Query Responsibility Segregation) pattern.
API Base URL: https://crm-tasks-api.onrender.com/api
Swagger UI: https://crm-tasks-api.onrender.com/swagger
π‘ Deploy in 5 minutes using Docker Compose or Render.com (see Deployment section)
- JWT Bearer Token Authentication - Secure API access
- User Registration & Login - Complete auth flow
- Role-based Authorization - Ready for role expansion
- Swagger UI Integration - Test authenticated endpoints
- β Clean Architecture - 4-layer separation (Domain/Application/Infrastructure/Api)
- β CQRS Pattern - Commands and Queries separated via MediatR
- β Domain-Driven Design - Domain events and business logic encapsulation
- β Repository Pattern - Data access abstraction
- β Unit of Work - Transaction management
- Company Management - Full CRUD with industry tracking
- Contact Management - Linked to companies with email validation
- Task Management - Priority levels (Low/Medium/High/Critical), Status tracking, Due dates
- Domain Events - Event-driven architecture support
- PostgreSQL Database - Production-grade data persistence
- AutoMapper - Automatic DTO mapping
- FluentValidation - Input validation
- xUnit Tests - Comprehensive test coverage
- Docker Support - Containerized deployment
- CI/CD Pipeline - GitHub Actions automation
βββββββββββββββββββββββββββββββββββββββ
β API Layer (Presentation) β β Controllers, JWT Auth, Swagger
βββββββββββββββββββββββββββββββββββββββ€
β Application Layer (Business) β β CQRS Commands/Queries, DTOs, Validators
βββββββββββββββββββββββββββββββββββββββ€
β Domain Layer (Core Business) β β Entities, Domain Events, Business Rules
βββββββββββββββββββββββββββββββββββββββ€
β Infrastructure Layer (Data/IO) β β EF Core, PostgreSQL, Repositories
βββββββββββββββββββββββββββββββββββββββ
graph TD
A[Client Request] --> B[Controller]
B --> C[MediatR]
C --> D{Command or Query?}
D -->|Command| E[Command Handler]
D -->|Query| F[Query Handler]
E --> G[FluentValidation]
G --> H[Business Logic]
H --> I[Repository]
I --> J[Unit of Work]
J --> K[PostgreSQL]
F --> L[Repository]
L --> M[AutoMapper]
M --> N[DTO Response]
K --> O[Domain Events]
O --> P[Response]
# Clone repository
git clone https://github.com/aymandakir/crm-tasks-api.git
cd crm-tasks-api
# Start services (API + PostgreSQL)
docker-compose up -d
# API will be available at http://localhost:5000
# Swagger UI at http://localhost:5000/swagger- .NET 8 SDK
- PostgreSQL 12+
# 1. Clone and navigate
git clone https://github.com/aymandakir/crm-tasks-api.git
cd crm-tasks-api
# 2. Update connection string in appsettings.json
# Edit: src/CrmTasksApi.Api/appsettings.json
# 3. Restore dependencies
dotnet restore
# 4. Create database migrations
cd src/CrmTasksApi.Infrastructure
dotnet ef migrations add InitialCreate --startup-project ../CrmTasksApi.Api
dotnet ef database update --startup-project ../CrmTasksApi.Api
# 5. Run the API
cd ../CrmTasksApi.Api
dotnet run
# 6. Access Swagger UI
# https://localhost:5001/swagger (or check console for port)POST /api/auth/register
Content-Type: application/json
{
"email": "user@example.com",
"password": "SecurePass123!",
"firstName": "John",
"lastName": "Doe"
}POST /api/auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "SecurePass123!"
}Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"email": "user@example.com",
"userName": "user@example.com",
"expiresAt": "2024-12-22T12:00:00Z"
}GET /api/companies
Authorization: Bearer {your-jwt-token}| Resource | Method | Endpoint | Auth Required |
|---|---|---|---|
| Auth | POST | /api/auth/register |
No |
| Auth | POST | /api/auth/login |
No |
| Companies | GET | /api/companies |
Yes |
| Companies | GET | /api/companies/{id} |
Yes |
| Companies | POST | /api/companies |
Yes |
| Companies | PUT | /api/companies/{id} |
Yes |
| Companies | DELETE | /api/companies/{id} |
Yes |
| Contacts | GET | /api/contacts |
Yes |
| Contacts | GET | /api/contacts/{id} |
Yes |
| Contacts | POST | /api/contacts |
Yes |
| Contacts | PUT | /api/contacts/{id} |
Yes |
| Contacts | DELETE | /api/contacts/{id} |
Yes |
| Tasks | GET | /api/taskitems |
Yes |
| Tasks | GET | /api/taskitems/{id} |
Yes |
| Tasks | POST | /api/taskitems |
Yes |
| Tasks | PUT | /api/taskitems/{id} |
Yes |
| Tasks | DELETE | /api/taskitems/{id} |
Yes |
Priority Levels:
0- Low1- Medium2- High3- Critical
Status Values:
0- Todo1- InProgress2- Done3- Cancelled
POST /api/taskitems
Authorization: Bearer {token}
Content-Type: application/json
{
"title": "Critical client follow-up",
"description": "Urgent: Discuss contract renewal",
"status": 0,
"priority": 3,
"dueDate": "2024-12-25T10:00:00Z",
"contactId": 1,
"companyId": 5
}dotnet test- β Company entity tests (3 tests)
- β Contact entity tests (3 tests)
- β TaskItem entity tests (3 tests)
- Navigate to
/swagger - Click Authorize button
- Enter JWT token:
Bearer {your-token} - Test authenticated endpoints
# Build image
docker build -t crm-tasks-api .
# Run with Docker Compose
docker-compose up -d
# View logs
docker-compose logs -f api
# Stop services
docker-compose downCreate .env file or set in docker-compose.yml:
ConnectionStrings__DefaultConnection=Host=postgres;Database=CrmTasksDb;Username=postgres;Password=postgres
Jwt__Key=YourSuperSecretKeyForJWTTokenGenerationThatShouldBeAtLeast32CharactersLong!
Jwt__Issuer=CrmTasksApi
Jwt__Audience=CrmTasksApiUsers-
Create PostgreSQL Database
- New β PostgreSQL
- Copy connection string
-
Create Web Service
- New β Web Service
- Connect GitHub repository
- Build Command:
dotnet publish -c Release -o ./publish - Start Command:
dotnet ./publish/CrmTasksApi.Api.dll - Health Check Path:
/health(optional, but recommended)
-
Set Environment Variables
ConnectionStrings__DefaultConnection={your-postgres-connection-string} Jwt__Key={generate-32-char-secret} Jwt__Issuer=CrmTasksApi Jwt__Audience=CrmTasksApiUsers ASPNETCORE_ENVIRONMENT=Production -
Health Check Endpoint
- The API includes a health check endpoint at
/health - Configure Render to use this for health monitoring
- Response:
{ "status": "healthy", "timestamp": "..." }
- The API includes a health check endpoint at
-
Database Migrations
- Migrations run automatically on startup via
Program.cs - No manual migration steps required
- Migrations run automatically on startup via
-
Deploy! π
- Azure App Service - Use Azure PostgreSQL
- AWS ECS/Fargate - Use RDS PostgreSQL
- Heroku - Use Heroku Postgres addon
- DigitalOcean - Use App Platform with managed database
crm-tasks-api/
βββ src/
β βββ CrmTasksApi.Domain/ # Domain entities, events
β β βββ Entities/ # Company, Contact, TaskItem, User
β β βββ Events/ # Domain events
β βββ CrmTasksApi.Application/ # CQRS, DTOs, validators
β β βββ Common/ # Behaviors, interfaces, mappings
β β βββ DTOs/ # Data transfer objects
β β βββ Features/ # Feature-based CQRS
β β βββ Auth/ # Login, Register
β β βββ Companies/ # CRUD commands/queries
β β βββ Contacts/ # CRUD commands/queries
β β βββ TaskItems/ # CRUD commands/queries
β βββ CrmTasksApi.Infrastructure/ # Data access, services
β β βββ Persistence/ # DbContext, repositories
β β βββ Services/ # JWT token service
β βββ CrmTasksApi.Api/ # Controllers, Program.cs
β βββ Controllers/ # REST endpoints
βββ tests/
β βββ CrmTasksApi.Tests/ # xUnit tests
βββ docker-compose.yml # Docker Compose config
βββ Dockerfile # Docker image definition
βββ README.md # This file
| Category | Technology |
|---|---|
| Framework | .NET 8, ASP.NET Core |
| Database | PostgreSQL 16 |
| ORM | Entity Framework Core 8 |
| Architecture | Clean Architecture, CQRS |
| Authentication | JWT Bearer Tokens, ASP.NET Identity |
| Validation | FluentValidation |
| Mapping | AutoMapper |
| CQRS | MediatR |
| Testing | xUnit, Moq |
| Documentation | Swagger/OpenAPI |
| Containerization | Docker, Docker Compose |
| CI/CD | GitHub Actions |
Company (1) βββ (Many) Contact
Contact (1) βββ (Many) TaskItem
Company (1) βββ (Many) TaskItem (optional)
User (1) βββ (Many) [Authentication]
- One Company can have many Contacts
- One Contact can have many Tasks
- One Company can have many Tasks (optional)
- Users authenticate via JWT tokens
- Sales Teams - Track companies, manage contacts, schedule follow-ups
- Customer Support - Link tickets to contacts and companies
- Business Development - Organize prospects and pipelines
- Project Management - Assign tasks to team members
- CRM Integration - Backend for custom CRM applications
- β JWT token-based authentication
- β Password hashing (ASP.NET Identity)
- β HTTPS enforcement
- β Input validation (FluentValidation)
- β SQL injection protection (EF Core parameterized queries)
- β CORS configuration ready
- β Async/await throughout
- β Repository pattern for data access optimization
- β Unit of Work for transaction efficiency
- β Indexed database columns
- β DTO mapping for minimal data transfer
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
MIT License - see LICENSE file for details
- Issues: GitHub Issues
- Documentation: See
/docsfolder - API Guide: See
API_USAGE_GUIDE.md
This project demonstrates:
- Clean Architecture principles
- CQRS pattern implementation
- Domain-Driven Design
- Repository and Unit of Work patterns
- JWT authentication
- Docker containerization
- CI/CD with GitHub Actions
Perfect for: Portfolio projects, learning enterprise patterns, interview preparation
Built with β€οΈ using Clean Architecture, CQRS, and .NET 8