<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Camilo </title>
    <description>The latest articles on DEV Community by Camilo  (@girardellibaptista).</description>
    <link>https://dev.to/girardellibaptista</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3866291%2F04cabfe8-4531-4f9b-a07f-24426ba9a9a5.png</url>
      <title>DEV Community: Camilo </title>
      <link>https://dev.to/girardellibaptista</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/girardellibaptista"/>
    <language>en</language>
    <item>
      <title>How I Built an Architecture Analyzer with Tree-Sitter AST (and What I Learned About Code Quality Metrics)</title>
      <dc:creator>Camilo </dc:creator>
      <pubDate>Tue, 07 Apr 2026 17:22:27 +0000</pubDate>
      <link>https://dev.to/girardellibaptista/how-i-built-an-architecture-analyzer-with-tree-sitter-ast-and-what-i-learned-about-code-quality-4m0c</link>
      <guid>https://dev.to/girardellibaptista/how-i-built-an-architecture-analyzer-with-tree-sitter-ast-and-what-i-learned-about-code-quality-4m0c</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj1q8qkdcfsrjoark8idf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj1q8qkdcfsrjoark8idf.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every codebase I've worked on in 19 years had the same story: the architecture starts clean, then slowly rots. Someone imports from the wrong layer. A utility class grows into a God Class. Circular dependencies creep in. By the time you notice in code review, refactoring is expensive.&lt;br&gt;
I wanted automated architecture checks — like ESLint for structure, not syntax.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Architect Genesis Does&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Architect Genesis is a CLI tool that analyzes your codebase architecture using Tree-Sitter AST parsing. It works with TypeScript, Python, Go, Java, Rust, Ruby, and PHP.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install and Run&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bashnpm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; @girardelli/architect
architect analyze ./src
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it. No config needed to start. It infers your stack, framework, and domain automatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What You Get&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Architecture Score (0-100) across four weighted dimensions:&lt;/p&gt;

&lt;p&gt;Dimension   Weight         What it measures&lt;br&gt;
Modularity   40%     How well-separated are your modules&lt;br&gt;
Coupling     25%       Cross-boundary dependency count&lt;br&gt;
Cohesion     20%     How related are elements within a module&lt;br&gt;
Layering.    15%     Clean layer separation (View/Core/Data/Infra)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Anti-pattern detection:&lt;/strong&gt;&lt;/em&gt; God Classes, Circular Dependencies, Leaky Abstractions, Spaghetti Modules. All derived from AST structure, not heuristics.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Layer detection:&lt;/strong&gt;&lt;/em&gt; Automatically classifies your code into View, Core, Data, and Infrastructure layers based on dependency patterns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Architecture as Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The real power is declaring rules in .architect.rules.yml:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;yamlquality_gates&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;min_overall_score&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;60&lt;/span&gt;
  &lt;span class="na"&gt;max_critical_anti_patterns&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
  &lt;span class="na"&gt;max_high_anti_patterns&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;

&lt;span class="na"&gt;boundaries&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;allow_circular_dependencies&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="na"&gt;banned_imports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;from&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;presentation/*"&lt;/span&gt;
      &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;infrastructure/*"&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;from&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;domain/*"&lt;/span&gt;
      &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;framework/*"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then plug into CI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;basharchitect check ./src
&lt;span class="c"&gt;# Exit code 0 = pass, 1 = fail&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Architecture violations now break the build.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AI-Assisted Refactoring&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When Architect finds problems, it generates a refactoring plan with 5 rule-based transformations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Hub Splitting — breaks up God Classes&lt;/li&gt;
&lt;li&gt;Barrel Optimization — cleans up index/init files&lt;/li&gt;
&lt;li&gt;Import Organization — restructures import paths&lt;/li&gt;
&lt;li&gt;Module Grouping — reorganizes related files&lt;/li&gt;
&lt;li&gt;Dead Code Detection — finds unreferenced exports&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Run &lt;code&gt;architect execute&lt;/code&gt; and it applies these using Claude, GPT, or Gemini — with human gating on every step. You approve, skip, retry with a different AI, or rollback. It creates a protective git branch and commits each step individually.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Predicting Architecture Decay&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;architect forecast&lt;/code&gt; command reads your git history, computes velocity-adjusted scoring, and runs ML-based regression to predict where your score will be in 3-6 months. You can see which modules are trending downward before it becomes a crisis.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technical Architecture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It's a monorepo with three packages:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;architect-core&lt;/em&gt; — Tree-Sitter AST parsing, scoring engine, rules engine&lt;br&gt;
&lt;em&gt;architect-agents&lt;/em&gt; — AI provider integration, stack/domain detection&lt;br&gt;
&lt;em&gt;architect CLI&lt;/em&gt; — reports (HTML/JSON/Markdown), GitHub Actions adapter&lt;/p&gt;

&lt;p&gt;Plus a VS Code extension (Architect Intelligence) with CodeLens integration and inline scoring.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I Learned Building This&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Scoring weights are hard.&lt;/em&gt; I calibrated 40/25/20/15 against ~30 codebases, but I'm not confident they generalize. A React SPA has different architecture concerns than a Spring Boot microservice. Context-aware weights might be the next step.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;AST beats regex.&lt;/em&gt; Early versions used pattern matching. Tree-Sitter was a game-changer — it gives you the real dependency graph, not approximations.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Human gating matters.&lt;/em&gt; I tried fully autonomous refactoring first. It was terrifying. The approve/skip/rollback model gives you AI speed with human judgment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where It's Heading&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The roadmap is to evolve from analyzer to intent compiler — describe the architecture you want, and the system generates the code. But that's the future. Today, v8.2.0 does analysis, scoring, validation, and assisted refactoring. And it does them well.&lt;/p&gt;

&lt;p&gt;Open source, MIT licensed.&lt;/p&gt;

&lt;p&gt;GitHub: &lt;a href="https://github.com/camilooscargbaptista/architect" rel="noopener noreferrer"&gt;https://github.com/camilooscargbaptista/architect&lt;/a&gt;&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>architecture</category>
      <category>devtools</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
