Refactory
Decomposes monolithic JavaScript source files into clean modules using mechanical extraction with deterministic function boundary detection, automatic import resolution, and syntax validation.
Decomposes Kotlin source files into modules using mechanical extraction with function boundary detection and import resolution (available in Pro tier).
Decomposes Python monoliths into clean modules using mechanical extraction with automatic function boundary detection, import resolution, and syntax validation.
Decomposes Rust source files into modules using mechanical extraction with deterministic parsing and import resolution (available in Pro tier).
Decomposes Swift source files into modules using mechanical extraction with function boundary detection and import resolution (available in Pro tier).
Decomposes TypeScript source files into modular components using mechanical extraction while preserving type annotations, with automatic import resolution and deterministic parsing.
Refactory
Hybrid code decomposition. AI plans the boundaries. A deterministic engine handles the routine extractions. Minimize tokens, maximize syntax validity.
Refactory splits monolith source files into clean modules. It uses an LLM for one thing — deciding which functions group together. Everything else is mechanical: function boundary detection, import resolution, module assembly, syntax validation, scoring.
JavaScript and Python extraction is mostly mechanical. The deterministic engine handles the straightforward moves — the routine 80% that's a waste of AI time and tokens. The LLM still handles complex edge cases where judgment matters. Other languages use LLM extraction with adaptive compression.
Works with Claude Code, Cursor, Windsurf, VS Code Copilot — any MCP client. Or use the CLI directly.
Results
Tested against 15 production monoliths:
Metric | Value |
Lines decomposed | 32,736 |
Functions extracted | 1,017 |
Pipeline score | 0.89 |
Mechanical extraction ratio | ~80% |
API cost (extraction) | Near zero |
Related MCP server: loctree-mcp
Quick Start
MCP (recommended)
Add to your .mcp.json:
{
"mcpServers": {
"refactory": {
"command": "npx",
"args": ["@refactory/mcp"],
"env": {
"GROQ_API_KEY": "your-key-here"
}
}
}
}Then tell your AI tool: "Analyze and decompose src/big-file.js into modules"
One free API key (Groq or Gemini) is needed for the PLAN step only. Extraction is mechanical — no key required for JS/Python.
CLI
git clone https://github.com/codedrop-codes/refactory.git
cd refactory && npm install
node src/cli.js decompose src/big-file.jsOther commands:
refactory analyze src/big-file.js # Health check + function map
refactory plan src/big-file.js # Generate module boundaries (needs LLM key)
refactory verify lib/modules/ # Check extracted modules
refactory languages # Show supported languages
refactory providers # Show configured LLM providers
refactory test submit broken.js # Submit a file that breaks extraction
refactory test run # Validate preprocessors against test corpusHow It Works
1. ANALYZE Scan functions, dependencies, health — mechanical
|
2. CHARACTERIZE Snapshot exports before touching anything — mechanical
|
3. PLAN LLM decides module boundaries — the only AI step
|
4. EXTRACT Copy functions by line range, resolve imports — mechanical
| (LLM fallback for unsupported languages)
5. FIX-IMPORTS Rewrite require()/import paths — mechanical
|
6. VERIFY Syntax check, load check, export comparison — mechanical
|
7. METRICS Refactory Score + HTML report — mechanical6 of 7 steps are deterministic. The LLM only decides where to split — it never touches your code.
Language Support
Language | Extraction | Status |
JavaScript / TypeScript | Mechanical | Built in |
Python | Mechanical | Built in |
Go, Rust, Java, C#, Kotlin, Swift | Mechanical | |
Everything else | LLM with compression | Automatic fallback |
Mechanical extraction handles the routine cases: the preprocessor finds function boundaries by parsing, copies them by line range, and resolves imports deterministically. Complex patterns (dynamic exports, deeply interleaved logic) still go through the LLM.
Contribute a preprocessor for your language.
Refactory Score
A single number (0.0 to 1.0) that measures decomposition quality.
Score = clean_rate × size_reductionclean_rate — modules that load without errors / total modules
size_reduction — 1 − (largest module / original file)
A score of 1.0 means every module loads cleanly and no module is bigger than the original.
Provider Routing
You only need one free key for the PLAN step. Extraction is mechanical for supported languages.
Provider | Output | Context | Free? |
Groq Llama 3.3 70B | 32k | 128k | Yes |
Gemini 2.5 Flash | 16k | 1M | Yes |
OpenRouter Qwen 3.6+ | 16k | 1M | Yes |
SambaNova MiniMax | 16k | 163k | Yes |
Set at least one: GROQ_API_KEY, GOOGLE_API_KEY, OPENROUTER_API_KEY, or SAMBANOVA_API_KEY.
Test Corpus
Found a file that breaks extraction? Submit it:
refactory test submit broken-file.js -d "what went wrong"Secrets are stripped automatically. Every submission becomes a permanent test case. The extractor gets stronger with every report.
Report via GitHub if you prefer.
Community
Discord — Help, ideas, show your results
Discussions — Feature requests, language requests
Issues — Bug reports
Contributing — Build a preprocessor, submit test files
License
AGPL-3.0 — see LICENSE.
Premium language packs available under commercial license. See refactory.codedrop.codes.
Available Tools
11 toolsrefactory_analyzeB
Analyze a source file for decomposition. Returns health score, function count, dependency graph, and recommended split points.
Inputs: file (required), language.
refactory_characterizeA
Generate characterization tests and golden export snapshot BEFORE decomposition. Captures behavioral contract.
Inputs: file (required), outputDir.
refactory_decomposeA
Full decomposition pipeline in one call: analyze, depmap, characterize, plan, extract ALL modules, fix-imports, verify, metrics, re-export, report. The 'just do it' tool.
Inputs: file (required), outputDir, maxLines, projectDir.
refactory_depmapA
Map dependencies for a file — who requires it (consumers), what it requires (dependencies), detect circular deps.
Inputs: file (required), projectDir.
refactory_extractC
Extract one module from the monolith according to the plan. Routes to the cheapest capable free LLM API.
Inputs: file (required), module (required), functions, outputDir, +1 more.
refactory_fix_importsA
Mechanically fix broken require() paths after module extraction. No LLM needed — pure path resolution.
Inputs: moduleDir (required), projectDir, dryRun.
refactory_metricsB
Calculate before/after metrics and the Refactory Score (0-1). Measures health improvement, module quality, test preservation.
Inputs: original (required), moduleDir (required), testResults.
refactory_planA
Generate a decomposition plan — module boundaries, function assignments, dependency order. Uses AST analysis + LLM reasoning.
Inputs: file (required), modules, maxLines, style.
refactory_reportA
Generate a decomposition report with metrics, dependency graphs, and Refactory Score. Outputs Markdown or HTML.
Inputs: metricsFile (required), format, outputPath.
refactory_verifyB
Verify a decomposed module: loads without errors, exports match plan, no circular deps, tests pass.
Inputs: moduleDir (required), original, testCmd.
refactory_verify_exportsA
Compare post-decomposition module against golden export snapshot. Reports missing, added, or type-changed exports.
Inputs: goldenFile (required), newFile (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
TDQS
Scored across 11 tools
Each tool has a distinct and clearly defined purpose within the decomposition pipeline—analyze, characterize, decompose, depmap, extract, fix imports, metrics, plan, report, verify, verify exports. There is no overlap or ambiguity between them; an agent can easily select the correct tool for each step.
All tools follow the consistent pattern 'refactory_verb_noun' (e.g., refactory_analyze, refactory_fix_imports, refactory_verify_exports). The naming is uniform, predictable, and uses only snake_case, making it easy for an agent to infer functionality from the name.
With 11 tools, the server is well-scoped for its domain of code decomposition. Each tool serves a necessary step in the pipeline, and the count is neither too low (missing functionality) nor too high (unwieldy). The tool set earns its place.
The tools cover the entire decomposition lifecycle: analysis, characterization, dependency mapping, planning, extraction, import fixing, verification, metrics, reporting, and export verification. There are no obvious gaps; the surface is complete for the stated purpose of refactoring a monolithic file.
Related MCP Connectors
Code intelligence platform for AI agents. 20 tools for architecture, security & impact analysis.
AI-powered codebase analysis — call graphs, security, dead code, complexity. 150+ tools.
AI Agent with Architectural Memory. Impact analysis (free), tests and code from the graph (pro).
Codebase intelligence for agents: 152 structured artifacts across 21 programs, one call.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA graph-powered code intelligence engine that indexes codebases into a structural knowledge graph to provide AI agents with deep context on function calls, types, and execution flows. It offers local, zero-dependency tools for hybrid search, impact analysis, and dead code detection across Python, JavaScript, and TypeScript projects.1,023 PyPI816MIT

loctree-mcpofficial
FlicenseNot gradedqualityBmaintenanceStructural code intelligence for AI agents. Scan once, query everything — dead exports, circular imports, dependency graphs, and more. CLI + MCP server.6 npm10-- AlicenseAqualityCmaintenanceExtracts deterministic architecture maps from codebases for AI agents, enabling queries about blast radius, routes, security findings, and production readiness without sending code anywhere.627 PyPIMIT
- FlicenseNot gradedqualityBmaintenanceEnables agents to statically analyze Python source via AST traversal, computing McCabe cyclomatic complexity, cognitive nesting depth, and dependency graphs to pinpoint refactoring hotspots. It returns standardized refactoring plans, decomposition guidance, and code-metric telemetry with zero external dependencies.7-