Commit graph

57 commits

Author SHA1 Message Date
7b062612f5 refactor(arch): Separate infrastructure from driven adapter
This commit introduces a significant architectural refactoring to decouple the driven adapter from low-level infrastructure concerns, adhering more strictly to the principles of Hexagonal Architecture.

Problem:
The driven adapter in `internal/adapters/driven/edgeconnect` was responsible for both adapting data structures and handling direct HTTP communication, authentication, and request/response logic. This violated the separation of concerns, making the adapter difficult to test and maintain.

Solution:
A new infrastructure layer has been created at `internal/infrastructure`. This layer now contains all the low-level details of interacting with the EdgeConnect API.

Key Changes:
- **New Infrastructure Layer:** Created `internal/infrastructure` to house components that connect to external systems.
- **Generic HTTP Client:** A new, generic `edgeconnect_client` was created in `internal/infrastructure/edgeconnect_client`. It is responsible for authentication, making HTTP requests, and handling raw responses. It has no knowledge of the application's domain models.
- **Config & Transport Moved:** The `config` and `http` (now `transport`) packages were moved into the infrastructure layer, as they are details of how the application is configured and communicates.
- **Consolidated Driven Adapter:** The logic from the numerous old adapter files (`apps.go`, `cloudlet.go`, etc.) has been consolidated into a single, true adapter at `internal/adapters/driven/edgeconnect/adapter.go`.
- **Clear Responsibility:** The new `adapter.go` is now solely responsible for:
  1. Implementing the driven port (repository) interfaces.
  2. Translating domain models into the data structures required by the `edgeconnect_client`.
  3. Calling the `edgeconnect_client` to perform the API operations.
  4. Translating the results back into domain models.
- **Updated Dependency Injection:** The application's entry point (`cmd/cli/main.go`) has been updated to construct and inject dependencies according to the new architecture: `infra_client` -> `adapter` -> `service` -> `cli_command`.
- **SDK & Apply Command:** The SDK examples and the `apply` command have been updated to use the new adapter and its repository methods, removing all direct client instantiation.
2025-10-09 00:47:45 +02:00
f1ee439c61 refactor: structure core logic by application use cases
Restructures the internal business logic from a generic `services` package to a use-case-driven design under `internal/application`.

Each primary function of the application (`app`, `instance`, `cloudlet`, `apply`) now resides in its own package. This clarifies the architecture and makes it easier to navigate and extend.

- Moved service implementations to `internal/application/<usecase>/`.
- Kept ports and domain models in `internal/core/`.
- Updated `main.go` and CLI adapters to reflect the new paths.
- Added missing `RefreshAppInstance` method to satisfy the service interface.
- Verified the change with a full build and test run.
2025-10-09 00:00:51 +02:00
19a9807499 fix: resolve all 27 golangci-lint issues with comprehensive error handling
🔧 Code Quality Improvements:
- Complete errcheck compliance (24 issues → 0)
- staticcheck optimizations (2 issues → 0)
- Unused code cleanup (1 issue → 0)
- Production-ready error handling across codebase

📦 Production Code Fixes (Priority 1):
- resp.Body.Close(): Proper defer functions with error logging
- cmd.MarkFlagRequired(): Panic on setup-critical flag errors
- viper.BindPFlag/BindEnv(): Panic on configuration binding failures
- file.Close(): Warning logs for file handling errors
- fmt.Scanln/cmd.Usage(): Graceful error handling in CLI

🧪 Test Code Fixes (Priority 2):
- w.Write(): Error checking in all HTTP mock servers
- json.NewEncoder().Encode(): Proper error handling in test helpers
- Robust test infrastructure without silent failures

 Performance & Readability (staticcheck):
- if-else chains → tagged switch statements in planner.go
- Empty branch elimination with meaningful error logging
- Import cleanup after unused function removal

🗂️ Code Organization:
- Removed unused createStreamingJSONServer helper function
- Clean imports without unused dependencies
- Consistent error handling patterns across adapters

 Quality Assurance:
- make lint: 27 issues → 0 issues
- All tests passing with robust error handling
- Production-ready error management and logging
- Enhanced code maintainability and debugging

🎯 Impact:
- Eliminates resource leaks from unclosed HTTP bodies
- Prevents silent failures in CLI setup and configuration
- Improves debugging with comprehensive error logging
- Enhances test reliability and error visibility
2025-10-08 18:55:31 +02:00
8e2e61d61e feat: implement dependency injection with proper hexagonal architecture
 Features:
- Simple dependency inversion following SOLID principles
- Clean constructor injection without complex DI containers
- Proper hexagonal architecture with driving/driven separation
- Presentation layer moved to cmd/cli for correct application structure

🏗️ Architecture Changes:
- Driving Adapters (Inbound): internal/adapters/driving/cli/
- Driven Adapters (Outbound): internal/adapters/driven/edgeconnect/
- Core Services: Dependency-injected via interface parameters
- main.go relocated from root to cmd/cli/main.go

📦 Application Flow:
1. cmd/cli/main.go - Entry point and dependency wiring
   └── Creates EdgeConnect client based on environment
   └── Instantiates services with injected repositories
   └── Executes CLI with properly wired dependencies

2. internal/adapters/driving/cli/ - User interface layer
   └── Receives user commands and input validation
   └── Delegates to core services via driving ports
   └── Handles presentation logic and output formatting

3. internal/core/services/ - Business logic layer
   └── NewAppService(appRepo, instanceRepo) - Constructor injection
   └── NewAppInstanceService(instanceRepo) - Interface dependencies
   └── NewCloudletService(cloudletRepo) - Clean separation

4. internal/adapters/driven/edgeconnect/ - Infrastructure layer
   └── Implements repository interfaces for external API
   └── Handles HTTP communication and data persistence
   └── Provides concrete implementations of driven ports

🔧 Build & Deployment:
- CLI Binary: make build → bin/edge-connect-cli
- Usage: ./bin/edge-connect-cli --help
- Tests: make test (all passing)
- Clean: make clean (updated paths)

💡 Benefits:
- Simple and maintainable dependency management
- Testable architecture with clear boundaries
- SOLID principles compliance without overengineering
- Proper separation of concerns in hexagonal structure
2025-10-08 18:15:26 +02:00
2625a58691 feat: implement unified domain error handling system
Addresses Verbesserungspotential 2 (Error Handling uneinheitlich) by introducing
a comprehensive, structured error handling approach across all architectural layers.

## New Domain Error System
- Add ErrorCode enum with 15 semantic error types (NOT_FOUND, VALIDATION_FAILED, etc.)
- Implement DomainError struct with operation context, resource identifiers, and regions
- Create resource-specific error constructors (NewAppError, NewInstanceError, NewCloudletError)
- Add utility functions for error type checking (IsNotFoundError, IsValidationError, etc.)

## Service Layer Enhancements
- Replace generic fmt.Errorf with structured domain errors in all services
- Add comprehensive validation functions for App, AppInstance, and Cloudlet entities
- Implement business logic validation with meaningful error context
- Ensure consistent error semantics across app_service, instance_service, cloudlet_service

## Adapter Layer Updates
- Update EdgeConnect adapters to use domain errors instead of error constants
- Enhance CLI adapter with domain-specific error checking for better UX
- Fix SDK examples to use new IsNotFoundError() approach
- Maintain backward compatibility where possible

## Test Coverage
- Add comprehensive error_test.go with 100% coverage of new error system
- Update existing adapter tests to validate domain error types
- All tests passing with proper error type assertions

## Benefits
-  Consistent error handling across all architectural layers
-  Rich error context with operation, resource, and region information
-  Type-safe error checking with semantic error codes
-  Better user experience with domain-specific error messages
-  Maintainable centralized error definitions
-  Full hexagonal architecture compliance

Files modified: 12 files updated, 2 new files added
Tests: All passing (29+ test cases with enhanced error validation)
2025-10-08 16:52:36 +02:00
7b359f81e3 chore(): unique go version 1.25, fixes 'make test-coverage' error 2025-10-08 16:49:31 +02:00
e72c81bc43 fix(test): fixed by ai all tests after refactoring 2025-10-08 13:35:49 +02:00
43d8f277a6 feat(arch) added hexagonal arch impl done with ai 2025-10-08 12:55:53 +02:00
c7b1284606 fix(test): finish fixing organisation refactoring tests failures 2025-10-07 17:21:38 +02:00
921822239b fix(test): finish fixing organisation refactoring tests failures 2025-10-07 17:19:52 +02:00
f32479aaf8 fix(test): fixed compile errors 2025-10-07 17:09:36 +02:00
a72341356b fix(test): started fixing tests 2025-10-07 17:05:35 +02:00
bc524c3b0e refactor(yaml): Moved organisation to metadata 2025-10-07 16:30:57 +02:00
0f3cc90b01 ci: Added test workflow running on each push except tags 2025-10-07 16:10:02 +02:00
06f921963a refactor(yaml): moved AppVersion into metadata 2025-10-07 16:01:38 +02:00
cc8b9e791b fix(cli): Fixed tests after outputting plan diff 2025-10-07 15:40:27 +02:00
f635157d67 chore: Added flake 2025-10-07 14:37:54 +02:00
e092f352f8 feat(cli): Added hash compare between current and desired manifest state without using annotation. instead the current hash is calculated from the showapp() app.deploymentmanifest field 2025-10-06 17:08:33 +02:00
6de170f6cf feat(cli): Added output of diff when updating outboundConnections in the desired manifest 2025-10-06 16:45:53 +02:00
393977c7fc feat(cli): Added an auto approve flag for apply
All checks were successful
ci / goreleaser (push) Successful in 1m52s
2025-10-02 14:52:40 +02:00
e061883c32 fix(cli): Run tests before release
All checks were successful
ci / goreleaser (push) Successful in 1m19s
2025-10-02 13:50:28 +02:00
38c08ccf00 fix(cli): Force usage of gitea token
All checks were successful
ci / goreleaser (push) Successful in 1m18s
2025-10-02 13:44:28 +02:00
6a66c8659b fix(cli): Unset GITHUB_TOKEN and set GITEA_TOKEN instead 2025-10-02 13:33:21 +02:00
7085667d31 fix(cli): Changed GITEA_TOKEN to GITHUB_TOKEN
Some checks failed
ci / goreleaser (push) Failing after 1m19s
2025-10-02 13:22:10 +02:00
a56360eacc fix(cli): Release pipeline using Goreleaser should work now 2025-10-02 13:19:40 +02:00
2f52257f1a fix(release): Downgraded forgejo-release action
Some checks failed
ci / goreleaser (push) Failing after 38s
2025-10-01 15:40:11 +02:00
be22a018d3 fix(release): Added all of the config out of desperation 2025-10-01 15:17:16 +02:00
81cbca153e fix(release): Added repo to release action 2025-10-01 15:04:16 +02:00
8a0c201b74 fix(release): Removed wrong version setting, Skipping artifact pubish 2025-10-01 14:55:21 +02:00
7936d2b845 fix(release): Set go version in setup action 2025-10-01 14:51:09 +02:00
b80c424840 fix(release): Downgraded checkout action due to node24 issue 2025-10-01 14:48:43 +02:00
54cc8caf1a feat(release): Added forgejo release action 2025-10-01 14:42:35 +02:00
72f9806e32 feat(goreleaser): fixed changelog messages 2025-10-01 14:20:11 +02:00
7da4e23b57 feat(goreleaser): added first implementation 2025-10-01 13:22:41 +02:00
7bfdeba49f feat(sdk, cli): Implemented update endpoints. Added recreate deployment strategy to cli. Fixed tests. 2025-10-01 10:49:15 +02:00
240a9028b3 feat(sdk): Added update endpoints for app and appinst 2025-09-30 12:09:00 +02:00
5d6fd8fc59 chore(cli): Removed appName from config schema. This is redundant to metadata name 2025-09-30 11:33:52 +02:00
5f0eccd315 chore(cli): Added methods to EdgeClientInterface and removed unnecessary typecasting 2025-09-29 18:04:55 +02:00
42ae3f61d9 chore(cli): Moved cli related packages out of sdk. Deleted duplicate files. 2025-09-29 17:35:34 +02:00
8b02fe54e5 feat(apply): Implement CLI command with comprehensive deployment workflow
- Add edge-connect apply command with -f/--file and --dry-run flags
- Integrate config parser, deployment planner, and resource manager
- Provide comprehensive error handling and progress reporting
- Support deployment confirmation prompts and result summaries
- Move internal packages to public SDK packages for CLI access
- Update all tests to pass with new package structure
- Complete Phase 4 CLI Command Implementation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-29 17:24:59 +02:00
8bfcd07ea4 feat(apply): Implement resource management with parallel deployment and rollback
Phase 3 Complete: Resource Management
- Add EdgeConnectResourceManager with deployment execution
- Implement app creation with manifest file processing
- Support parallel instance deployment across multiple cloudlets
- Handle network configuration conversion to SecurityRules
- Add comprehensive rollback functionality for failed deployments
- Include detailed logging and progress tracking
- Create extensive test coverage with mock scenarios

