# chinmay-gope/graphite-v2 architecture

> Architecture diagram of the GitHub repository chinmay-gope/graphite-v2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chinmay-gope/graphite-v2
- Repository: https://github.com/chinmay-gope/graphite-v2

## Overview

#### Purpose and entry points
Graphite is a Java graph-algorithms library, not a web application. Consumers create or load mutable directed/undirected, weighted/unweighted adjacency-list graphs, invoke algorithm implementations or service APIs, and receive typed immutable result objects. Main executable/demo entry points are `src/io/graphite/Main.java` and `src/io/graphite/examples/GraphDemo.java`; library-facing APIs are under `src/io/graphite/api/`.

#### Graph domain and construction
The core boundary is the `Graph` abstraction, with concrete directed and undirected implementations and immutable graph support: `src/io/graphite/graph/Graph.java`, `src/io/graphite/graph/DirectedGraph.java`, `src/io/graphite/graph/UndirectedGraph.java`. Creation is centralized through builders/configuration and factories: `src/io/graphite/builder/AbstractGraphBuilder.java`, `src/io/graphite/builder/Graphs.java`, `src/io/graphite/graph/GraphFactory.java`. `Edge` and DSU are shared algorithm models in `src/io/graphite/model/Edge.java` and `src/io/graphite/model/DSU.java`.

#### Algorithm execution layer
Algorithms are organized by graph concern behind category interfaces, separating selection/calling contracts from implementations: `src/io/graphite/algorithm/GraphAlgorithm.java`, `src/io/graphite/algorithm/shortestpath/ShortestPathAlgorithm.java`, `src/io/graphite/algorithm/traversal/TraversalAlgorithm.java`. Key stages include traversal (`BFS`, `DFS`), shortest path (`Dijkstra`, `BellmanFord`, `FloydWarshall`), MST (`Prim`, `Kruskal`), topology/cycles, Euler/bipartite, and connectivity (`Kosaraju`, bridge/AP/biconnected). Algorithms consume graph-model interfaces and return result types rather than formatting output.

#### API, validation, and failure boundaries
Service classes provide higher-level category façades over algorithms: `src/io/graphite/api/GraphService.java`, `src/io/graphite/api/ShortestPathService.java`, `src/io/graphite/api/ConnectivityService.java`. Validation protects preconditions such as graph type, weights, vertex validity, connectivity, and Euler constraints: `src/io/graphite/validation/GraphValidator.java`, `src/io/graphite/validation/EulerValidator.java`. Domain-specific exceptions make invalid input and algorithm constraints explicit, e.g. `src/io/graphite/exception/algorithm/NegativeCycleException.java` and `src/io/graphite/exception/graph/UnsupportedGraphTypeException.java`.

#### Results and analysis
Execution outputs are dedicated immutable-style result objects, preventing algorithms from owning presentation: `src/io/graphite/result/ShortestPathResult.java`, `src/io/graphite/result/MSTResult.java`, `src/io/graphite/result/TraversalResult.java`. A separate analysis API aggregates graph properties/results: `src/io/graphite/api/analysis/GraphAnalysis.java`, `src/io/graphite/api/analysis/GraphAnalysisService.java`.

#### Input, generation, and output adapters
Graphs enter through edge-list readers or programmatic/random/pattern generation: `src/io/graphite/io/reader/EdgeListReader.java`, `src/io/graphite/generator/RandomGraphGenerator.java`, `src/io/graphite/generator/pattern/DAGGenerator.java`. Writers and formatters form the output boundary for edge lists and display/export representations: `src/io/graphite/io/writer/GraphWriterService.java`, `src/io/graphite/print/GraphPrinter.java`, `src/io/graphite/print/formatter/DotFormatter.java`. No external database, network service, or framework infrastructure is evident.

#### Performance workflow
The benchmark subsystem repeatedly generates graphs, runs algorithm callbacks, and records timing/progress through configurable stress runners: `src/io/graphite/benchmark/StressRunner.java`, `src/io/graphite/benchmark/StressConfig.java`, `src/io/graphite/benchmark/StressTestRunner.java`. This is the principal performance-validation runtime alongside normal Java library execution.

Main entry points: [`src/io/graphite/graph/Graph.java`](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/graph/Graph.java) (Graph abstraction), [`src/io/graphite/api/GraphService.java`](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/api/GraphService.java) (Algorithm services), [`src/io/graphite/benchmark/StressRunner.java`](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/benchmark/StressRunner.java) (Stress runner), [`src/io/graphite/io/reader/EdgeListReader.java`](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/io/reader/EdgeListReader.java) (Readers & generators)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Consumers &amp; Workflows"]
  node_demo["Main &amp; demos<br/>Java entry points<br/>[Main.java]"]
  node_input["Readers &amp; generators<br/>graph input"]
end

subgraph group_graph["Graph Domain"]
  node_builder["Builders &amp; factory<br/>graph construction"]
  node_graph{{"Graph abstraction<br/>core interface<br/>[Graph.java]"}}
  node_directed["Directed graph<br/>graph implementation<br/>[DirectedGraph.java]"]
  node_undirected["Undirected graph<br/>graph implementation"]
  node_models["Edge &amp; DSU<br/>shared models<br/>[Edge.java]"]
end

subgraph group_execution["Algorithms &amp; APIs"]
  node_services["Algorithm services<br/>API façades<br/>[GraphService.java]"]
  node_algorithm_contracts{{"Algorithm contracts<br/>algorithm interfaces"}}
  node_algorithm_implementations["Algorithm implementations<br/>algorithm suite"]
  node_validation["Validators<br/>preconditions"]
  node_exceptions["Domain exceptions<br/>failure boundary"]
  node_results["Typed results<br/>immutable outputs"]
  node_analysis["Graph analysis API<br/>analysis façade<br/>[GraphAnalysis.java]"]
end

subgraph group_adapters["I/O &amp; Presentation"]
  node_writers["Writers<br/>output adapter"]
  node_formatters["Printers &amp; formatters<br/>presentation adapter<br/>[GraphPrinter.java]"]
end

subgraph group_performance["Performance"]
  node_stress_config["Stress configuration<br/>benchmark config<br/>[StressConfig.java]"]
  node_stress_runner["Stress runner<br/>benchmark runtime<br/>[StressRunner.java]"]
end

node_demo -->|"loads or generates"| node_input
node_demo -->|"invokes"| node_services
node_input -->|"constructs through"| node_builder
node_builder -->|"creates"| node_graph
node_directed -->|"implements"| node_graph
node_undirected -->|"implements"| node_graph
node_graph -->|"uses"| node_models
node_services -->|"enforces"| node_validation
node_services -->|"selects via"| node_algorithm_contracts
node_algorithm_implementations -->|"implements"| node_algorithm_contracts
node_algorithm_implementations -->|"consumes"| node_graph
node_algorithm_implementations -->|"uses"| node_models
node_algorithm_implementations -->|"returns"| node_results
node_validation -->|"raises"| node_exceptions
node_algorithm_implementations -->|"signals constraints"| node_exceptions
node_analysis -->|"aggregates"| node_services
node_analysis -->|"consumes"| node_results
node_writers -->|"exports"| node_graph
node_formatters -->|"renders"| node_graph
node_stress_config -->|"configures"| node_stress_runner
node_stress_runner -->|"generates graphs"| node_input
node_stress_runner -->|"runs callbacks"| node_services

click node_demo "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/Main.java"
click node_input "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/io/reader/EdgeListReader.java"
click node_builder "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/builder/AbstractGraphBuilder.java"
click node_graph "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/graph/Graph.java"
click node_directed "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/graph/DirectedGraph.java"
click node_undirected "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/graph/UndirectedGraph.java"
click node_models "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/model/Edge.java"
click node_services "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/api/GraphService.java"
click node_algorithm_contracts "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/algorithm/GraphAlgorithm.java"
click node_validation "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/validation/GraphValidator.java"
click node_exceptions "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/exception/algorithm/NegativeCycleException.java"
click node_results "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/result/ShortestPathResult.java"
click node_analysis "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/api/analysis/GraphAnalysis.java"
click node_writers "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/io/writer/GraphWriterService.java"
click node_formatters "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/print/GraphPrinter.java"
click node_stress_config "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/benchmark/StressConfig.java"
click node_stress_runner "https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/benchmark/StressRunner.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_demo,node_input toneBlue
class node_builder,node_graph,node_directed,node_undirected,node_models toneAmber
class node_services,node_algorithm_contracts,node_algorithm_implementations,node_validation,node_exceptions,node_results,node_analysis toneMint
class node_writers,node_formatters toneRose
class node_stress_config,node_stress_runner toneIndigo
```

## Components

### Consumers & Workflows

- [Main & demos](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/Main.java): Java entry points · Library usage entry points. · `src/io/graphite/Main.java`
- [Readers & generators](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/io/reader/EdgeListReader.java): graph input · Loads edge lists or creates random and pattern graphs. · `src/io/graphite/io/reader/EdgeListReader.java`

### Graph Domain

- [Builders & factory](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/builder/AbstractGraphBuilder.java): graph construction · Centralizes graph creation and configuration. · `src/io/graphite/builder/AbstractGraphBuilder.java`
- [Graph abstraction](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/graph/Graph.java): core interface · Mutable adjacency-list graph contract. · `src/io/graphite/graph/Graph.java`
- [Directed graph](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/graph/DirectedGraph.java): graph implementation · `src/io/graphite/graph/DirectedGraph.java`
- [Undirected graph](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/graph/UndirectedGraph.java): graph implementation · `src/io/graphite/graph/UndirectedGraph.java`
- [Edge & DSU](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/model/Edge.java): shared models · Shared edge representation and disjoint-set structure. · `src/io/graphite/model/Edge.java`

### Algorithms & APIs

- [Algorithm services](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/api/GraphService.java): API façades · Category-level library APIs select and invoke algorithms. · `src/io/graphite/api/GraphService.java`
- [Algorithm contracts](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/algorithm/GraphAlgorithm.java): algorithm interfaces · Common, shortest-path, and traversal calling contracts. · `src/io/graphite/algorithm/GraphAlgorithm.java`
- **Algorithm implementations**: algorithm suite · Traversal, paths, MST, topology, Euler, and connectivity algorithms.
- [Validators](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/validation/GraphValidator.java): preconditions · Checks graph capabilities and algorithm constraints. · `src/io/graphite/validation/GraphValidator.java`
- [Domain exceptions](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/exception/algorithm/NegativeCycleException.java): failure boundary · Reports invalid graphs and algorithm-specific failures. · `src/io/graphite/exception/algorithm/NegativeCycleException.java`
- [Typed results](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/result/ShortestPathResult.java): immutable outputs · Shortest-path, MST, and traversal outputs. · `src/io/graphite/result/ShortestPathResult.java`
- [Graph analysis API](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/api/analysis/GraphAnalysis.java): analysis façade · Aggregates graph properties and algorithm results. · `src/io/graphite/api/analysis/GraphAnalysis.java`

### I/O & Presentation

- [Writers](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/io/writer/GraphWriterService.java): output adapter · Writes graph representations and edge lists. · `src/io/graphite/io/writer/GraphWriterService.java`
- [Printers & formatters](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/print/GraphPrinter.java): presentation adapter · Displays graphs and produces DOT output. · `src/io/graphite/print/GraphPrinter.java`

### Performance

- [Stress configuration](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/benchmark/StressConfig.java): benchmark config · Configures repeated performance runs. · `src/io/graphite/benchmark/StressConfig.java`
- [Stress runner](https://github.com/chinmay-gope/graphite-v2/blob/master/src/io/graphite/benchmark/StressRunner.java): benchmark runtime · Generates graphs, invokes callbacks, and records timing/progress. · `src/io/graphite/benchmark/StressRunner.java`

## Connections

- Main & demos → Readers & generators: loads or generates
- Main & demos → Algorithm services: invokes
- Readers & generators → Builders & factory: constructs through
- Builders & factory → Graph abstraction: creates
- Directed graph → Graph abstraction: implements
- Undirected graph → Graph abstraction: implements
- Graph abstraction → Edge & DSU: uses
- Algorithm services → Validators: enforces
- Algorithm services → Algorithm contracts: selects via
- Algorithm implementations → Algorithm contracts: implements
- Algorithm implementations → Graph abstraction: consumes
- Algorithm implementations → Edge & DSU: uses
- Algorithm implementations → Typed results: returns
- Validators → Domain exceptions: raises
- Algorithm implementations → Domain exceptions: signals constraints
- Graph analysis API → Algorithm services: aggregates
- Graph analysis API → Typed results: consumes
- Writers → Graph abstraction: exports
- Printers & formatters → Graph abstraction: renders
- Stress configuration → Stress runner: configures
- Stress runner → Readers & generators: generates graphs
- Stress runner → Algorithm services: runs callbacks
