Submission for the **Hacktoberfest Open-Source AI Challenge: Week 3 (Slow and Steady / Sloth Edition)* in the Best Use of Gemma category.*
π¦₯ The "Sloth Developer" Problem: Understanding Legacy Codebases
Software engineers are famously passionate about working smart instead of working hard. But there is one task every developer dreads: being dropped into an unfamiliar, 50-file legacy Python repository without architectural documentation and being told: "Figure out how this works."
Normally, you spend hours:
- Clicking through dozens of nested directories,
- Tracing obscure import statements across packages,
- Manually drawing box-and-arrow diagrams on whiteboards,
- Getting bit by nasty runtime
ImportError: cannot import name ... from partially initialized modulecircular import bugs.
This is tedious cognitive labor. In the spirit of International Sloth Day, why spend mental energy deciphering spaghetti architecture when we can let open-source AI and deterministic compilers do the heavy lifting for us?
Meet RepoGraph β a sub-0.1-second deterministic Python architecture scanner coupled with an open-weight Google Gemma 2 AI architect engine.
With a single terminal command:
python repograph.py ./my-project
RepoGraph deterministically parses your code's Abstract Syntax Tree (AST), clusters your modules into architectural tiers, feeds the topology to Google Gemma, and produces an interactive, zoomable blueprint in your browser with circular dependency refactoring recipes.
π Try the Live Web Demo (GitHub Pages)
π¦ GitHub Repository
π‘ Why Open Innovation Matters for What You Built
Judges Prompt Response: Why Open Innovation Matters for What You Built
When designing AI developer tooling, the default instinct for many is to pipe code into a closed cloud LLM API (like OpenAI or Claude). For RepoGraph, closed AI was a complete non-starter. Open innovation through Google's open-weight Gemma family was the foundational architectural decision for three critical reasons:
1. Absolute Data Sovereignty & IP Privacy
Private repositories, fintech codebases, healthcare backends, and proprietary algorithms cannot leave developer machines. Enterprise compliance (SOC2, HIPAA, GDPR) strictly prohibits exfiltrating unreleased source code to closed corporate cloud APIs where data might be retained, logged, or used for model training.
Because Gemma 2 (gemma2:2b, gemma2:9b) is fully open-weight, developers can run it 100% locally on their own laptop or air-gapped workstations using Ollama or llama.cpp. Not a single line of proprietary source code ever crosses the network boundary.
2. Zero Token Costs & Zero Rate Limits
Closed APIs charge per token. A developer analyzing large repositories with dozens of modules repeatedly during daily refactoring cycles would quickly accumulate non-trivial API bills and hit rate limits.
With open-weight Gemma, the marginal cost of running architectural analysis is $0.00. You can analyze 100 codebases a day without an API key, without a credit card, and without an internet connection.
3. Open Hybrid Pipeline: Determinism + Generative Reasoning
Closed LLMs hallucinate dependencies, miss edge cases, and take 10+ seconds to process raw files.
Open innovation allowed us to construct a hybrid two-tier architecture:
-
Tier 1 (Compiler Speed): Python's open standard library
astparses class hierarchies, method signatures, and imports deterministically in < 0.05 seconds. -
Tier 2 (Open-Weight Reasoning): Google's lightweight
gemma2:2bdigests the extracted semantic structure to identify design patterns, calculate architectural health scores, and write refactoring recipes.
If the developer is offline on an airplane without an active local AI daemon, RepoGraph's built-in offline synthesis engine kicks in gracefully. The tool never fails.
ποΈ Architecture Pipeline
RepoGraph operates as an end-to-end, zero-dependency pipeline:
βββββββββββββββββββββββββββββββββββ
β Target Python Repo β
ββββββββββββββββββ¬βββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββ
β Python Native AST Engine β < 0.1s execution (Zero external pip deps)
β - Class hierarchies & methods β
β - Public functions & docstringsβ
β - Relative/subpackage imports β
β - Cyclomatic branch complexity β
ββββββββββββββββββ¬βββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββ
β Architectural Layer Classifier β Deterministic layer clustering
β - Application Entry β (Entry, API, Core, Data, Utils, Config)
β - Cycle Detection (Tarjan DFS) β
ββββββββββββββββββ¬βββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββ
β Google Gemma 2 AI Architect β Open-weight local intelligence
β - Executive System Narrative β (Ollama / llama.cpp / Groq / Offline fallback)
β - Design Pattern Detection β Data Sovereignty: 0 private code leaves your laptop
β - Cycle Refactoring Recipes β
β - Architecture Health Score β
ββββββββββββββββββ¬βββββββββββββββββ
β
βββββββββ΄ββββββββ
β β
βΌ βΌ
ββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββββββ
β ARCHITECTURE.mdβ β index.html & repograph.html β
β Mermaid GitHub β β Interactive Canvas (Pan, Zoom, Highlight)β
β + Gemma Report β β + Interactive Gemma AI Architect Modal β
ββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββββββ
π€ Inside the Gemma AI Architect Engine
RepoGraph leverages Google's Gemma 2 to turn dry dependency lists into deep architectural intelligence:
1. Executive Architectural Narrative
Instead of reading 20 files, Gemma synthesizes a concise executive summary explaining the primary purpose, responsibilities, and structural boundaries of the codebase.
2. Design Pattern Detection
Gemma analyzes the relationship graph and class naming conventions to automatically flag architectural design patterns:
- Clean N-Tier Layered Architecture (Interface β Core β Storage separation)
- Dispatcher & Facade Pattern (Centralized routing layers)
- Core Domain Workflow Orchestrator (Stateful business logic coordinators)
- Data Entity & Domain Model (Structured persistence entities)
- Stateless Shared Service Provider (Cryptographic and string utilities)
3. Actionable Circular Dependency Refactoring Recipes
When cyclic imports are detected (routes.py β engine.py β routes.py), RepoGraph doesn't just display an error. Gemma provides a concrete, 3-step refactoring recipe based on the Dependency Inversion Principle (DIP):
- Extract shared interfaces or DTOs into a dedicated module,
- Invert dependencies so high-level modules depend on abstractions,
- Eliminate runtime import hazards.
4. Per-Module Role Explanations in the Inspector Drawer
Clicking on any file in the interactive web canvas opens an inspector drawer where Gemma provides a dedicated synopsis of that specific module's architectural role within the larger system.
π¨ Interactive Blueprint Highlights
The generated index.html is a standalone, self-contained single-page application with zero third-party JavaScript dependencies:
- Infinite Vector Canvas: Smooth drag-to-pan, scroll-to-zoom, and mobile touch pinch-to-zoom using a custom SVG transform matrix engine.
- Bidirectional Pathway Lighting: Click any module to illuminate callers in emerald green and dependencies in cyan, with glowing vector edges while dimming unrelated code.
- Circular Dependency Radar: Cycles are highlighted in vivid crimson, with direct links in the top navigation modal.
- Orientation Switcher (T): Instantly toggle between Top-Down (TD) and Left-to-Right (LR) layouts.
- Gemma Modal (G or A): Dedicated full-screen modal showing the Gemma AI report, health score, detected patterns, and actionable recommendations.
-
Multi-Format Exports: Export vector SVG (with embedded styling for Figma/draw.io), Mermaid Markdown, or auto-generated
ARCHITECTURE.md.
π How to Run RepoGraph in 10 Seconds
RepoGraph requires zero external pip dependencies. All you need is Python 3.9+:
Step 1: Clone and Run
git clone https://github.com/sharan-s-dev/RepoGraph-.git
cd RepoGraph-
# Analyze any local repo
python repograph.py ./my-project --serve
Step 2: Use Local Gemma with Ollama (Optional)
If you have Ollama installed:
ollama run gemma2:2b
python repograph.py ./my-project --ai-provider ollama
RepoGraph will automatically detect your local Gemma runner on port 11434 and execute live local inference!
π§ͺ Rigorous Engineering & Unit Testing
RepoGraph includes a comprehensive multi-platform unit test suite tested on Windows, macOS, and Linux:
-
astvisitor signature extraction - Subpackage and multi-root import resolution across
src/and nested directories - Circular dependency cycle detection (Tarjan DFS)
- Gemma AI Architect prompt generation, pattern synthesis, and cycle remediation recipes
- Resilient HTML generation
python -m unittest discover tests
# Ran 21 tests in 0.525s - OK!
π Summary
The DEV.to Hacktoberfest "Slow and Steady" challenge reminded us that the best developers aren't the ones who grind through manual boilerplate β they're the ones who automate the friction away.
By combining the sub-0.1s mathematical precision of native AST parsing with the open-weight reasoning of Google's Gemma 2, RepoGraph lets developers offload codebase archaeology and get straight to building.
- π Live Demo: https://sharan-s-dev.github.io/RepoGraph-/
- π» Source Code: https://github.com/sharan-s-dev/RepoGraph-
- π License: MIT Open Source
Built with β€οΈ for Hacktoberfest 2026.
Top comments (1)
"The hybrid two-tier architecture: determinism for structure, generative reasoning for interpretation" is the right design, and it's the one most "AI code analysis" tools get wrong.
Most tools just dump the whole repo into a context window and ask the model to "find the architecture". That's slow, expensive, and hallucinates dependencies. Your approach β parse the AST deterministically, then let Gemma interpret the structure β is much more reliable, because the model isn't guessing what imports what.
Curious how Gemma handles the "the codebase is 500 files" case. Does the prompt get truncated, or do you summarize the AST before sending it?