🌐 Language: English | 日本語
Created: 2026-04-14
Updated: 2026-06-03
Current version: v0.9
Shingan adopts the Onion Architecture. Dependencies always flow from outer layers to inner layers — reverse dependencies are forbidden.
┌──────────────────────────────────────────────────────────────────┐
│ cmd/ │
│ shingan/ api/ runner/ shingan-web/ shingan-lsp/ shingan-mcp/ │
│ shingan-gen/ — cobra commands, Factory calls, DI wiring │
│ ┌────────────────────────────────────────────────────────────┐ │
│ │ infrastructure/ │ │
│ │ parser/ — 12 framework parsers (JSON / ADK-Go / │ │
│ │ LangGraph / CrewAI / n8n / … ) │ │
│ │ reporter/ — Markdown / JSON / SARIF reporter impls │ │
│ │ factory/ — AnalyzerFactory / ParserFactory impls │ │
│ │ api/ baseline/ cache/ — service, baseline, cache impls │ │
│ │ ┌──────────────────────────────────────────────────────┐ │ │
│ │ │ application/ │ │ │
│ │ │ orchestrator.go — AnalysisOrchestrator │ │ │
│ │ │ parser.go / reporter.go — consumer-side interfaces│ │ │
│ │ │ policy.go / rule_catalog.go — .shingan.yaml + catalog │
│ │ ┌────────────────────────────────────────────────┐ │ │ │
│ │ │ domain/ │ │ │ │
│ │ │ graph.go — WorkflowGraph / Node / Edge │ │ │ │
│ │ │ rule.go — AnalysisRule + tier ifaces │ │ │ │
│ │ │ finding.go — Finding / Severity │ │ │ │
│ │ │ rules/ — 22 built-in rule impls │ │ │ │
│ │ │ (registry.go AllBuiltins()) │ │ │ │
│ │ │ testutil/ — builder.go (test graph builder) │ │ │ │
│ │ └────────────────────────────────────────────────┘ │ │ │
│ │ └──────────────────────────────────────────────────────┘ │ │
│ └────────────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────┘
The
domainpackage itself holds the core types (graph.go,rule.go,finding.go,visitor.go,baseline.go); the rule implementations live in thedomain/rulessub-package (there is nodomain/analyzerpackage).
| Layer | Allowed imports | Forbidden imports |
|---|---|---|
| domain/ | standard library only | application/, infrastructure/, cmd/ |
| application/ | domain/ (+ two documented exceptions — see §7) | infrastructure/, cmd/ |
| infrastructure/ | application/, domain/ | cmd/ |
| cmd/ | infrastructure/, application/, domain/ | — |
The "application → domain only" row is the ideal. The code has two deliberate, bounded exceptions (
gopkg.in/yaml.v3and thepluginpackage); the real dependency graph and its rationale are documented in §7 and ADR-017.
WorkflowGraph— graph representation of nodes and edges (graph.go)Node— node type (LLM / Tool / Task / Loop / Branch, etc.) and metadataEdge— directed edge with conditional labelAnalysisRule— legacy analysis rule interface (Analyze(graph) []Finding); new rules implement theLocalRule/PathRule/GlobalRuletier interfaces (ADR-006/007) so the single-walkGraphWalkercan dispatch themFinding— detection result (RuleName, Severity, Message, NodeID, Confidence)Severity— enum of Info / Warning / Criticalrules/— 22 built-in rule implementations, each self-registered via its owninit()into the registry;rules.AllBuiltins()returns the full set
The domain layer pulls in zero external libraries (standard library only). This means unit tests can be written without mocks.
WorkflowParserinterface —Parse(input) (*WorkflowGraph, error)ReportFormatterinterface —Format(findings) stringAnalysisOrchestrator— runs rules concurrently with goroutines and aggregates results
Interfaces are defined on the consumer side (application/), not the implementation side (infrastructure/). This is the principle of Dependency Inversion.
parser/— 12 framework parsers mapping each framework onto the sharedWorkflowGraphIR:json(native schema),adkgo(Go AST viago/parser),samurai,langgraph,n8n,crewai, plus the six added in v0.9 (langgraph-js,mastra,pydantic-graph,llamaindex,autogen,openai-agents). The Python/TS-backed parsers run their shim in a long-lived subprocess over JSON-RPC; n8n is pure Go.reporter/markdown/reporter/json/reporter/sarif— output formatsfactory/— concrete implementations of AnalyzerFactory / ParserFactory / ReporterFactoryapi/,baseline/,cache/— HTTP service,--save-baselinesupport, and the parse/analysis cache
- cobra command definitions (
analyzesubcommand) - Calls Factories to inject dependencies
- Determines the exit code (highest Severity → 0/1/2)
The factory no longer holds a hardcoded rule map. It delegates to
rules.AllBuiltins(), which returns every rule that self-registered via its
own init() block — so adding a rule never touches the factory (ADR-010,
internal-first Plugin SDK).
AnalyzerFactory
├── Create(ruleType string) (domain.AnalysisRule, error)
│ └── walks rules.AllBuiltins(), matches by Name()
└── CreateAll() []domain.AnalysisRule
└── rules.AllBuiltins() // all 22 built-ins
To add a new rule, drop a file under domain/rules/ whose init() registers
it — the factory and CLI pick it up automatically.
ParserFactory
└── Build(format string) application.WorkflowParser
├── "json" "adk-go" "samurai" "langgraph" "n8n" "crewai"
└── "langgraph-js" "pydantic-graph" "llamaindex" "autogen" "mastra"
To add a new format, add an implementation under infrastructure/parser/ and register it in ParserFactory.
ReporterFactory
└── Build(output string) application.ReportFormatter
├── "markdown" → MarkdownReporter{}
├── "json" → JSONReporter{}
└── "sarif" → SARIFReporter{}
AnalysisOrchestrator.Run() executes all analysis rules in parallel using goroutines.
Run(graph *WorkflowGraph, rules []AnalysisRule) []Finding
│
├── goroutine: rules[0].Analyze(graph) → ch
├── goroutine: rules[1].Analyze(graph) → ch
├── … one goroutine per rule (all 22 built-ins by default) …
└── goroutine: rules[n-1].Analyze(graph) → ch
↓
wait for completion via sync.WaitGroup
↓
aggregate and return []Finding
Single-node / single-path rules implemented against the tier interfaces (
LocalRule/PathRule/GlobalRule) are additionally dispatched by a single sharedGraphWalkerpass (ADR-006/007) rather than each re-walking the graph; theAnalysisRule.Analyzeshape above is the legacy/compat view.
Design assumptions:
graphis read-only (Analyze does not mutate the graph)- Each goroutine writes Findings to its own independent slice → results are aggregated via channel
- No data races (
go test -racestays green)
- Create
<rule_name>.gounderdomain/rules/implementing a tier interface (LocalRule/PathRule/GlobalRule) — or the legacyAnalysisRule— and self-register it in aninit()block - Create
domain/rules/<rule_name>_test.go(build graphs with testutil/builder.go) - No factory edit needed —
rules.AllBuiltins()picks it up automatically - Confirm that
go test ./... && go vet ./...is green
- Create
infrastructure/parser/<format>/parser.goimplementingapplication.WorkflowParser - Add a branch in
infrastructure/factory/parser_factory.go - Add sample files under
testdata/<format>/and write tests
- Create
infrastructure/reporter/<format>/reporter.goimplementingapplication.ReportFormatter - Add a branch in
infrastructure/factory/reporter_factory.go
For details on the design decisions, see shingan-adr.md.
| ADR | Title |
|---|---|
| ADR-001 | Product selection — why "static analysis of AI agent workflows" |
| ADR-002 | Selection of target frameworks |
| ADR-003 | Architecture design (Onion Architecture + Factory Pattern) |
| ADR-004 | Infrastructure design (parsers, reporters, CLI) |
| ADR-005 | Implementation scope and schedule |
| Appendix A | Glossary |
| Appendix B | SamuraiAI ↔ ADK-Go node mapping |
| Appendix C | Detailed analysis rule specifications |
(The table above lists the founding ADRs; later decisions — ADR-006 … ADR-017 —
live in shingan-adr.md directly.)
The "application depends only on domain" rule in §1 is the ideal. The code has two deliberate, bounded exceptions. Rather than claim a purity the code doesn't have, the real graph is recorded here and in ADR-017:
application/policy.go → gopkg.in/yaml.v3 (.shingan.yaml parsing)
application/rule_catalog.go → plugin (rule-catalog rendering)
plugin/plugin.go → domain, domain/rules, version, golang.org/x/mod/semver
application → gopkg.in/yaml.v3—.shingan.yamlparsing is policy-domain logic; thePolicystruct lives alongsideApplyPolicy/VerifyRequiredPlugins, and onlyLoadPolicytouches YAML (one caller incli/analyze.go). Splitting it into infrastructure buys nothing.application → plugin—rule_catalogmust read the live plugin registry to render all rules (built-in + plugin-registered).pluginis the public SDK package, so inverting this edge is an SDK-contract change.
A faithful refactor would ripple into the public plugin SDK surface, so it was
deliberately not done (see ADR-017 for the trigger conditions that would
justify revisiting it).