Skip to content

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 DemoInstall VS Code ExtensionAPI DocsArchitecture


🎉 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 EngineCOMPLETE

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

Phase 2: Production FeaturesCOMPLETE

  • 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

 
 
 

Contributors

Languages

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