Skip to content

About

CLI tool that models neural signaling pathways as a directed graph in MySQL, with BFS/DFS, shortest-path, and cycle detection built from scratch in Java.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

NeuroGraph

A command-line tool that models neural signaling pathways as a directed graph and persists it in MySQL 8. Nodes are biological entities (e.g. Estradiol, Tyrosine Hydroxylase, Dopamine, CREB, BDNF); edges are typed, directed relationships: ACTIVATES, INHIBITS, SYNTHESIZES, MODULATES.

The graph and all traversal algorithms are built from scratch — adjacency list, a hand-built Queue (BFS), and a hand-built Stack / explicit recursion (DFS). The only third-party data dependency is the MySQL JDBC driver.

Built with strict spec-driven development. The source of truth lives in specs/ (spec.md → plan.md → tasks.md) and is published at https://neurograph-seven.vercel.app.

What it does (functional requirements)

  1. Add / remove a node (synced to MySQL and the in-memory graph).
  2. Add / remove a typed, directed edge between two nodes.
  3. Load the full graph from MySQL into memory on startup.
  4. Traverse downstream from a node (BFS and DFS).
  5. Shortest path between two molecules (BFS, unweighted).
  6. Detect feedback loops (cycles).
  7. Rank the most influential nodes by reachable-set size (out-degree tiebreak).

Data model

Normalized MySQL schema (see schema.sql):

  • nodes — id, unique name, optional description, created_at.
  • edge_types — lookup table: ACTIVATES, INHIBITS, SYNTHESIZES, MODULATES.
  • edges — source_id / target_id (FK → nodes, ON DELETE CASCADE), edge_type_id (FK → edge_types), with a UNIQUE(source, target, type) constraint. Cascade + FKs guarantee no orphan edges.

In memory the graph is an adjacency list: Map<String, List<Edge>> where each Edge is (target, type).

Architecture

ui (interactive menu)  ->  service (GraphService)  ->  db (JDBC repositories)
                              |
                              +-> domain (Graph, EdgeType, ds/Queue, ds/Stack, algo/GraphAlgorithms)

The CLI never touches SQL; all persistence is behind GraphService. Every algorithm is pure and unit-tested against in-memory fixtures.

Requirements

  • Java 17+ (built/tested on JDK 25)
  • Maven 3.9+
  • MySQL 8 (for running the CLI; not needed to run the unit tests)

Setup

Option A — Docker Compose (quickest)

docker-compose.yml starts MySQL 8 and auto-loads schema.sql + seed.sql on first run:

docker compose up -d        # MySQL on host port 3307, schema + seed loaded

Then point the app at it:

export NEUROGRAPH_DB_HOST=127.0.0.1 NEUROGRAPH_DB_PORT=3307 \
       NEUROGRAPH_DB_NAME=neurograph NEUROGRAPH_DB_USER=root \
       NEUROGRAPH_DB_PASSWORD=neurograph

Option B — existing MySQL

  1. Create the schema and seed data:
mysql -u root -p < schema.sql
mysql -u root -p neurograph < seed.sql
  1. Configure the connection. Copy the example and edit, or use env vars:
cp db.properties.example db.properties
# or override at runtime:
#   NEUROGRAPH_DB_HOST, NEUROGRAPH_DB_PORT, NEUROGRAPH_DB_NAME,
#   NEUROGRAPH_DB_USER, NEUROGRAPH_DB_PASSWORD

Build & test

mvn test          # runs the unit suite (no database required)
mvn package       # builds target/neurograph.jar (runnable fat JAR)

DB integration tests are tagged @Tag("db") and excluded by default so the suite runs anywhere. To run them against a live MySQL (e.g. the Docker container above, using a dedicated neurograph_test database):

# create an empty test database with the same schema
docker exec -i neurograph-mysql mysql -uroot -pneurograph -e "CREATE DATABASE IF NOT EXISTS neurograph_test"
# (apply schema.sql tables to neurograph_test as well)

NEUROGRAPH_DB_HOST=127.0.0.1 NEUROGRAPH_DB_PORT=3307 \
NEUROGRAPH_DB_NAME=neurograph_test NEUROGRAPH_DB_USER=root \
NEUROGRAPH_DB_PASSWORD=neurograph \
mvn -Ddb.tests= test

(-Ddb.tests= clears the default db tag exclusion so JdbcRepositoryDbTest runs alongside the offline suite.)

The integration tests cover node/edge round-trips, the unique constraints, ON DELETE CASCADE (no orphan edges), and the FR3 startup load against real MySQL. If no database is reachable they are skipped (not failed).

Run

java -jar target/neurograph.jar

You'll get an interactive menu:

=== NeuroGraph ===
 1) List nodes            7) Detect feedback loops
 2) Add node              8) Rank most influential
 3) Remove node           9) Downstream (BFS)
 4) Add edge             10) Downstream (DFS)
 5) Remove edge          11) Reload from database
 6) Shortest path         0) Exit

Example session (with the seed data)

  • List nodes (1) shows each entity and its outgoing typed edges.
  • Shortest path (6) from Estradiol to CREB → Estradiol -> BDNF -> CREB (2 steps).
  • Detect feedback loops (7) reports a cycle such as CREB -> BDNF -> TrkB -> CREB.
  • Rank most influential (8) lists nodes by how many entities they can ultimately influence.
  • Add edge (4): enter source, target, and a type (ACTIVATES / INHIBITS / SYNTHESIZES / MODULATES).

Project layout

schema.sql, seed.sql          # database
src/main/java/com/neurograph/
  App.java                     # composition root + startup load
  domain/                      # Graph, Edge, EdgeType, ds/, algo/
  service/GraphService.java    # memory <-> DB sync
  db/                          # repositories (interfaces) + jdbc/ impls
  ui/Cli.java                  # interactive menu (no SQL)
src/test/java/com/neurograph/  # JUnit 5 tests + in-memory fixtures/fakes
specs/                         # spec.md, plan.md, tasks.md (source of truth)

About

CLI tool that models neural signaling pathways as a directed graph in MySQL, with BFS/DFS, shortest-path, and cycle detection built from scratch in Java.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages