A high-performance natural language query interface designed to visualize and traverse relational Order-to-Cash data as an interactive graph. The platform is engineered as a secure, fast, full-stack monorepo. Complex financial flowsโCustomer โ Order โ Delivery โ Invoice โ Paymentโare projected natively from PostgreSQL into an interactive 2D graph topology, without the infrastructure overhead of a dedicated Graph DB.
๐ฉโ๐ผ Analytics / User Console
- Natural Language Search: Query intricate relational data natively in English (e.g., "Trace complete order flow for Order X").
- Live Flow Tracing: Translates results into visual paths, dynamically highlighting all relational nodes and traversed edges.
- Node Introspection: Click any node (e.g., Customer, Payment) to view deep metadata properties instantly.
- Dynamic Exploration: Interact with a rich
react-force-graph-2dphysics-engine layout for intuitive data relationship discovery.
โ๏ธ System Architecture & LLM Mechanics
- Zero-Shot Prompting Pipeline: The system statically injects your relational Prisma schema into an LLM (Gemini or Groq) context layer to synthesize valid, deterministic PostgreSQL logic.
- Dual-Layered Hallucination Prevention: The first pass strictly extracts SQL logic (
temperature: 0.1); the second pass acts as an analyst converting JSON tuples back into conversational responses (temperature: 0.3). - Dynamic Projection Layer: Bypasses sync issues between SQL and Graph databases (like Neo4j) by calculating graph edges dynamically at the Express request layer.
- Strict Guardrails: Blocks malicious inputs (
UPDATE,DROP) at the middleware, and mandates domain-keyword bounds for processing.
| Layer | Technology |
|---|---|
| Frontend | React, Next.js, TypeScript, TailwindCSS, react-force-graph-2d |
| Backend | Node.js, Express, TypeScript |
| Database | PostgreSQL |
| Data Layer | Prisma ORM |
| Generative AI | Google Gemini API, Groq SDK |
| Validation | Zod (Data payloads) |
| Deployment | Vercel (Client) & Render (Backend Service) |
graph-query-system/
โ
โโโ frontend/
โ โโโ app/ # Next.js App Router specific pages
โ โโโ components/ # React UI components (Graph rendering, chat overlays)
โ โโโ lib/
โ โ โโโ api.ts # API Service logic handling query execution & graph parsing
โ โโโ package.json
โ โโโ .env
โ
โโโ backend/
โ โโโ src/
โ โ โโโ controllers/ # HTTP Request management
โ โ โโโ services/
โ โ โ โโโ ai/ # Gemini & Groq LLM integration providers
โ โ โ โโโ guardrail.service.ts # Traffic sanitization, domain keyword verity
โ โ โ โโโ graph.service.ts # Dynamic dynamic projection of nodes/edges
โ โ โ โโโ query.service.ts # Core LLM prompt pipeline orchestrator
โ โ โโโ etl/ # Database seed scripts and CSV processors
โ โ โโโ index.ts # Express App initialization and Route mounts
โ โ โโโ prisma/ # DB configuration logic
โ โโโ prisma/
โ โ โโโ schema.prisma # Central relational schema definition
โ โโโ package.json
โ โโโ .env
โ
โโโ README.md
Analyst / User Client (Next.js โ Vercel)
โ
REST (HTTP/JSON)
โผ
Express.js Backend Service (Node.js โ Render)
โ
โโโโโโโโโโดโโโโโโโโโโ
โ โ
Controllers Middleware /
โ Guardrail Service (Sanitization)
โโโโโโโโโโฌโโโโโโโโโโ
โ
Services Layer (Core Business Logic)
โ
โโโโโโโโโโดโโโโโโโโโโโโโโโโโโ
โ โ
Prisma ORM LLM Routing Interfaces (Gemini / Groq)
โ
PostgreSQL Database
The backend restricts data logic natively via Service patterns. QueryService handles the SQL/prompt synchronization, GraphService maps tabular tuples to arrays for the browser, and GuardrailService prevents logic poisoning.
- Graph Explorer (
react-force-graph-2d): Visualizes JSON representations containing independent arrays fornodesandedges. Manages click-to-expand semantics to provide metadata previews. - Chat Panel: Collects human intention statements as raw strings, feeding deeply into the
/api/queryREST layer, tracking user context updates (such as highlighted arrays spanning cross query).
The api.ts utility normalizes remote actions against environmental parameters (process.env.VITE_BACKEND_URL or NEXT_PUBLIC_BACKEND_URL).
fetchGraphData(): Retrieves full universal nodes and active ties.executeQuery(question): Triggers the AI pipeline, dynamically un-wrapping backend objects yielding highlights and parsed natural language.
Maps directly towards resolving client queries synchronously. Restricts un-safe JSON payload manipulation via robust TS interfaces.
| File | Responsibility |
|---|---|
graph.controller.ts |
Feeds entire relational projections matching nodes and edges format for visual plotting. |
query.controller.ts |
Evaluates question complexity directly delegating processing towards QueryService. |
All complex logic and Prisma abstractions are managed securely downstream.
| Service | Responsibility |
|---|---|
graph.service.ts |
Loops DB Entities formatting standard ids, labels, and constructing edge linkage sources implicitly based on relational keys mapping. |
query.service.ts |
Coordinates the LLM execution pipeline; injects exact schema; runs generated SQL asynchronously using raw abstractions. |
guardrail.service.ts |
Evaluates inputs prior to triggering the LLM, and enforces strict output containment against un-safe mutations. |
gemini.provider.ts |
Instantiates models dynamically, managing exact hardware token parameter limits (temperature, instructions logic). |
Using customized error abstraction guarantees zero leak of database architecture to external API consumers. The system strictly isolates errors responding neatly with:
{
"error": "Generated SQL contains prohibited keyword: UPDATE"
}model Customer {
id String @id @default(uuid())
name String
email String @unique
phone String?
addressId String
address Address @relation(fields: [addressId], references: [id])
orders Order[]
createdAt DateTime @default(now())
}
model Order {
id String @id @default(uuid())
customerId String
customer Customer @relation(fields: [customerId], references: [id])
status OrderStatus @default(CREATED)
totalAmount Float
orderItems OrderItem[]
deliveries Delivery[]
}
model Delivery {
id String @id @default(uuid())
orderId String
addressId String
order Order @relation(fields: [orderId], references: [id])
address Address @relation(fields: [addressId], references: [id])
invoice Invoice?
}
model Invoice {
id String @id @default(uuid())
deliveryId String @unique
amount Float
delivery Delivery @relation(fields: [deliveryId], references: [id])
payment Payment?
}
model Payment {
id String @id @default(uuid())
invoiceId String @unique
amount Float
status PaymentStatus
invoice Invoice @relation(fields: [invoiceId], references: [id])
}(All models uniquely assigned to @@schema("graph_query") via multiSchema flag)
Execution Flow (Chat โ Highlights)
- User Request: User sends string "Trace my Order #1231"
- Validating Context:
GuardrailServicechecks ifOrderis within domain tracking criteria before execution to prevent external requests. - Synthesis Translation:
QueryServicesends strictly defined relational database schema parameters asynchronously toGeminiProvider. - Validation Isolation: LLM generates strict synthetic
SELECTstatement.GuardrailServiceenforces no logic termination overlaps or syntax mutations present. - Prisma Fetching: Prisma safely invokes statement retrieving raw structured parameters matching exactly requested relational objects.
- Data Translation Request: Raw tuples returned mapped dynamically towards secondary Prompt Pipeline translating it backwards efficiently alongside relevant relational trace highlights pointing backend coordinates logically!
- Frontend Binding: Next.js parses responses dynamically mapping graph array state logically mutating visualizations.
git clone https://github.com/xaltyPasta/graph-query-system.git
cd graph-query-system# Backend
cd backend && npm install
# Frontend
cd ../frontend && npm installbackend/.env:
DATABASE_URL="postgresql://user:password@localhost:5432/db_name"
GEMINI_API_KEY="your_api_key"
PORT=5000
CORS_ORIGIN="http://localhost:3000"frontend/.env:
# Next.js may require NEXT_PUBLIC_BACKEND_URL or properly evaluated logic within Vite depending on configuration abstractions mapping.
VITE_BACKEND_URL="http://localhost:5000"Ensure your local PostgreSQL connection holds valid constraints natively pointing inside your configuration:
cd backend
npx prisma generate
npx prisma db push
# or npx prisma migrate dev based on initialization state.# Backend (tab 1)
cd backend && npm run dev
# Frontend (tab 2)
cd frontend && npm run dev| Layer | Platform | Environment Variables Required |
|---|---|---|
| Frontend | Vercel | VITE_BACKEND_URL, NEXT_PUBLIC_BACKEND_URL |
| Backend | Render | DATABASE_URL, PORT, CORS_ORIGIN, GEMINI_API_KEY, GROQ_API_KEY |
| Database | Supabase/AWS | Provides the DATABASE_URL routing logic explicitly. |
- Neo4j Storage Switch: Eventually cache relational state implicitly using proper analytical stores natively rather than projections per-call basis improving visual density response rate safely.
- RAG-based Document Understanding: Store PDFs alongside invoices natively mapped logically within isolated graphs increasing LLM interpretation tracking precision dynamically!
- Historical Snapshots: Render graph visualizations based on exact timestamp states dynamically supporting auditing procedures locally tracking history logs interactively!



