Skip to content

Feasibility Analysis: Refactoring MyCoder from TypeScript to Clojure/Babashka #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
4 tasks
bhouston opened this issue Apr 27, 2025 · 2 comments
Open
4 tasks
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@bhouston
Copy link
Member

Overview

This issue analyzes the feasibility and implications of refactoring the entire MyCoder codebase from TypeScript to Clojure with Babashka runtime.

Current Codebase Assessment

  • MyCoder is a TypeScript/JavaScript monorepo with three main packages:

    • cli: Command-line interface for MyCoder
    • agent: Core AI agent system
    • docs: Documentation website
  • The codebase consists of approximately 108 TypeScript files

  • Uses modern JavaScript/TypeScript features and ecosystem tools

  • Has a well-structured architecture with clear separation of concerns

  • Relies on npm/pnpm for package management

  • Has an established testing framework (Vitest)

Key Dependencies

  • LLM integrations (Anthropic Claude, OpenAI)
  • Browser automation via Playwright
  • Various Node.js utilities and libraries
  • Semantic release for versioning

Clojure/Babashka Capabilities

  • Clojure is a dynamic, functional programming language that runs on the JVM
  • Babashka is a native Clojure scripting runtime with fast startup time
  • Babashka includes many built-in libraries for scripting tasks
  • Supports multi-threading and has good interop capabilities

Refactoring Implications

Potential Benefits

  • Functional programming paradigm may align well with AI agent workflows
  • Immutable data structures could simplify state management
  • Clojure's macro system could provide powerful abstractions
  • Babashka offers fast startup times for CLI applications
  • Potential for more concise code in some areas

Challenges and Considerations

  1. Ecosystem Compatibility:

    • Need to find/create Clojure equivalents for all current dependencies
    • LLM client libraries would need to be rewritten or wrapped
    • Browser automation would require interop with Playwright or alternative solutions
  2. Development Infrastructure:

    • Complete rewrite of build system, testing framework, and CI/CD pipeline
    • New deployment processes for all components
    • Developer experience changes requiring team retraining
  3. Maintenance Burden:

    • Parallel maintenance during transition period
    • Documentation updates across the entire codebase
    • Potential for regressions during rewrite
  4. Community Impact:

    • Smaller ecosystem and community compared to TypeScript/JavaScript
    • Fewer available libraries and integrations
    • Steeper learning curve for new contributors
  5. Time and Resource Investment:

    • Complete rewrite would require significant developer time
    • Extensive testing to ensure feature parity
    • Potential delays in roadmap for new features

Recommendation

Before proceeding with a full refactoring effort, consider:

  1. Creating a proof-of-concept for a limited component to evaluate feasibility
  2. Starting with a smaller, non-critical package to test the approach
  3. Evaluating specific pain points in the current TypeScript implementation that Clojure might address
  4. Considering a gradual approach where new features are written in Clojure while maintaining existing TypeScript code

Next Steps

  • Gather input from team members on this analysis
  • Create a small proof-of-concept implementation of a core component
  • Benchmark TypeScript vs Clojure implementations for key workflows
  • Develop a more detailed migration plan if the team decides to proceed
@bhouston bhouston added enhancement New feature or request help wanted Extra attention is needed labels Apr 27, 2025
@bhouston
Copy link
Member Author

Issue Triage Analysis

Thank you for this comprehensive feasibility analysis for refactoring MyCoder from TypeScript to Clojure/Babashka. I've conducted a thorough review of the codebase to assess the feasibility and implications of this proposal.

Categorization

  • Issue Type: Enhancement (architectural change proposal)
  • Labels Applied: enhancement, help wanted

Codebase Analysis Summary

I've analyzed the current MyCoder codebase and found:

  1. Size and Structure:

    • 108 TypeScript files (~14K lines of code)
    • Monorepo with 3 main packages (agent: 90 files, cli: 16 files, docs: 2 files)
    • Moderately complex architecture with well-defined separation of concerns
  2. TypeScript-Specific Features:

    • Extensive use of TypeScript's type system (interfaces, union types, generics)
    • Heavy reliance on async/await patterns
    • ES Modules with modern JavaScript features
    • Class-based implementations for key components
  3. Critical Dependencies:

    • LLM integration libraries (@anthropic-ai/sdk, openai, ollama)
    • Browser automation via Playwright
    • CLI framework (yargs)
    • Schema validation (zod)
    • Various Node.js utilities
  4. Build & Testing:

    • Vitest for testing (36 test files)
    • PNPM workspace for monorepo management
    • TypeScript compilation
    • GitHub Actions for CI/CD

Migration Feasibility Assessment

Challenges:

  1. Paradigm Shift: Major shift from imperative/OOP to functional programming
  2. Type System: Replacing TypeScript's static typing with Clojure's dynamic typing + spec
  3. Async Model: Adapting extensive async/await patterns to Clojure's concurrency model
  4. Ecosystem Gaps: Finding equivalent Clojure libraries for all current dependencies
  5. Developer Experience: Potential learning curve for team members not familiar with Clojure
  6. Maintenance Burden: Parallel maintenance during transition period

Potential Benefits:

  1. Functional Paradigm: May align well with agent workflows
  2. Immutable Data: Could simplify state management
  3. Concurrency Model: Potentially better handling of parallel operations
  4. Startup Time: Babashka offers fast startup for CLI applications
  5. Code Conciseness: Potentially more concise code in some areas

Recommendation

I agree with the approach suggested in the issue:

  1. Proof of Concept: Create a small proof-of-concept for a limited component
  2. Gradual Approach: Consider starting with a smaller, non-critical package
  3. Specific Pain Points: Evaluate specific areas where Clojure might provide significant benefits
  4. Team Input: Gather feedback from the development team on this proposal

This approach allows for incremental evaluation without committing to a full rewrite upfront.

Next Steps

  1. Community Input: Since this is a major architectural decision, it would be valuable to get input from the wider community
  2. Benchmarking: Create benchmarks comparing TypeScript vs. Clojure implementations for key workflows
  3. Learning Resources: If proceeding, compile Clojure/Babashka learning resources for the team
  4. Migration Plan: Develop a detailed migration strategy if the team decides to move forward

I'm happy to provide further analysis or answer any questions about this assessment.

@bhouston
Copy link
Member Author

I've created a follow-up issue to propose a proof-of-concept implementation as suggested in the feasibility analysis:

#396 Create Clojure/Babashka Proof of Concept for a Core Component

This will allow for a more concrete evaluation of the migration approach with a smaller, manageable scope before making decisions about the larger refactoring effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant