Amán Rules Engine

Full-stack rules authoring & eval platform: React + Next.js UI with AI natural-language to AST conversions, plus a high-performance Go evaluator.

Next.js React TypeScript Go PostgreSQL pgx chi sqlc Gemini (LLM)

Overview

Text-to-AST rules engine where users type intent, click Generate, external LLM (Gemini) returns AST, UI renders JSON + interactive editor, and engine evaluates with trace output.

Architecture

Next.js / React UI -> LLM API (Gemini) for NL-to-AST -> AST render + UI test data -> Go rule evaluator (+ trace) -> result output. Backend persisted in Postgres JSONB, evaluator in-memory per request.

Next.js UI Gemini LLM API AST Generator Go Evaluator PostgreSQL JSONB

Key Technical Decisions

Go for performance and strong typing

PostgreSQL JSONB for flexible persisted rule models

chi for minimal routing and extensible middleware

WebLLM (Gemini) to avoid hosting own model and leverage latest LLM capabilities

Challenges

JSON serialization of pgx JSONB []byte in responses

Type-safety with dynamic rule payloads

Operator flexibility for eq/gte/string/collection

Nested field resolution via dot notation parser

Trade-offs

Parser creates new instance per request (MVP allocation overhead)

Regex compiled on each evaluation instead of cache (deferred optimization)

No DB-level rule caching yet (could add Redis later)

Single-node evaluator vs distributed (chosen for initial release)

No auth on rules API yet; design MVP first, add JWT later

Resources