# Visualizador Instanciados

Docker Compose stack for exploring large RDF/OWL graphs stored in AnzoGraph.

## What Runs Here

- `anzograph`: SPARQL store
- `backend`: Go API that queries AnzoGraph and serves cached graph snapshots
- `frontend`: React/Vite app with a WebGL left graph and a right-side `cosmos.gl` selection graph
- `owl_imports_combiner`: one-shot Python service that can merge `owl:imports`
- `radial_sugiyama`: Rust hierarchy layout pipeline used in two ways:
  - standalone SVG generator through the `radial` Compose profile
  - optional hierarchy layout engine for the Go backend

## Current Flow

- The backend always builds graph snapshots from SPARQL queries against AnzoGraph.
- `graph_query_id=default` and `graph_query_id=types` use the Go layout path.
- `graph_query_id=hierarchy` can use either:
  - the Go layout path
  - the Rust radial Sugiyama path when `HIERARCHY_LAYOUT_ENGINE=rust`
- When the Rust hierarchy path is enabled, the backend sends the hierarchy graph to Rust over JSON, Rust lays it out, returns node positions + routed edge segments, and also rewrites:

```text
radial_sugiyama/out/layout.svg
```

That SVG is a debug artifact for the exact Rust layout run used by the backend.

## Quick Start

1. Put your TTL files under `./data/`.
2. Copy or edit `.env` as needed.
3. Start the stack:

```bash
docker compose up --build
```

Open:

- Frontend: `http://localhost:5173`
- Backend health: `http://localhost:8000/api/health`

Stop:

```bash
docker compose down
```

## Rust Hierarchy Layout

To use Rust for the `hierarchy` graph mode, set this in the repo root `.env`:

```env
HIERARCHY_LAYOUT_ENGINE=rust
```

The backend also reads `radial_sugiyama/.env` for the Rust layout settings such as:

- `RADIAL_ROOT_CLASS_IRI`
- `RADIAL_OUTPUT_DIR`
- `RADIAL_OUTPUT_FILE`
- `RADIAL_RING_DISTRIBUTION`

The debug SVG for backend-driven hierarchy requests is written to:

```text
radial_sugiyama/out/layout.svg
```

You can still run the standalone Rust SVG pipeline directly with:

```bash
docker compose --profile radial up --build radial_sugiyama
```

## Main API

- `GET /api/health`
- `GET /api/stats`
- `GET /api/graph`
- `GET /api/graph_queries`
- `GET /api/selection_queries`
- `POST /api/selection_query`
- `POST /api/selection_triples`
- `POST /api/sparql`

## Repo Layout

- `backend_go/` Go API and SPARQL snapshot logic
- `frontend/` React/Vite UI
- `radial_sugiyama/` Rust hierarchy layout and SVG export
- `python_services/owl_imports_combiner/` import-flattening helper
- `data/` local shared data mounted into containers
- `docker-compose.yml` service wiring
