Skip to content

Umut-Tosun/CleanArchitectureSetup-2025

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clean Architecture Setup - Employee Management System

📋 Proje Hakkında

Bu proje, Clean Architecture prensiplerine göre tasarlanmış bir çalışan yönetim sistemidir. .NET 9, Entity Framework Core, MediatR ve OData kullanılarak geliştirilmiştir.

🏗️ Mimari Yapı

Proje, Clean Architecture katmanlarına göre organize edilmiştir:

CleanArchitectureSetupYoutube/
├── src/
│   ├── CleanArchitectureSetupYoutube.Domain/          # İş kuralları ve entity'ler
│   ├── CleanArchitectureSetupYoutube.Application/     # Use case'ler ve iş mantığı
│   ├── CleanArchitectureSetupYoutube.Infrastructure/  # Veri erişimi ve external servisler
│   ├── CleanArchitectureSetupYoutube.WebAPI/          # API endpoints
│   ├── CleanArchitectureSetupYoutube.ServiceDefaults/ # Aspire service defaults
│   └── CleanArchitectureSetupYoutube.AppHost/         # Aspire orchestration

Katman Sorumlulukları

  • Domain: Entity'ler, value object'ler ve repository interface'leri
  • Application: CQRS pattern ile command/query'ler, validation ve mapping
  • Infrastructure: EF Core, repository implementasyonları ve migrations
  • WebAPI: Minimal API endpoints ve OData controller'lar

🚀 Teknolojiler

  • .NET 9
  • Entity Framework Core 9.0.1 - ORM
  • MediatR 12.4.1 - CQRS pattern
  • FluentValidation 11.3.0 - Validation
  • Mapster 7.4.0 - Object mapping
  • OData 9.4.1 - Sorgu desteği
  • Scrutor 7.0.0 - Dependency injection scanning
  • TS.Result 9.0.1 - Result pattern
  • Scalar - API documentation
  • .NET Aspire - Cloud-native orchestration

📦 Kurulum

Gereksinimler

  • .NET 9 SDK
  • SQL Server (LocalDB veya Express)
  • Visual Studio 2022 veya JetBrains Rider

Adımlar

  1. Repository'yi klonlayın:
git clone https://github.com/yourusername/CleanArchitectureSetupYoutube.git
cd CleanArchitectureSetupYoutube
  1. Connection string'i yapılandırın:

src/CleanArchitectureSetupYoutube.WebAPI/appsettings.json dosyasında connection string'i düzenleyin:

{
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=(localdb)\\mssqllocaldb;Initial Catalog=CleanArchitectureSetupYoutubeDb;Integrated Security=True;"
  }
}
  1. Database migration'ları uygulayın:
cd src/CleanArchitectureSetupYoutube.WebAPI
dotnet ef database update
  1. Projeyi çalıştırın:

Aspire ile (önerilen):

cd src/CleanArchitectureSetupYoutube.AppHost
dotnet run

Doğrudan WebAPI ile:

cd src/CleanArchitectureSetupYoutube.WebAPI
dotnet run
  1. API dokümantasyonuna erişin:
  • Scalar UI: https://localhost:7028/scalar/v1
  • OData endpoint: https://localhost:7028/odata/Employees

🔧 Temel Özellikler

CQRS Pattern

  • Command: EmployeeCreateCommand - Yeni çalışan oluşturma
  • Query: EmployeeGetAllQuery - Tüm çalışanları listeleme

Validation

FluentValidation ile otomatik validation:

  • TC No zorunlu kontrol
  • Email format validation
  • Salary > 0 kontrolü
  • Birthdate geçmiş tarih kontrolü

Soft Delete

Fiziksel silme yerine IsDeleted flag'i ile soft delete desteği.

OData Desteği

Gelişmiş sorgulama özellikleri:

GET /odata/Employees?$filter=salary gt 50000
GET /odata/Employees?$orderby=firstName
GET /odata/Employees?$select=firstName,lastName,salary
GET /odata/Employees?$top=10&$skip=0

Rate Limiting

Saniyede 100 istek sınırı ile koruma.

📝 API Kullanımı

Çalışan Oluşturma

Endpoint: POST /employees

Request Body:

{
  "firstName": "Ahmet",
  "lastName": "Yılmaz",
  "salary": 75000.00,
  "birthDate": "1990-05-15",
  "personelInformation": {
    "tcno": "12345678901",
    "email": "[email protected]",
    "phone1": "05551234567",
    "phone2": "05559876543"
  },
  "address": {
    "country": "Türkiye",
    "city": "İstanbul",
    "town": "Kadıköy",
    "fullAddress": "Örnek Mahallesi, Test Sokak No:1"
  }
}

Response:

{
  "isSuccessful": true,
  "data": "Employee created successfully with ID: 3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "errorMessages": null,
  "statusCode": 200
}

Çalışanları Listeleme

Endpoint: GET /odata/Employees

OData Query Örnekleri:

# Maaşı 50000'den fazla olanlar
GET /odata/Employees?$filter=salary gt 50000

# İsme göre sıralama
GET /odata/Employees?$orderby=firstName asc

# Sadece belirli alanları getir
GET /odata/Employees?$select=firstName,lastName,salary

# Sayfalama
GET /odata/Employees?$top=10&$skip=0

# Toplam kayıt sayısı
GET /odata/Employees?$count=true

🗄️ Veritabanı Şeması

Employees Tablosu

Kolon Tip Açıklama
Id uniqueidentifier Primary key
FirstName nvarchar(max) Çalışan adı
LastName nvarchar(max) Çalışan soyadı
BirthDate date Doğum tarihi
Salary money Maaş bilgisi
TCNO nvarchar(max) TC kimlik no
Email nvarchar(max) Email adresi
Phone1 nvarchar(max) Telefon 1
Phone2 nvarchar(max) Telefon 2
Country nvarchar(max) Ülke
City nvarchar(max) Şehir
Town nvarchar(max) İlçe
FullAddress nvarchar(max) Tam adres
CreatedDate datetimeoffset Oluşturulma tarihi
LastUpdatedDate datetimeoffset Son güncelleme tarihi
IsDeleted bit Silinme durumu
DeletedDate datetimeoffset Silinme tarihi

🏛️ Design Patterns

  • CQRS: Command Query Responsibility Segregation
  • Repository Pattern: Veri erişim soyutlaması
  • Unit of Work: Transaction yönetimi
  • Result Pattern: Hata yönetimi
  • Mediator Pattern: İş mantığı koordinasyonu
  • Pipeline Behavior: Validation middleware
  • Dependency Injection: IoC container

🔐 Global Exception Handling

Tüm hatalar merkezi olarak yakalanır ve standart formatta döndürülür:

{
  "isSuccessful": false,
  "data": null,
  "errorMessages": ["Hata mesajı"],
  "statusCode": 500
}

🧪 Migration Komutları

# Yeni migration oluştur
dotnet ef migrations add MigrationName -p src/CleanArchitectureSetupYoutube.Infrastructure -s src/CleanArchitectureSetupYoutube.WebAPI

# Migration uygula
dotnet ef database update -p src/CleanArchitectureSetupYoutube.Infrastructure -s src/CleanArchitectureSetupYoutube.WebAPI

# Migration geri al
dotnet ef database update PreviousMigrationName -p src/CleanArchitectureSetupYoutube.Infrastructure -s src/CleanArchitectureSetupYoutube.WebAPI

# Migration sil
dotnet ef migrations remove -p src/CleanArchitectureSetupYoutube.Infrastructure -s src/CleanArchitectureSetupYoutube.WebAPI

📚 Proje Yapısı Detayları

Domain Layer

  • Entities: İş nesneleri (Employee, Entity)
  • Value Objects: PersonelInformation, Address
  • Repository Interfaces: IEmployeeRepository

Application Layer

  • Commands: EmployeeCreateCommand
  • Queries: EmployeeGetAllQuery
  • Validators: EmployeeCreateCommandValidator
  • Behaviors: ValidationBehavior

Infrastructure Layer

  • DbContext: ApplicationDbContext
  • Configurations: EmployeeConfiguration
  • Repositories: EmployeeRepository
  • Migrations: EF Core migrations

WebAPI Layer

  • Endpoints: Minimal API endpoints
  • Controllers: OData controllers
  • Middleware: Exception handling, rate limiting

🛠️ Geliştirme Notları

Yeni Entity Ekleme

  1. Domain layer'da entity oluştur
  2. Repository interface tanımla
  3. Infrastructure'da configuration ekle
  4. Repository implementasyonu yap
  5. Migration oluştur ve uygula
  6. Application layer'da command/query ekle
  7. WebAPI'de endpoint tanımla

Validation Kuralları

FluentValidation kullanarak her command için validator oluşturun:

public class MyCommandValidator : AbstractValidator<MyCommand>
{
    public MyCommandValidator()
    {
        RuleFor(x => x.Property)
            .NotEmpty()
            .WithMessage("Mesaj");
    }
}

📄 Lisans

Bu proje eğitim amaçlı geliştirilmiştir.

🤝 Katkıda Bulunma

  1. Fork edin
  2. Feature branch oluşturun (git checkout -b feature/amazing-feature)
  3. Commit yapın (git commit -m 'feat: Add amazing feature')
  4. Push edin (git push origin feature/amazing-feature)
  5. Pull Request açın

📞 İletişim

Sorularınız için issue açabilirsiniz.


Not: Bu proje Clean Architecture ve .NET best practice'lerini göstermek amacıyla hazırlanmıştır.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages