modules/solution/Write-Readme.ps1
|
param( [string]$ProjectName, [string]$OrmMode, [string]$DbProvider, [string]$FrontendMode, [string[]]$Entities, [string]$OutputPath, [bool]$SkipFrontend = $false, [bool]$SkipTests = $false, [bool]$SkipCi = $false, [switch]$Observability, [string]$CiProvider = "GitHub", [string]$Platform = "Web", [string]$ConnectionString = "" ) . (Join-Path (Split-Path $MyInvocation.MyCommand.Path) "..\core\Utils.ps1") # --- Proje yapisi (ASCII agac) --- $tree = "$ProjectName/`n" $tree += " $ProjectName-backend/`n" $tree += " src/`n" $tree += " $ProjectName.Domain/ # Entity'ler, arayuzler, is kurallari`n" $tree += " $ProjectName.Application/ # Use case'ler, CQRS handler'lar, DTO'lar`n" $tree += " $ProjectName.Infrastructure/ # Harici servisler, kimlik dogrulama`n" $tree += " $ProjectName.Persistence/ # Veritabani erisimi ($OrmMode)`n" $tree += " $ProjectName.WebApi/ # REST API, controller'lar, ExceptionHandler`n" if (-not $SkipTests) { $tree += " tests/`n" $tree += " $ProjectName.Domain.Tests/`n" $tree += " $ProjectName.Application.Tests/`n" $tree += " $ProjectName.Integration.Tests/`n" } if (-not $SkipFrontend) { if ($Platform -match "Web|Both") { $tree += " $ProjectName-web/ # Web (React Vite + TS) uygulamasi`n" } if ($Platform -match "Mobile|Both") { $tree += " $ProjectName-mobile/ # Mobil (React Native / Expo) uygulamasi`n" } } $tree += " $ProjectName-docker/ # Docker compose ve init sql dosyalari" # --- Teknoloji tablosu --- $techTable = "| Katman | Teknoloji |`n" $techTable += "|---------------|--------------------------------|`n" $techTable += "| Backend | .NET 10, ASP.NET Core |`n" $techTable += "| ORM | $OrmMode |`n" $techTable += "| Veritabani | $DbProvider |`n" if (-not $SkipFrontend) { $techTable += "| Platform | $Platform |`n" if ($Platform -match "Web|Both") { $techTable += "| Web UI | React Vite + TypeScript |`n" } if ($Platform -match "Mobile|Both") { $techTable += "| Mobile UI | React Native / Expo |`n" } } $techTable += "| Auth | JWT Bearer |" if ($Observability) { $techTable += "`n| Logging | Serilog + OpenTelemetry |" } # --- Migration bolumu --- $migrationSection = "" if ($OrmMode -ne "Dapper") { $migrationSection = @" ## Veritabani Migration ```bash cd $ProjectName-backend dotnet ef migrations add InitialCreate --project src/$ProjectName.Persistence --startup-project src/$ProjectName.WebApi dotnet ef database update --project src/$ProjectName.Persistence --startup-project src/$ProjectName.WebApi ``` "@ } # --- Frontend bolumu --- $frontendSection = "" if (-not $SkipFrontend) { if ($Platform -match "Web|Both") { $frontendSection += @" ## Web Frontend (React Vite + TS) ```bash cd $ProjectName-web npm install npm run dev ``` > Varsayilan adres: http://localhost:5173 "@ } if ($Platform -match "Mobile|Both") { $frontendSection += @" ## Mobil Frontend (React Native / Expo) ```bash cd $ProjectName-mobile npm install npm start ``` > Expo Metro bundler basladiktan sonra QR kodu telefonunuzla taratarak Expo Go uzerinden test edebilirsiniz. "@ } } # --- CI bolumu --- $ciSection = "" if (-not $SkipCi) { $ciSection = @" ## CI/CD GitHub Actions workflow: ``.github/workflows/ci.yml`` Her push ve pull request'te otomatik build + test calisir. "@ } # --- Observability bolumu --- $obsSection = "" if ($Observability) { $obsSection = @" ## Observability - **Serilog** ile yapilandirilmis loglama - **OpenTelemetry** ile tracing ve metrics "@ } # --- Entity listesi --- $entityList = ($Entities | ForEach-Object { "- ``$_``" }) -join "`n" # --- Gereksinimler --- $prereqs = "- .NET 10 SDK" if (-not $SkipFrontend) { $prereqs += "`n- Node.js 18+" } if ($DbProvider -eq "MSSQL") { $prereqs += "`n- SQL Server (veya Docker)" } if ($DbProvider -eq "Postgres") { $prereqs += "`n- PostgreSQL (veya Docker)" } $content = @" # $ProjectName Clean Architecture tabanli .NET 10 projesi. Bu proje **Clean Architecture Template Generator** ile olusturulmustur. ## Proje Yapisi ``` $tree ``` ## Teknoloji Yigini $techTable ## Entity'ler $entityList ## Baslangic ### Gereksinimler $prereqs ### Backend ```bash cd $ProjectName-backend dotnet restore dotnet build dotnet run --project src/$ProjectName.WebApi ``` > Swagger UI: http://localhost:8080/swagger (veya https://localhost:7080/swagger) $frontendSection $migrationSection ## API Endpoint'leri | Metot | Path | Aciklama | Auth | |-------|------|----------|------| | `POST` | `/api/auth/login` | JWT Token Al | - | | `POST` | `/api/auth/register` | Yeni Kullanici Kaydet | - | | `GET` | `/health` | API & Veritabani Saglik Kontrolu | - | | `GET` | `/api/v1/products` | Sayfali Urun Listesi | Bearer | | `POST` | `/api/v1/products` | Yeni Urun Ekle | Bearer (Admin) | ## Kimlik Dogrulama JWT tabanli kimlik dogrulama kullanilmaktadir. ### Varsayilan Kullanici (Seed) | Alan | Deger | |------|-------| | Kullanici Adi | `admin` | | Sifre | `Admin123!` | > Uretim ortaminda bu sifreyi degistirin. ### Giris Akisi 1. `POST /api/auth/login` -- Kullanici adi ve sifre ile token alin 2. Swagger'da **Authorize** butonuna tiklayin ve `Bearer <token>` girin 3. `POST /api/auth/register` -- Yeni kullanici olusturmak icin $ciSection $obsSection ## Docker Yönetimi & Komutlar ### Container'lari Baslatma ```bash cd $ProjectName-docker docker compose up -d --build ``` ### Container'lari Durdurma ```bash cd $ProjectName-docker docker compose down ``` ### Sıfırlama / Kaldırma (Uninstall & Volume Reset) Tüm veritabanı verilerini, container'ları ve ağları tamamen temizlemek için: ```bash cd $ProjectName-docker docker compose down -v ``` ### Container Loglarını İzleme ```bash docker logs -f ${ProjectName.ToLower()}-api docker logs -f ${ProjectName.ToLower()}-db ``` ## Temizlik & Kaldırma (Local Cleanup / Uninstall) ### .NET Build Çıktılarını Temizleme ```bash cd $ProjectName-backend dotnet clean ``` ### Veritabanını Sıfırlama / Silme ```bash cd $ProjectName-backend dotnet ef database drop --project src/$ProjectName.Persistence --startup-project src/$ProjectName.WebApi ``` ### Node.js Bağımlılıklarını Temizleme ```bash # Web için cd $ProjectName-web rm -rf node_modules package-lock.json # Mobil için cd $ProjectName-mobile rm -rf node_modules package-lock.json .expo ``` ## Sık Sorulan Sorular & Sorun Giderme - **Android Emülatöründen API'ye Erişilemiyor:** Android emülatörü `localhost`'u emülatörün kendisine bağlar. API'ye erişim için `http://10.0.2.2:8080/api` adresi kullanılır. `services/api.ts` bu dönüşümü otomatik yapar. - **PostgreSQL "Users" relation does not exist Hatası:** PostgreSQL tablo isimlerini varsayılan olarak küçük harfe çevirir. `init.sql` ve EF Core tablo isimlerinde çift tırnak (`"Users"`) kullanılır. - **Docker 100 Saniye Bekleme Hatası:** MSSQL healthcheck `sqlcmd -C` parametresi gerektirir. `docker-compose.yml` içerisindeki healthcheck komutunu kontrol edin. "@ Write-CoreFile (Join-Path $OutputPath "README.md") $content |