Skip to content

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏒 CRM Tasks API - Production-Ready Enterprise REST API

.NET License: MIT Tests .NET Version

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.

πŸš€ Live Demo

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)


✨ Key Features

πŸ” Authentication & Security

  • 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

πŸ—οΈ Architecture

  • βœ… 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

πŸ“Š Core Functionality

  • 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

πŸ› οΈ Production Features

  • 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

πŸ—οΈ Architecture Overview

Clean Architecture Layers

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   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
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

CQRS Flow Diagram

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]
Loading

πŸš€ Quick Start

Option 1: Docker Compose (Recommended)

# 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

Option 2: Local Development

Prerequisites

  • .NET 8 SDK
  • PostgreSQL 12+

Steps

# 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)

πŸ“š API Documentation

Authentication

Register User

POST /api/auth/register
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "SecurePass123!",
  "firstName": "John",
  "lastName": "Doe"
}

Login

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"
}

Using JWT Token

GET /api/companies
Authorization: Bearer {your-jwt-token}

Endpoints

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

Task Priority & Status

Priority Levels:

  • 0 - Low
  • 1 - Medium
  • 2 - High
  • 3 - Critical

Status Values:

  • 0 - Todo
  • 1 - InProgress
  • 2 - Done
  • 3 - Cancelled

Example: Create Task with Priority

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
}

πŸ§ͺ Testing

Run Unit Tests

dotnet test

Test Coverage

  • βœ… Company entity tests (3 tests)
  • βœ… Contact entity tests (3 tests)
  • βœ… TaskItem entity tests (3 tests)

Swagger UI Testing

  1. Navigate to /swagger
  2. Click Authorize button
  3. Enter JWT token: Bearer {your-token}
  4. Test authenticated endpoints

🐳 Docker Deployment

Build and Run

# 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 down

Environment Variables

Create .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

☁️ Deployment

Render.com Deployment

  1. Create PostgreSQL Database

    • New β†’ PostgreSQL
    • Copy connection string
  2. 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)
  3. Set Environment Variables

    ConnectionStrings__DefaultConnection={your-postgres-connection-string}
    Jwt__Key={generate-32-char-secret}
    Jwt__Issuer=CrmTasksApi
    Jwt__Audience=CrmTasksApiUsers
    ASPNETCORE_ENVIRONMENT=Production
    
  4. Health Check Endpoint

    • The API includes a health check endpoint at /health
    • Configure Render to use this for health monitoring
    • Response: { "status": "healthy", "timestamp": "..." }
  5. Database Migrations

    • Migrations run automatically on startup via Program.cs
    • No manual migration steps required
  6. Deploy! πŸš€

Other Platforms

  • Azure App Service - Use Azure PostgreSQL
  • AWS ECS/Fargate - Use RDS PostgreSQL
  • Heroku - Use Heroku Postgres addon
  • DigitalOcean - Use App Platform with managed database

πŸ“ Project Structure

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

πŸ”§ Technology Stack

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

πŸ“Š Database Schema

Company (1) ──→ (Many) Contact
Contact  (1) ──→ (Many) TaskItem
Company  (1) ──→ (Many) TaskItem (optional)
User     (1) ──→ (Many) [Authentication]

Entity Relationships

  • One Company can have many Contacts
  • One Contact can have many Tasks
  • One Company can have many Tasks (optional)
  • Users authenticate via JWT tokens

🎯 Use Cases

  1. Sales Teams - Track companies, manage contacts, schedule follow-ups
  2. Customer Support - Link tickets to contacts and companies
  3. Business Development - Organize prospects and pipelines
  4. Project Management - Assign tasks to team members
  5. CRM Integration - Backend for custom CRM applications

πŸ”’ Security Features

  • βœ… JWT token-based authentication
  • βœ… Password hashing (ASP.NET Identity)
  • βœ… HTTPS enforcement
  • βœ… Input validation (FluentValidation)
  • βœ… SQL injection protection (EF Core parameterized queries)
  • βœ… CORS configuration ready

πŸ“ˆ Performance

  • βœ… Async/await throughout
  • βœ… Repository pattern for data access optimization
  • βœ… Unit of Work for transaction efficiency
  • βœ… Indexed database columns
  • βœ… DTO mapping for minimal data transfer

🀝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

πŸ“ License

MIT License - see LICENSE file for details


πŸ“ž Support

  • Issues: GitHub Issues
  • Documentation: See /docs folder
  • API Guide: See API_USAGE_GUIDE.md

πŸŽ“ Learning Resources

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

.NET

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages