Garment.id
🇺🇸 English
  • 🇮🇩 Indonesian
  • 🇺🇸 English
Home
Core APITenant APISupport CenterChangelog
Home
Core APITenant APISupport CenterChangelog
Github
Instagram
|
🇺🇸 English
  • 🇮🇩 Indonesian
  • 🇺🇸 English
🇺🇸 English
  • 🇮🇩 Indonesian
  • 🇺🇸 English
  1. Home
  • Introduction
  • 01 - Project Structure
  • 02 - Context Boundaries
  • 03 - Central Auth Runtime
  • 04 - Central Billing
  • 05 - Tenant Runtime
  • 06 - FE Integration Contracts
  • 07 - Security, Middleware, and RLS
  • 08 - Events, Jobs, Listeners, Notifications, Observers
  • 09 - Testing and Quality Gates
  • 10 - Operations Runbook
  • 11 - Architecture Decisions (ADR Ringkas)
  • 12 - API Endpoint Catalog (v1)
  • 13 - Class Catalog by Context
  • 14 - Feature Development Playbook
  • 15 - Migration and Model Conventions
  • 16 - Service, Support, and Trait Contracts
  • 17 - Auth Business Scenarios and Decision Tree
  • 18 - Config Reference and Impact
  • 19 - Migration and Model Cookbook
  • 20 - Billing and Provisioning Business Flows
  • 21 - FE Error Handling Matrix
  • 22 - Incident Playbooks
  • 23 - Data Ownership Matrix
  • 24 - Documentation Governance and Changelog
  • 25 - Tenant Authorization Backend Guide
Home
Core APITenant APISupport CenterChangelog
Home
Core APITenant APISupport CenterChangelog
Github
Instagram
|
🇺🇸 English
  • 🇮🇩 Indonesian
  • 🇺🇸 English
🇺🇸 English
  • 🇮🇩 Indonesian
  • 🇺🇸 English
  1. Home

16 - Service, Support, and Trait Contracts

Dokumen ini menjelaskan kontrak tanggung jawab layer Service, Support, dan Trait.

Layer Contracts#

Service Layer#

Lokasi:
app/Services/Central/*
app/Services/Shared/*
Kontrak:
tempat business logic domain.
orchestration antar repository/model/domain policy.
tidak menangani parsing HTTP request mentah.
tidak menghasilkan response envelope langsung.

Support Layer#

Lokasi:
app/Support/*
Kontrak:
infra concern reusable (connection manager, alerting, auth helper, utility kecil).
bukan tempat business policy domain yang berubah karena rule produk.

Trait Layer#

Lokasi:
app/Traits/*
Kontrak:
behavior cross-cutting untuk model/controller.
tidak boleh menyimpan orchestration flow besar.

Core Examples (Current Project)#

Services#

AuthorizationResolver: resolve authz tenant/platform.
PaymentWebhookService: orchestration webhook billing.
TenantRegistrationService: orchestration registrasi tenant.
SubscriptionService: billing subscription domain logic reusable.

Support#

TenantClusterResolver: resolve koneksi cluster tenant dari context.
ClusterConnectionManager: manage dynamic DB connection per cluster.
RefreshTokenManager: helper auth refresh token operations.
OperationalAlerter: jalur alert operasional lintas domain.

Traits#

HasTenantClusterConnection: auto resolve DB connection tenant model.
HasApiResponse: helper response envelope di controller.
HasUuidV7: shared UUID behavior.

Decision Matrix#

Gunakan pertanyaan ini:
1.
Apakah ini business policy domain?
Ya -> Service.
2.
Apakah ini infra/helper reusable lintas domain?
Ya -> Support.
3.
Apakah ini behavior kecil reusable pada class tertentu?
Ya -> Trait.

Anti-Patterns#

business logic berat ditaruh di trait.
support class mulai mengandung policy bisnis yang kompleks.
controller langsung memuat 100% logic domain tanpa service.

Collaboration Rule#

Saat menambah class baru:
tulis 1 kalimat purpose di docblock class.
update docs/13-class-catalog-by-context.md via generator.
jika mengubah kontrak layer, update dokumen ini.
Diubah pada 2026-03-03 22:25:30
Sebelumnya
15 - Migration and Model Conventions
Berikutnya
17 - Auth Business Scenarios and Decision Tree
Built with