From a987e42ad6747fa1c7e09ef855b7e3a8ddcc8c56 Mon Sep 17 00:00:00 2001 From: Stephan Lo Date: Thu, 9 Oct 2025 01:09:36 +0200 Subject: [PATCH] refactor(domain): Decompose domain.go into individual entity files Decomposes the monolithic `internal/core/domain/domain.go` file into separate files for each domain entity (`app.go`, `app_instance.go`, `cloudlet.go`, `flavor.go`). - `SecurityRule` struct moved into `app.go` as it is a value object specific to the App entity. - `Location` struct moved into `cloudlet.go` as it is a value object specific to the Cloudlet entity. - `Flavor` remains a separate file as it is a shared entity used by App, AppInstance, and Cloudlet. This refactoring improves modularity and makes the domain model easier to navigate and understand. --- internal/core/domain/app.go | 31 +++++++++++ internal/core/domain/app_instance.go | 18 +++++++ internal/core/domain/cloudlet.go | 26 +++++++++ internal/core/domain/domain.go | 79 ---------------------------- internal/core/domain/flavor.go | 6 +++ 5 files changed, 81 insertions(+), 79 deletions(-) create mode 100644 internal/core/domain/app.go create mode 100644 internal/core/domain/app_instance.go create mode 100644 internal/core/domain/cloudlet.go delete mode 100644 internal/core/domain/domain.go create mode 100644 internal/core/domain/flavor.go diff --git a/internal/core/domain/app.go b/internal/core/domain/app.go new file mode 100644 index 0000000..026c122 --- /dev/null +++ b/internal/core/domain/app.go @@ -0,0 +1,31 @@ +package domain + +// AppKey uniquely identifies an application +type AppKey struct { + Organization string + Name string + Version string +} + +// App represents an application definition +type App struct { + Key AppKey + Deployment string + ImageType string + ImagePath string + AllowServerless bool + DefaultFlavor Flavor + ServerlessConfig interface{} + DeploymentGenerator string + DeploymentManifest string + RequiredOutboundConnections []SecurityRule + Fields []string +} + +// SecurityRule defines network access rules +type SecurityRule struct { + PortRangeMax int + PortRangeMin int + Protocol string + RemoteCIDR string +} diff --git a/internal/core/domain/app_instance.go b/internal/core/domain/app_instance.go new file mode 100644 index 0000000..6d2e9bd --- /dev/null +++ b/internal/core/domain/app_instance.go @@ -0,0 +1,18 @@ +package domain + +// AppInstanceKey uniquely identifies an application instance +type AppInstanceKey struct { + Organization string + Name string + CloudletKey CloudletKey +} + +// AppInstance represents a deployed application instance +type AppInstance struct { + Key AppInstanceKey + AppKey AppKey + Flavor Flavor + State string + PowerState string + Fields []string +} diff --git a/internal/core/domain/cloudlet.go b/internal/core/domain/cloudlet.go new file mode 100644 index 0000000..51bc66e --- /dev/null +++ b/internal/core/domain/cloudlet.go @@ -0,0 +1,26 @@ +package domain + +// CloudletKey uniquely identifies a cloudlet +type CloudletKey struct { + Organization string + Name string +} + +// Cloudlet represents edge infrastructure +type Cloudlet struct { + Key CloudletKey + Location Location + IpSupport string + NumDynamicIps int32 + State string + Flavor Flavor + PhysicalName string + Region string + NotifySrvAddr string +} + +// Location represents geographical coordinates +type Location struct { + Latitude float64 + Longitude float64 +} diff --git a/internal/core/domain/domain.go b/internal/core/domain/domain.go deleted file mode 100644 index 3613c4b..0000000 --- a/internal/core/domain/domain.go +++ /dev/null @@ -1,79 +0,0 @@ - -package domain - -// AppKey uniquely identifies an application -type AppKey struct { - Organization string - Name string - Version string -} - -// CloudletKey uniquely identifies a cloudlet -type CloudletKey struct { - Organization string - Name string -} - -// AppInstanceKey uniquely identifies an application instance -type AppInstanceKey struct { - Organization string - Name string - CloudletKey CloudletKey -} - -// Flavor defines resource allocation for instances -type Flavor struct { - Name string -} - -// SecurityRule defines network access rules -type SecurityRule struct { - PortRangeMax int - PortRangeMin int - Protocol string - RemoteCIDR string -} - -// App represents an application definition -type App struct { - Key AppKey - Deployment string - ImageType string - ImagePath string - AllowServerless bool - DefaultFlavor Flavor - ServerlessConfig interface{} - DeploymentGenerator string - DeploymentManifest string - RequiredOutboundConnections []SecurityRule - Fields []string -} - -// AppInstance represents a deployed application instance -type AppInstance struct { - Key AppInstanceKey - AppKey AppKey - Flavor Flavor - State string - PowerState string - Fields []string -} - -// Cloudlet represents edge infrastructure -type Cloudlet struct { - Key CloudletKey - Location Location - IpSupport string - NumDynamicIps int32 - State string - Flavor Flavor - PhysicalName string - Region string - NotifySrvAddr string -} - -// Location represents geographical coordinates -type Location struct { - Latitude float64 - Longitude float64 -} diff --git a/internal/core/domain/flavor.go b/internal/core/domain/flavor.go new file mode 100644 index 0000000..e11b3ed --- /dev/null +++ b/internal/core/domain/flavor.go @@ -0,0 +1,6 @@ +package domain + +// Flavor defines resource allocation for instances +type Flavor struct { + Name string +}