Skip to content

Latest commit

Β 

History

24 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐹 DPX-Go: Hexagonal Go Pattern Scanner & Architecture Engine

High-Performance Static Analysis & Software Design Pattern Detection for Go (Golang 1.18 - 1.24+)

Go Hexagonal DDD Rules License


🌟 Overview

DPX-Go is a next-generation static analysis and software design pattern detection engine designed specifically for Go (Golang) codebases. Built following strict Hexagonal Architecture (Ports & Adapters) and Domain-Driven Design (DDD) principles, DPX-Go detects Gang of Four (GoF) design patterns, idiomatic Go concurrency idioms (Channels, Pipelines, Fan-Out/Fan-In, Worker Pools, sync.Once), and architectural code smells (God Structs, Fat Interfaces, Goroutine Leaks).

πŸš€ Key Highlights

  • ⚑ Zero External Binaries / Blazing Fast: Native streaming Go lexer and balanced-delimiter parser capable of scanning thousands of Go files in sub-second speeds.
  • πŸ› οΈ Idiomatic Go Concurrency & Options: Specialized detection for Functional Options (WithPort()), Channel Pipelines, Fan-Out/Fan-In, Worker Pools, errgroup, and context.Context propagation.
  • πŸ›‘οΈ Safety & Resource Auditing: Detects Goroutine Leaks (unbounded loops without ctx.Done()) and unchecked errors (_ = fn()).
  • πŸ“Š Rich Multi-Format Reporting: Generates interactive dark Semantic UI HTML Dashboards, OASIS SARIF v2.1.0 (for GitHub Security Scanning), JSON, Markdown, and AI / LLM Architectural Context Maps.

πŸ—οΈ Architecture

                               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                               β”‚                    DPX-Go CLI                          β”‚
                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                           β”‚
                                                           β–Ό (ScanOptions)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                             APPLICATION LAYER                                                    β”‚
β”‚                                                                                                                  β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚   β”‚               ScanningService                │─────────────▢│              DetectionService              β”‚   β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚ (CodeModel)                                                β”‚ (Rules Execution)
                           β–Ό                                                            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    OUTBOUND PORTS                     β”‚  β”‚                     DOMAIN RULES                      β”‚
β”‚                                                       β”‚  β”‚                                                       β”‚
β”‚ β€’ NativeGoParserAdapter (Go 1.18+ AST / CST)          β”‚  β”‚ β€’ Creational: Functional Options, Builder, Factory    β”‚
β”‚ β€’ FileSourceProvider (.go files)                      β”‚  β”‚ β€’ Structural: Adapter, Decorator, Facade, Composite   β”‚
β”‚ β€’ HtmlReportFormatter (Dark Semantic UI Dashboard)    β”‚  β”‚ β€’ Behavioral: Strategy, Observer, Command, Visitor    β”‚
β”‚ β€’ SarifReportFormatter (OASIS SARIF v2.1.0)           β”‚  β”‚ β€’ Concurrency: Pipeline, Fan-In, Worker Pool, errgroupβ”‚
β”‚ β€’ Json / Markdown / LLM Context Formatters            β”‚  β”‚ β€’ SOLID & Safety: SRP, ISP, Goroutine Leaks, DRY     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“¦ Installation & Quick Start

# Clone the repository
git clone https://github.com/bivex/DPX-Go.git
cd DPX-Go

# Install dependencies using uv
uv sync

# Run the pattern scanner on any Go project
uv run dpx scan /path/to/your/go/project

# Generate an interactive HTML dashboard
uv run dpx scan /path/to/your/go/project -H report.html

# Generate GitHub SARIF for CI/CD
uv run dpx scan /path/to/your/go/project -S results.sarif

πŸ“‹ Catalog of Supported Patterns & Rules (40 Rules)

1. πŸ—οΈ Creational Patterns (6)

Pattern Detection Criteria
Functional Options Idiomatic Go creational pattern: type Option func(*Server), WithPort(), variadic ...Option.
Builder Fluent chaining setters returning *Builder with terminal Build() / Create() methods.
Factory Method Encapsulated constructor functions (New...(), NewFromConfig(), Open()).
Abstract Factory Interfaces declaring families of product creation methods (CreateConnection(), CreateTx()).
Singleton Thread-safe lazy global initialization via sync.Once (once.Do(func() { ... })).
Prototype Deep object cloning via explicit Clone() / DeepCopy() methods.

2. 🧩 Structural Patterns (7)

Pattern Detection Criteria
Adapter Structs wrapping adaptees (src, inner) implementing target interfaces (io.Reader, http.Handler).
Decorator / Middleware Wrapping inner interfaces/handlers to layer cross-cutting concerns (logging, auth, metrics).
Facade Aggregator structs simplifying access across 3+ subsystem packages behind a unified API.
Composite Part-whole tree hierarchies with slices of component interfaces ([]Component, []Node).
Proxy Surrogate objects holding target references to control access, caching, or remote RPC calls.
Bridge Decoupling struct abstraction from backend driver interfaces (driver.Driver, backend.Engine).
Flyweight Shared memory allocation reuse via sync.Pool or string interning caches.

3. 🎯 Behavioral Patterns (11)

Pattern Detection Criteria
Strategy Polymorphic algorithm interfaces or first-class function strategy types (type MatcherFunc func(...)).
Observer / Event Hub Multi-subscriber channel dispatchers (chan Event, map[string][]chan Event, Publish()).
Command Encapsulating requests as executable interfaces with Execute(ctx) / Undo().
Template Method Base struct workflows calling embedded interface steps in fixed template sequence.
Chain of Responsibility Onion middleware chains (func(http.Handler) http.Handler, handler successors).
Iterator Collection traversal via Next() / HasNext(), channels, or range-over-func.
Mediator Central coordinator managing communication channels between independent goroutines.
Memento Capturing internal struct state snapshots for restoration (SaveSnapshot() / Restore()).
Visitor AST traversal protocol via Visitor interfaces (Walk(v Visitor), Visit(node Node)).
Interpreter Grammatical expression evaluation over AST nodes (Eval(ctx Context) Value).
State Interface-based state machines and polymorphic state handlers.

4. ⚑ Go Concurrency & Idioms (8)

Pattern / Idiom Detection Criteria
Pipeline Channel stages taking <-chan T input and streaming transformed items to <-chan T output.
Fan-Out / Fan-In Merging multiple channel inputs into a single output channel using sync.WaitGroup.
Worker Pool Fixed number of worker goroutines consuming tasks from a shared jobs channel.
Generator Spawning a producer goroutine and returning a read-only receive channel (<-chan T).
Context Propagation Idiomatic passing of ctx context.Context as the first parameter for cancellations and timeouts.
ErrGroup Concurrency Coordinating concurrent subtasks with golang.org/x/sync/errgroup for automatic error handling.
Struct Embedding Idiomatic Go composition over inheritance via anonymous struct embedding.
Circular Dependency Detecting cross-package import cycles.

5. πŸ›‘οΈ SOLID Principles & Safety (8)

Principle / Smell Detection Criteria
Single Responsibility (SRP) God Structs: Structs with excessive methods (β‰₯15) or fields (β‰₯12).
Interface Pollution (ISP) Fat Interfaces: Interfaces with β‰₯8 methods (idiomatic Go prefers 1-2 method interfaces).
Open/Closed Principle (OCP) Rigid type switch cascades (switch v.(type)) with β‰₯5 cases that should use polymorphism.
Liskov Substitution (LSP) Methods calling panic("unimplemented") or unconditional errors in interface methods.
Dependency Inversion (DIP) Functions depending on interface abstractions (io.Reader, io.Writer) rather than struct pointers.
Keep It Simple (KISS) Functions with high cyclomatic complexity (β‰₯10) or long parameter lists (β‰₯5).
Don't Repeat Yourself (DRY) Identical function implementation logic duplicated across multiple locations.
Goroutine Leak Risk Goroutines running infinite loops or blocking channels without ctx.Done() or quit channels.
Unchecked Error Risk Explicitly ignored returned errors (_ = fn()).