Features:
- Parallel deployment with configurable limits
- Intelligent rollback in reverse order
- Manifest file reading and hash calculation
- Network rule conversion and validation
- Deployment progress tracking and logging
- Comprehensive error handling with detailed messages

Testing:
- 16 test scenarios covering success/failure cases
- Mock client interfaces for reliable testing
- Rollback testing with failure scenarios
- Configuration conversion validation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-29 16:46:34 +02:00
02767adccd feat(apply): Implement deployment planning with intelligent state comparison
Phase 2 Complete: Deployment Planning
- Add comprehensive deployment plan types with action tracking
- Implement EdgeConnectPlanner with state comparison logic
- Support manifest hash calculation and change detection
- Add parallel infrastructure target planning
- Create deployment summary generation with duration estimates
- Include comprehensive test coverage with mock scenarios
- Handle API errors and edge cases gracefully

Features:
- Smart comparison of current vs desired state
- Minimal API calls through batched queries
- Support for dry-run planning operations
- Detailed deployment summaries with resource counts
- Extensible action types (CREATE, UPDATE, DELETE, NONE)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-29 16:36:21 +02:00
1e48e1b059 feat(apply): Implement EdgeConnect configuration parsing foundation
- Add comprehensive YAML configuration types for EdgeConnectConfig
- Implement robust parser with validation and path resolution
- Support both k8sApp and dockerApp configurations
- Add comprehensive test coverage with real example parsing
- Create validation for infrastructure uniqueness and port ranges
- Generate instance names following pattern: appName-appVersion-instance

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-29 16:18:35 +02:00
37df99810b feat(validation): Added validation of baseURL config 2025-09-29 10:48:52 +02:00
053de33fa7 feat(validation): Added validation of baseURL config 2025-09-29 10:29:11 +02:00
55e9f86759 Renamed package and removed unused make calls 2025-09-29 09:41:44 +02:00
7c5db7fa39 Removed binaries and fixed tests 2025-09-25 17:11:50 +02:00
a701a7bcba feat(sdk): Fixed filters. Keys are nested resources in edgecon 2025-09-25 17:08:08 +02:00
99f3e9f88e feat(examples): Add instance state polling with 5-minute timeout
Enhanced comprehensive example to wait for AppInstance deployment completion:

## New Polling Features:
- **State Monitoring**: Polls ShowAppInst every 10 seconds until ready
- **Timeout Protection**: 5-minute maximum wait time with context cancellation
- **Smart State Detection**: Handles Creating, Ready, Running, Error states
- **Progress Feedback**: Real-time status updates during deployment

## Implementation Details:
- **waitForInstanceReady()**: Robust polling function with timeout
- **State Logic**: Exits on non-creating states (Ready, Running, Error)
- **Error Handling**: Distinguishes between polling errors and failure states
- **Context Management**: Proper timeout context with cleanup

## User Experience:
```
5️⃣  Waiting for application instance to be ready...
   Polling instance state (timeout: 5 minutes)...
   📊 Instance state: Creating
   📊 Instance state: Creating (power: PowerOn)
   📊 Instance state: Ready (power: PowerOn)
    Instance reached ready state: Ready
```

This ensures the example demonstrates a complete, realistic deployment
workflow where instance creation is fully completed before proceeding
to subsequent operations.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 16:59:24 +02:00
cf7fb88aa2 feat(sdk): Fixed test 2025-09-25 16:31:23 +02:00