Skip to content

Synapse uses a hybrid refactoring engine. It runs 50+ ultra-fast rule-based checks for instant fixes and falls back to a deterministic refactoring engine when AI providers are rate-limited, ensuring reliable output and zero downtime.

Notifications You must be signed in to change notification settings

Team-TechTonics/Synapse

Β 
Β 

Repository files navigation

πŸš€ Synapse - AI-Powered Code Refactoring Engine

Synapse Banner

Live Demo VS Code Extension Backend API License

Transform messy code into production-ready masterpieces with context-aware AI refactoring

Try Live Demo β€’ Install VS Code Extension β€’ API Docs β€’ Architecture


πŸŽ‰ NEW: VS Code Extension Available!

Install Synapse directly in your editor:

Option 1: VS Code Marketplace (Verifying - Available Soon)

# Search "Synapse" in VS Code Extensions
# OR visit: https://marketplace.visualstudio.com/items?itemName=synapseai.synapse-refactor

Option 2: Install from VSIX (Available NOW)

  1. Download synapse-refactor-0.1.0.vsix
  2. In VS Code: Ctrl+Shift+X β†’ ... menu β†’ "Install from VSIX..."
  3. Select the downloaded file
  4. Use: Select code β†’ Press Ctrl+Shift+R

Features:

  • ⚑ Instant refactoring (Ctrl+Shift+R)
  • πŸ” Real-time smell detection
  • πŸ“Š Complexity metrics
  • 🎨 Side-by-side diff preview
  • ⚠️ Risk scoring
  • 🌐 Powered by the same API as our web app

🎯 What is Synapse?

Synapse is an intelligent code refactoring engine that learns from your repository's patterns and coding style to provide context-aware, production-safe refactoring suggestions. Unlike generic AI tools, Synapse understands your codebase's unique DNA.

✨ Core Features

🧠 Repository-Aware Intelligence

  • Pattern Learning: Analyzes your existing codebase to understand coding conventions
  • Style Enforcement: Automatically matches indentation, naming, and structure
  • Context Understanding: Adapts suggestions based on file type and project architecture

πŸ” Advanced Code Analysis

  • 40+ Rule-Based Detections: Fast, deterministic smell detection
  • AI-Powered Deep Analysis: Context-aware refactoring powered by OpenRouter/Gemini
  • Hybrid Approach: Combines rule-based and AI analysis for maximum accuracy

🎨 Production-Ready UX

  • Code Health Score: Visual before/after quality metrics (A-D grading)
  • Risk-Aware Refactoring: Every change tagged with risk level (Low/Medium/High)
  • GitHub-Style Diffs: Side-by-side comparison with syntax highlighting
  • One-Click Safe Apply: Automatically filters and applies low-risk changes

πŸ“Š Explainable AI

  • Why It Changed: Each refactor includes detailed explanations
  • Smell Identification: Clear description of detected anti-patterns
  • Impact Metrics: Shows complexity reduction, time savings, code lines saved

πŸ”„ Feedback-Driven Learning Loop

  • User Feedback: Thumbs up/down on suggestions
  • Pattern Memory: Remembers rejected/accepted patterns
  • Adaptive Suggestions: Continuously improves based on preferences

πŸš€ Live Demo

Sample Workflow:

  1. Paste code or GitHub URL
  2. Select optimization mode (Clean Code, Performance, Security, Readability)
  3. Choose language (Auto-detect, JavaScript, React, Python, Java)
  4. Click "ANALYZE & REFACTOR"
  5. View stunning results with metrics & diff

πŸ† Why Synapse Wins Hackathons

Feature Synapse ChatGPT SonarQube
Context-Aware βœ… Learns from your repo ❌ Generic ⚠️ Rule-based only
Multi-Language βœ… JS, React, Python, Java βœ… Yes ⚠️ Limited
Risk Assessment βœ… Low/Medium/High tags ❌ No ❌ No
Explainability βœ… Detailed "why" ⚠️ Sometimes ❌ No
GitHub Integration βœ… Direct repo analysis ❌ No βœ… Plugin
Real-Time Diff βœ… Side-by-side ❌ No ⚠️ Separate UI
Feedback Loop βœ… Learning from usage ❌ No ❌ No

πŸ› οΈ Tech Stack

Frontend

  • React 18 + Vite - Lightning-fast development
  • Monaco Editor - Professional code editing
  • Lucide React - Beautiful icons
  • Custom CSS - Premium dark mode UI

Backend

  • Node.js + Express - Robust API server
  • Modular Pipeline - Extensible architecture
  • OpenRouter/Gemini - Multi-model AI support
  • PostgreSQL + SQLite - Dual persistence strategy

