You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor the SudoStart codebase from its current layered/component-based architecture to Hexagonal Architecture (Ports and Adapters pattern). This will improve testability, maintainability, and make the codebase more extensible for future features like Windows support, different AI providers, and additional package managers.
Current Architecture Issues
Mixed Concerns: Business logic (script generation, package resolution) is scattered across React components and API routes
Tight Coupling: Direct dependencies on:
Groq AI (hard to swap for OpenAI/Anthropic)
Specific registries (Homebrew, apt) - hard to add Windows support
Zustand store structure throughout components
Testing Difficulty: Business logic is intertwined with React components, making unit testing nearly impossible
Extensibility Problems: Adding new features requires changes across multiple layers
Current codebase analysis: See /docs/architecture/current-state.md
Notes
This is a non-breaking refactor - all existing features must continue working
Consider using feature flags for gradual rollout if needed
Document any deviations from pure hexagonal architecture (if necessary for Next.js constraints)
Update CI/CD pipeline to run new test suites
Overview
Refactor the SudoStart codebase from its current layered/component-based architecture to Hexagonal Architecture (Ports and Adapters pattern). This will improve testability, maintainability, and make the codebase more extensible for future features.
Current Problems
❌ Business logic (script generation, package resolution) scattered across React components and API routes
❌ Tight coupling to Groq AI (hard to swap providers)
❌ Tight coupling to specific registries (Homebrew, apt) - Windows support difficult
❌ Testing business logic requires mounting React components
❌ Adding new features requires changes across multiple layers
Proposed Solution
Implement Hexagonal Architecture with clear separation:
Domain Layer (Core)
Entities: Package, Script, Bucket
Value Objects: Version, Platform, Shell
Domain Services: ScriptGenerator
Repository Interfaces
Application Layer
Use Cases: GenerateScript, ChatWithAI, FetchVersions, ManageBucket
DTOs for input/output
Application Services
Infrastructure Layer
Adapters: GroqAI, Homebrew, Apt, LocalStorage
API Routes (thin HTTP handlers)
UI Components (thin presentation layer)
Implementation Phases
Phase 1: Domain Layer Foundation [1 day]
Create domain entities (Package, Script, Bucket)
Create value objects (Version, Platform, Shell)
Define repository interfaces
Write unit tests (target: 100% coverage)
Phase 2: Application Layer [1-1.5 days]
Implement use cases
Create DTOs
Write unit tests with mocked repositories
Phase 3: Infrastructure Adapters [1.5-2 days]
Refactor existing registry helpers into adapters
Create AI provider abstraction
Implement storage adapters
Write integration tests
Phase 4: UI/API Refactoring [1 day]
Refactor components to be thin (delegate to use cases)
Refactor API routes to be thin HTTP handlers
Implement dependency injection
Update existing hooks
Phase 5: Testing & Documentation [0.5-1 day]
Achieve >80% test coverage
Create architecture documentation
Add ADR (Architecture Decision Record)
Update README
Benefits
✅ Testability: Unit test business logic without React components
✅ Flexibility: Swap AI providers (Groq ↔ OpenAI ↔ Anthropic) with single file change
✅ Platform Support: Add Windows (Winget/Chocolatey) by creating new adapter
✅ Maintainability: Changes to UI don't affect business logic
✅ Team Scaling: Frontend and backend developers work independently
Success Metrics
All existing functionality preserved (feature parity)
Unit test coverage > 80% for domain and application layers
Overview
Refactor the SudoStart codebase from its current layered/component-based architecture to Hexagonal Architecture (Ports and Adapters pattern). This will improve testability, maintainability, and make the codebase more extensible for future features like Windows support, different AI providers, and additional package managers.
Current Architecture Issues
Proposed Architecture
Implementation Phases
Phase 1: Domain Layer Foundation ⏳
Estimated Time: 1 day
Tasks:
src/domain/entities/directory structurePackageentity with:Scriptentity with:Bucketentity with:Version(with validation)Platform(enum: macOS, Linux, Windows)Shell(enum: bash, zsh, fish)PackageRepository(findById, findByCategory, search)VersionRepository(fetchLatest, validateVersion)Acceptance Criteria:
Phase 2: Application Layer (Use Cases) ⏳
Estimated Time: 1-1.5 days
Tasks:
src/application/ports/for incoming portsGenerateScriptUseCaseChatWithAIUseCaseFetchVersionsUseCaseManageBucketUseCaseShareScriptUseCaseAcceptance Criteria:
Phase 3: Infrastructure Layer - Adapters ⏳
Estimated Time: 1.5-2 days
Tasks:
src/infrastructure/adapters/structure:Acceptance Criteria:
Phase 4: UI and API Refactoring ⏳
Estimated Time: 1 day
Tasks:
Files to Refactor:
src/components/script-output.tsx→ UseGenerateScriptUseCasesrc/components/chat-window.tsx→ UseChatWithAIUseCasesrc/components/package-manager.tsx→ UseManageBucketUseCasesrc/app/api/chat/route.ts→ Delegate to use casesrc/app/api/versions/route.ts→ Delegate to use casesrc/lib/script-generator.ts→ Move to domain serviceAcceptance Criteria:
Phase 5: Testing and Documentation ⏳
Estimated Time: 0.5-1 day
Tasks:
Testing Strategy:
Directory Structure After Refactoring
Benefits After Completion
Immediate Benefits:
Long-term Benefits:
Risks and Mitigation
Success Metrics
Related Resources
/docs/architecture/current-state.mdNotes
Overview
Refactor the SudoStart codebase from its current layered/component-based architecture to Hexagonal Architecture (Ports and Adapters pattern). This will improve testability, maintainability, and make the codebase more extensible for future features.
Current Problems
Proposed Solution
Implement Hexagonal Architecture with clear separation:
Domain Layer (Core)
Application Layer
Infrastructure Layer
Implementation Phases
Phase 1: Domain Layer Foundation [1 day]
Phase 2: Application Layer [1-1.5 days]
Phase 3: Infrastructure Adapters [1.5-2 days]
Phase 4: UI/API Refactoring [1 day]
Phase 5: Testing & Documentation [0.5-1 day]
Benefits
✅ Testability: Unit test business logic without React components
✅ Flexibility: Swap AI providers (Groq ↔ OpenAI ↔ Anthropic) with single file change
✅ Platform Support: Add Windows (Winget/Chocolatey) by creating new adapter
✅ Maintainability: Changes to UI don't affect business logic
✅ Team Scaling: Frontend and backend developers work independently
Success Metrics
Risks
Resources
/docs/tickets/hexagonal-architecture-refactor.md/docs/tickets/hexagonal-refactor-diagram.mdEstimated Effort
3-5 days across 5 phases
Priority
High - Blocks Windows support and AI provider flexibility
Labels
architecture,refactoring,technical-debt,hexagonal,enhancementOption 2: Using GitHub Web Interface
architecture,refactoring,technical-debt,enhancementRelated Files Created
Detailed Ticket:
docs/tickets/hexagonal-architecture-refactor.mdVisual Reference:
docs/tickets/hexagonal-refactor-diagram.mdThis Template:
docs/tickets/github-issue-template.md