Struktur Proyek
Pendahuluan
Dokumen ini memberikan rincian detail tentang struktur direktori proyek, menjelaskan tujuan dari setiap folder, konvensi kepemilikan file, pola namespace, dan file-file yang terkait dengan startup.
Direktori Root
Kepemilikan Folder
| Folder | Tanggung Jawab |
|---|---|
API/Controllers/ | Penangan titik akhir HTTP, perutean permintaan, atribut otorisasi |
Application/DTOs/ | Kelas payload permintaan dan respons |
Domain/Entities/ | Model domain yang disimpan di PostgreSQL melalui EF Core |
Infrastructure/Data/ | ApplicationDbContext, pabrik design-time, konfigurasi persistensi |
Infrastructure/Services/ | Layanan integrasi eksternal (JWT, Redis, InfluxDB, OpenSearch) |
Infrastructure/Repositories/ | Abstraksi akses data dan implementasi repositori konkret |
Common/Helpers/ | Kelas utilitas lintas-potong |
Extensions/ | Komposisi startup (DI, middleware, pemeriksaan kesehatan, migrasi) |
Protos/ | File gRPC .proto untuk definisi layanan |
Migrations/ | File migrasi database EF Core |
Seed/ | File data yang disalin ke kontainer Docker untuk seeding |
Scripts/ | Skrip utilitas dan operasional |
Organisasi Controller
Controller dikelompokkan berdasarkan domain fitur ke dalam subdirektori:
Konvensi Namespace
Namespace root distandarisasi menjadi Ravenxcope.Backend, tetapi beberapa area menggunakan namespace yang disingkat:
| Direktori | Namespace Aktual | Catatan |
|---|---|---|
API/Controllers/Auth/ | Ravenxcope.Backend.Controllers.Auth | Dikelompokkan berdasarkan fitur |
API/Controllers/Users/ | Ravenxcope.Backend.Controllers.Users | Dikelompokkan berdasarkan fitur |
Application/DTOs/ | Ravenxcope.Backend.DTOs | Namespace datar untuk semua DTO |
Domain/Entities/ | Ravenxcope.Backend.Domain.Entities | Sejajar dengan struktur folder |
Infrastructure/Data/ | Ravenxcope.Backend.Data | Disingkat |
Infrastructure/Services/ | Ravenxcope.Backend.Services | Disingkat |
Common/Helpers/ | Ravenxcope.Backend.Helpers atau .Common.Helpers | Campuran |
Extensions/ | Ravenxcope.Backend.Extensions | Konsisten |
Catatan: Namespace entitas sekarang diselaraskan ke
Ravenxcope.Backend.Domain.Entities.
File Terkait Startup
File-file ini terlibat langsung dalam startup aplikasi:
| File | Peran |
|---|---|
Program.cs | Titik masuk, mengatur fase-fase startup |
Extensions/ServiceCollectionExtensions.cs | Mendaftarkan semua layanan DI, DB, auth, Swagger |
Extensions/WebApplicationExtensions.cs | Mengonfigurasi pipa middleware |
Extensions/ConfigurationValidationExtensions.cs | Memvalidasi kunci konfigurasi wajib saat startup |
Extensions/StartupDependencyHealthChecksExtensions.cs | Pemeriksaan kesehatan untuk dependensi eksternal |
Extensions/DatabaseMigrationExtensions.cs | Migrasi otomatis dengan logika retry |
Extensions/CorsExtensions.cs | Registrasi kebijakan CORS |
Extensions/BackendConfiguration.cs | Konstanta kunci konfigurasi dan opsi ber-tipe |
Referensi Paket NuGet
File .csproj mereferensikan paket-paket berikut:
Paket Aplikasi
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Grpc.AspNetCore" Version="2.70.0" />
<PackageReference Include="InfluxDB.Client" Version="4.18.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.0" />
<PackageReference Include="OpenSearch.Client" Version="1.8.0" />
<PackageReference Include="StackExchange.Redis" Version="2.10.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.9.0" />
Paket Database & ORM
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
Paket Logging
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
Pengaturan Proyek
Framework Target
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Ravenxcope.Backend</RootNamespace>
</PropertyGroup>
- Nullable Reference Types: Diaktifkan di seluruh proyek
- Implicit Usings: Diaktifkan untuk namespace umum
System.*danMicrosoft.* - Root Namespace: Diatur ke
Ravenxcope.Backend(menimpa namespace berbasis folder default)
Konfigurasi Docker
EXPOSE 5144
ENV ASPNETCORE_URLS=http://+:5144
ENTRYPOINT ["dotnet", "Ravenxcope.Backend.dll"]
Dockerfile menggunakan build multi-tahap dengan mcr.microsoft.com/dotnet/sdk:10.0 untuk build dan mcr.microsoft.com/dotnet/aspnet:10.0 untuk runtime. Direktori Seed/ disalin secara eksplisit dari tahap build ke gambar akhir.