Deployment

  • Frontend: Vercel (CDN, auto-deploy)
  • Backend: Render (auto-scale, always-on)
  • Database: Supabase (managed PostgreSQL)

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      User Request                           β”‚
β”‚           (Code/URL + Language + Preferences)               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 Language Adapter Factory                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”‚
β”‚  β”‚ JS/React β”‚  Python  β”‚   Java   β”‚   Auto   β”‚             β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Static Smell Analyzer (Fast)                    β”‚
β”‚    β€’ 40+ Rule-Based Checks                                  β”‚
β”‚    β€’ Language-Agnostic + Language-Specific                  β”‚
β”‚    β€’ O(n) Complexity                                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 Prompt Builder                               β”‚
β”‚    β€’ Dynamic JSON Schema                                    β”‚
β”‚    β€’ Language Constraints                                   β”‚
β”‚    β€’ Context Injection                                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  AI Client                                   β”‚
β”‚    β€’ OpenRouter (multi-model)                               β”‚
β”‚    β€’ Gemini (fast, free tier)                               β”‚
β”‚    β€’ Fallback to Simulation Mode                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Post Processor & Validator                      β”‚
β”‚    β€’ JSON Parsing                                           β”‚
β”‚    β€’ Safety Validation                                      β”‚
β”‚    β€’ Error Recovery                                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 Refactor Repository                          β”‚
β”‚    β€’ SQLite (anonymous users)                               β”‚
β”‚    β€’ PostgreSQL (authenticated users)                       β”‚
β”‚    β€’ Dual Persistence                                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Frontend Display                           β”‚
β”‚    β€’ Code Health Score                                      β”‚
β”‚    β€’ Metrics Dashboard                                      β”‚
β”‚    β€’ Diff Viewer                                            β”‚
β”‚    β€’ Feedback Loop                                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“¦ Installation & Setup

Prerequisites:

  • Node.js 18+
  • Git
  • (Optional) PostgreSQL database

1. Clone Repository

git clone https://github.com/ramanuj077/Synapse.git
cd Synapse

2. Install Dependencies

# Frontend
npm install

# Backend
cd backend
npm install

3. Configure Environment

Create backend/.env:

# AI API (Choose one)
OPENROUTER_API_KEY=sk-or-v1-xxxxx
# OR
GEMINI_API_KEY=xxxxx

# Database (Optional - SQLite used by default)
DATABASE_URL=postgresql://user:pass@host:5432/db

# Security
JWT_SECRET=your-secret-key
NODE_ENV=development

4. Run Development Servers

# Terminal 1: Frontend
npm run dev

# Terminal 2: Backend
cd backend
npm run dev

5. Open Browser

http://localhost:5173

πŸ”Œ API Usage

Analyze Code (Single File)

POST /api/analyze
Content-Type: application/json

{
  "code": "function calculateTotal(items) { ... }",
  "language": "javascript",
  "refactorType": "clean-code"
}

Response:

{
  "id": "1735123456789",
  "refactored_code": "const calculateTotal = (items) => { ... }",
  "smell_detected": "var usage detected (ES6+ uses const/let)",
  "explanation": "Refactored to modern ES6+ syntax...",
  "metrics": {
    "complexity_before": 5,
    "complexity_after": 2,
    "time_complexity_before": "O(nΒ²)",
    "time_complexity_after": "O(n)",
    "risk_score": 2,
    "lines_saved": 3
  }
}

Analyze GitHub Repository

POST /api/repo/analyze
Content-Type: application/json

{
  "repoUrl": "https://github.com/facebook/react"
}

🎯 Roadmap

Phase 1: Core Engine βœ… COMPLETE

  • Modular pipeline architecture
  • Language adapters (JS, React, Python, Java)
  • Rule-based smell detection
  • AI integration (OpenRouter/Gemini)
  • Dual persistence (PostgreSQL + SQLite)

Phase 2: Production Features βœ… COMPLETE

  • GitHub repository analysis
  • Interactive diff viewer
  • Code health scoring
  • Risk-aware refactoring
  • Feedback loop UI

Phase 3: Enterprise 🚧 IN PROGRESS

  • VS Code extension
  • IntelliJ plugin
  • Pre-commit hooks
  • Team dashboards
  • Custom rule definitions

Phase 4: Intelligence πŸ“… PLANNED

  • Natural language refactoring ("make this safer")
  • Multi-file dependency analysis
  • Performance benchmarking
  • Auto-generated documentation

🀝 Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.


πŸ“„ License

MIT License - see LICENSE for details.


🌟 Star History

If Synapse helps you write better code, give us a star! ⭐


Built with ❀️ for developers who care about code quality

⬆ Back to Top

About

Synapse uses a hybrid refactoring engine. It runs 50+ ultra-fast rule-based checks for instant fixes and falls back to a deterministic refactoring engine when AI providers are rate-limited, ensuring reliable output and zero downtime.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 92.5%
  • CSS 7.2%
  • HTML 0.3%