A multi-tenant, enterprise-grade AI Agent Workflow Orchestration Engine built with Nhost (PostgreSQL, Hasura GraphQL Engine, Nhost Auth, Serverless Functions), Groq LLM API, and Next.js.
Designed for chaining autonomous AI agent steps, enforcing strict multi-tenant data boundaries, and applying a dual-layer role-based permission system with human-in-the-loop approval gates.
Link : https://drive.google.com/file/d/16WDUc1yO2vSmmU40a-hQEfkFtZA8RqCc/view?usp=sharing
| Layer | Technology | Description |
|---|---|---|
| Frontend Framework | Next.js 16 (App Router, Turbopack) | Responsive, dark-themed UI built with React 19 and Tailwind CSS. |
| GraphQL & State Management | Apollo Client | Managed GraphQL queries, mutations, and real-time execution polling. |
| Backend & Database | Nhost + Hasura GraphQL Engine | Managed PostgreSQL database, GraphQL API generator, and RBAC matrix. |
| Serverless Functions | Node.js (TypeScript) | Custom Hasura Actions (/triggerWorkflowRun, /approveStep) & Event Triggers (/executeStep). |
| LLM Inference | Groq API (llama3-8b-8192) |
Live, high-speed LLM execution for AI agent step nodes. |
| Deployment | Netlify + Nhost Cloud | CD deployment with automated migrations and metadata application. |
The platform strictly enforces two separate layers of security:
┌──────────────────────────────────────────────┐
│ GraphQL Request │
└──────────────────────┬───────────────────────┘
│
▼
┌──────────────────────────────────────────────┐
│ Layer 1: Multi-Tenant Isolation │
│ Checks: user_id = X-Hasura-User-Id │
│ in tenant's org_members table │
└──────────────────────┬───────────────────────┘
│
▼
┌──────────────────────────────────────────────┐
│ Layer 2: Step-Level Permission Gating │
│ - DB Level: _nin [db_write, notify] │
│ - Action Level: Role verification for │
│ approval_gate steps │
└──────────────────────────────────────────────┘
- Prevents cross-tenant data leakage. Every Hasura query, insert, update, and delete is scoped to the caller's organization via an
org_membersjoin filter. - Cross-Tenant Role Lock: To prevent a user who is an
ownerin Tenant A from elevating privileges in Tenant B where they are aneditor, permissions explicitly evaluate the caller's role within the target organization'sorg_membersrecord.
- Database Level Enforcement (
_ninConstraints): Hasura metadata constraints restricteditorroles from creating or updating high-privilege steps (db_write,notify) or triggers (webhook). Onlyownerroles can access these resources. - Action Handler Level Enforcement: Clearing an
approval_gatestep mid-execution is handled via the/approveStepserverless function. It verifies the approver's role in backend logic before resuming execution. - Quota Safeguards:
usage_quotaonorganizationsis read-only for tenant owners, preventing unauthorized quota manipulation.
The PostgreSQL database comprises 8 core entities:
organizations: Tenant container withusage_quotaandcalls_used.org_members: Mapsuser_idtoorg_idwith roles (owner,editor,viewer).workflows: Belongs to an organization.workflow_steps: Ordered execution steps (llm_call,http_request,db_write,notify,conditional_branch,approval_gate).workflow_triggers: Trigger configurations (manual,webhook,scheduled,database_event).workflow_runs: Tracks execution run instances and overall status (pending,running,completed,paused,failed).step_runs: Detailed per-step execution logs, inputs, outputs, errors, attempt counts, and approval audit metadata (approved_by,approved_at).org_usage_stats: A PostgreSQL view calculating remaining quota and execution metrics per tenant.
- Triggering a Run: The
/triggerWorkflowRunHasura Action validates tenant membership, verifiesremaining_quota > 0, creates aworkflow_run, and initializesstep_runs. - Event-Driven LLM Execution: Inserting a step run fires a Hasura Event Trigger pointing to
/executeStep. Forllm_callsteps, the function calls Groq's API and updates the output. - Approval Gate Pause: When an
approval_gatestep executes, the run pauses inrunningstatus. - Approval & Resume: An authorized user triggers the
/approveStepAction. The handler verifies their role inorg_members, records audit timestamps, marks the stepcompleted, and signals execution to resume.
- Node.js >= 18.x
- npm / yarn / pnpm
Create a .env.local file in the root directory:
NEXT_PUBLIC_NHOST_SUBDOMAIN=s******************p
NEXT_PUBLIC_NHOST_REGION=ap-south-1
NEXT_PUBLIC_NHOST_GRAPHQL_URL=https://s*****************p.hasura.ap-south-1.nhost.run/v1/graphqlNote: For backend serverless functions running on Nhost Cloud, set
GROQ_API_KEYunder Nhost Dashboard Settings -> Environment Variables.
# Install dependencies with legacy peer deps option for React 19 compatibility
npm install --legacy-peer-deps
# Start Next.js development server
npm run devVisit http://localhost:3000 to access the application.
For a comprehensive architectural breakdown on schema design reasoning, Hasura metadata configurations, and approval gate lifecycles, read ARCHITECTURE.md.