🌐 The DPX Multi-Language Static Analysis Family (33 Languages)

# Language Repository Ecosystem & Focus
1 Ada bivex/DPX-Ada Ada 2012/2022, SPARK Contracts, Ravenscar Tasking, DO-178C Safety
2 Clojure bivex/DPX Lisp S-Expressions, Protocols, Multimethods
3 C bivex/DPX-C Memory Safety, Struct VTables, Idiomatic C11/C23
4 Cairo bivex/DPX-Cairo Starknet Smart Contracts, ZK-Rollup Invariants
5 C++ bivex/DPX-Cpp RAII, CRTP, Concepts, Modern C++20/23
6 C# bivex/DPX-CSharp .NET 9, Roslyn AST, Linq, Records
7 Dart bivex/DPX-Dart Dart 3.x, Flutter, BLoC, Riverpod, Isolates
8 Elixir bivex/DPX-Elixir BEAM OTP, GenServer, Supervisors
9 Erlang bivex/DPX-Erlang Fault Tolerance, Actor Model, OTP Behaviors
10 Gleam bivex/DPX-Gleam Type-Safe BEAM, Actor Concurrency
11 Go bivex/DPX-Go Goroutines, Channels, Composition, Interfaces
12 Haskell bivex/DPX-Haskell Pure Functional, Monads, Typeclasses, Arrows
13 Huff bivex/DPX-Huff Low-Level EVM Bytecode & Opcodes
14 Idris 2 bivex/DPX-Idris2 Dependent Types, QTT Linear Protocols, Totality, Proofs
15 Java bivex/DPX-Java Spring Boot, Enterprise Java, JVM Invariants
16 Julia bivex/DPX-Julia Multiple Dispatch, Scientific Computing
17 Kotlin bivex/DPX-Kotlin Coroutines, Multiplatform, Functional DSLs
18 Lua bivex/DPX-Lua Metatables, Coroutines, LuaJIT, Neovim
19 Mojo bivex/DPX-Mojo SIMD Hardware, Memory Lifetimes, AI Systems
20 Move bivex/DPX-Move Aptos & Sui Resource Safety, Linear Types
21 OCaml bivex/DPX-OCaml Algebraic Data Types, Functors, Polymorphism
22 PHP bivex/DPX-Php Modern PHP 8.4, Attributes, Traits, Laravel
23 Prolog bivex/DPX-Prolog ISO Prolog, SWI-Prolog, DCG, CLP(FD/R/Q), CHR, Meta-Interpreters
24 Puppet bivex/DPX-Puppet Puppet DSL, Roles/Profiles, IaC Security, Hiera
25 Python bivex/DPX-Py Metaprogramming, Protocols, Hexagonal DDD
26 Ruby bivex/DPX-Ruby Ruby 3.x, Rails, Metaprogramming, Dry-RB, Security
27 Rust bivex/DPX-Rust Zero-Cost Abstractions, Borrow Checker, Traits
28 Solidity bivex/DPX-Solidity DeFi Security, Reentrancy, EVM Yul/Assembly
29 SQL bivex/DPX-SQL PostgreSQL, MySQL, SQLite, T-SQL, PL/SQL
30 Swift bivex/DPX-Swift Protocol-Oriented Programming, Actors
31 TypeScript bivex/DPX-TypeScript Generics, Conditional Types, Clean Architecture
32 Yul bivex/DPX-Yul EVM Intermediate Representation Optimization
33 Zig bivex/DPX-Zig Comptime, Manual Memory Allocators, C ABI

πŸ“„ License

Distributed under the MIT License. See LICENSE for details.

About

🐹 DPX-Go: Hexagonal Go Pattern Scanner, Concurrency Idioms & Clean Architecture Static Analyzer (Go 1.18 - 1.24+)

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages