Skip to content

shrihari7396/SentientGate

Repository files navigation

πŸ›‘οΈ SentientGate

AI-Driven Distributed Security Mesh for Microservices

Java Spring Boot Kafka Redis Docker License

SentientGate is an intelligent, high-concurrency security infrastructure that protects microservice ecosystems from sophisticated bot attacks, injection attempts, and behavioral anomalies β€” using real-time AI-driven threat analysis powered by a local LLM (Ollama).

Unlike static firewalls, SentientGate's Sentient MCP (Master Control Program) analyzes user behavioral history using a layered Strategy pattern β€” from rule-based pattern matching to AI anomaly detection β€” all without any external API dependency.

🌐 Live Dashboard: https://sentient-gate.vercel.app/

Live Demo Β· Architecture Β· Services Β· Tech Stack Β· Quick Start Β· Docker Setup Β· Folder Structure


πŸ—οΈ System Architecture

High-Level Architecture

SentientGate Architecture

The architecture follows a distributed, event-driven microservice model where detection, analysis, and enforcement are completely decoupled for maximum scalability and resilience.

Request Lifecycle (Sequence Flow)

SentientGate Sequence

A suspicious request flows through the following pipeline:

Incoming Request
      β”‚
      β–Ό
 ApiGateway ──► Kafka Event Bus ──► MCPService
      β”‚                                  β”‚
      β”‚                            β”Œβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
      β”‚                        LoggingService   AIService
      β”‚                        (via gRPC)    (Ollama LLM)
      β”‚                                  β”‚
      └──────── Redis Blacklist β—„β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               (TTL Enforcement)

πŸ”¬ Microservices

πŸ”Ή ApiGateway

ApiGateway/ Β· Spring Boot Β· Maven Β· Port 8079

The entry point of the entire system.

  • Visitor Identity Signing β€” generates and validates fingerprinted visitor tokens
  • Sub-millisecond Blacklist Enforcement β€” checks Reactive Redis for blocked IPs/tokens instantly
  • Threat Event Publishing β€” publishes SecurityAlertEvent to Kafka for async analysis
  • Reactive Architecture β€” built on Spring WebFlux for non-blocking, high-throughput processing
  • Global Filters β€” authentication, request validation, rate limiting applied as gateway filters

πŸ”Ή MCPService (Sentient Engine)

MCPService/ Β· Spring Boot Β· Gradle Β· The "Brain"

The core decision-making engine of SentientGate.

  • Consumes SecurityAlertEvent from Kafka
  • Fetches 10-minute behavioral history from LoggingService via gRPC
  • Applies a layered, Strategy-based threat analysis pipeline:
Strategy Type Detects
PatternMatchStrategy Rule-Based SQL Injection, XSS, Path Traversal
BurstTrafficStrategy Heuristic Burst traffic, high error rate, bot probing
AiAnomalyStrategy AI-Driven Behavioral entropy, non-human activity patterns
  • Applies TTL-based dynamic blocking via Redis for temporary bans (prevents false positives)

πŸ”Ή AIService

AIService/ Β· Spring Boot Β· Maven Β· Reactive

The AI inference microservice.

  • Interfaces with a local Ollama LLM (llama3 model)
  • Performs deep behavioral anomaly detection on request patterns
  • Called only for high-complexity, edge-case threats to avoid latency impact on the gateway
  • Fully reactive using Spring WebFlux

πŸ”Ή LoggingService

LogingService/ Β· Spring Boot Β· Gradle Β· gRPC Server

The memory and data layer of the system.

  • Records all gateway interaction logs to PostgreSQL
  • Exposes gRPC endpoints for MCPService to fetch behavioral history
  • Consumes gateway decision events from Kafka
  • Powers entropy and pattern-based behavioral scoring
  • Provides REST APIs for the monitoring dashboard

πŸ”Ή EurekaServer

EurekaServer/ Β· Spring Cloud Β· Gradle Β· Port 8761

Netflix Eureka service discovery server.

  • All microservices register here dynamically
  • Enables load-balanced, service-name-based inter-service routing (used with gRPC and Feign)

πŸ”Ή DummyService

DummyService/ Β· Spring Boot Β· Gradle

A mock protected backend service that demonstrates the security mesh in action.

  • Simulates a real downstream microservice behind the gateway
  • Used for end-to-end testing of detection, blocking, and request forwarding behavior

πŸ”Ή UI β€” Sentinel Gateway Dashboard

UI/sentinel-gateway-ui/ Β· React Β· Vite Β· Tailwind CSS Β· Port 5173

A real-time security monitoring dashboard.

  • Live request logs and threat detection feed
  • Gateway statistics and charts (/dashboard)
  • Visualizes blocked IPs, threat reason breakdown, and traffic patterns
  • Communicates with backend via the ApiGateway

⚑ Technology Stack

Layer Technology Purpose
Backend Java 21, Spring Boot 3.x Core service runtime
Reactive Spring WebFlux, Project Reactor Non-blocking, high-throughput I/O
Service Discovery Spring Cloud Netflix Eureka Dynamic service registration
Messaging Apache Kafka Async, decoupled threat event pipeline
Communication gRPC Low-latency inter-service calls (MCP ↔ Logging)
HTTP Client OpenFeign REST-based service-to-service calls
Cache / Blacklist Redis (Reactive) Sub-millisecond TTL-based block enforcement
Database PostgreSQL Persistent request log storage
AI Inference Ollama (llama3) Local, privacy-first LLM anomaly detection
Frontend React, Vite, Tailwind CSS Security monitoring dashboard
Containerization Docker, Docker Compose Full-stack orchestration
Build Tools Maven, Gradle Per-service build management

πŸ” Security Design Principles

  • TTL-Based Blocking β€” temporary bans prevent permanent false positives; auto-expire via Redis
  • Kafka Buffering β€” security events are buffered, preventing system collapse under spike load
  • Decoupled AI β€” AI inference happens asynchronously; it never adds latency to the gateway response
  • Strategy Pattern β€” threat detection rules are modular and independently extensible
  • Stateless Services β€” every service is designed for horizontal scalability with no shared in-memory state
  • Local AI β€” Ollama runs fully on-premise β€” zero external API dependency, total data privacy

πŸ“ Project Structure

SentientGate/
β”œβ”€β”€ ApiGateway/                  # Spring Boot (Maven) β€” Entry point, filters, blacklist
β”‚   └── src/main/java/
β”‚       └── filters/             # Global filters: Auth, RateLimit, RequestValidation
β”‚       └── services/            # Redis blacklist service, Kafka publisher
β”‚
β”œβ”€β”€ MCPService/                  # Spring Boot (Gradle) β€” Sentient threat analysis engine
β”‚   └── src/main/java/
β”‚       └── strategy/            # PatternMatch, BurstTraffic, AiAnomaly strategies
β”‚       └── kafka/               # Security alert consumer
β”‚       └── grpc/                # gRPC client to LoggingService
β”‚
β”œβ”€β”€ AIService/                   # Spring Boot (Maven) β€” Ollama LLM integration
β”‚   └── src/main/java/
β”‚       └── service/             # OllamaService β€” behavioral anomaly analysis
β”‚
β”œβ”€β”€ LogingService/               # Spring Boot (Gradle) β€” gRPC server, log persistence
β”‚   └── src/main/java/
β”‚       └── kafka/               # Gateway decision consumer
β”‚       └── grpc/                # gRPC server β€” behavioral history provider
β”‚       └── repository/          # PostgreSQL interaction log repository
β”‚
β”œβ”€β”€ EurekaServer/                # Spring Cloud Eureka β€” Service registry
β”‚
β”œβ”€β”€ DummyService/                # Spring Boot (Gradle) β€” Mock protected service
β”‚
β”œβ”€β”€ UI/
β”‚   └── sentinel-gateway-ui/     # React + Vite + Tailwind β€” Monitoring dashboard
β”‚       └── src/
β”‚           β”œβ”€β”€ components/      # Dashboard, charts, log viewer components
β”‚           └── pages/           # Route-based page views
β”‚
β”œβ”€β”€ Architectures/               # Architecture and sequence diagrams
β”œβ”€β”€ docker-compose.yml           # Full-stack Docker Compose orchestration
β”œβ”€β”€ push_images.sh               # Docker Hub image publish script
β”œβ”€β”€ run_tests.sh                 # Automated test runner script
└── README.md

πŸš€ Quick Start

Prerequisites

Requirement Version
Java 21+
Maven 3.8+
Gradle 8+
Docker & Docker Compose Latest
Ollama Latest
Node.js 18+ (for UI dev only)

🐳 Docker Deployment (Recommended)

The fastest way to run the full stack. All service images are pre-built and published to Docker Hub.

1. Pull and Start Ollama (required for AI inference)

# Install Ollama: https://ollama.com
ollama serve
ollama pull llama3

2. Start All Services with Docker Compose

git clone https://github.com/shrihari7396/SentientGate.git
cd SentientGate

docker compose up -d

Docker Compose will automatically start:

Container Image Port
sentient-postgres postgres:16.2 5433
sentient-redis redis:7.2.4 6379
sentient-kafka confluentinc/cp-kafka:7.5.0 9092
sentient-zookeeper confluentinc/cp-zookeeper:7.5.0 β€”
eureka-server shrihari7396/eureka-server:latest 8761
api-gateway shrihari7396/api-gateway:latest 8079
logging-service shrihari7396/logging-service:latest β€”
mcp-server shrihari7396/mcp-server:latest β€”
ai-service shrihari7396/ai-service:latest β€”
dummy-service shrihari7396/dummy-service:latest β€”
sentinel-ui shrihari7396/sentinel-ui:latest 5173

3. Access the Dashboard

http://localhost:5173       β†’ Sentinel Gateway Dashboard (UI)
http://localhost:8761       β†’ Eureka Service Registry
http://localhost:8079       β†’ API Gateway (entry point)

πŸ› οΈ Local Development Setup

Step 1 β€” Start Infrastructure

# Start Kafka, Zookeeper, Redis, and PostgreSQL via Docker
docker compose up -d postgres redis zookeeper kafka

Step 2 β€” Start Ollama

ollama serve
ollama pull llama3

Step 3 β€” Start Services (Order Matters)

# 1. Service Registry
cd EurekaServer && ./gradlew bootRun

# 2. Data + Memory layer
cd LogingService && ./gradlew bootRun

# 3. AI inference
cd AIService && mvn spring-boot:run

# 4. Sentient brain
cd MCPService && ./gradlew bootRun

# 5. Entry point
cd ApiGateway && mvn spring-boot:run

# 6. Protected mock service
cd DummyService && ./gradlew bootRun

# 7. Dashboard UI
cd UI/sentinel-gateway-ui && npm install && npm run dev

Step 4 β€” Run Tests

# Run all service tests
bash run_tests.sh

πŸ§ͺ How It Works β€” Attack Scenario

  1. A bot starts sending rapid, repeated requests to the ApiGateway
  2. The gateway detects an anomaly and publishes a SecurityAlertEvent to Kafka (non-blocking)
  3. MCPService consumes the event and fetches the visitor's last 10 minutes of history from LoggingService via gRPC
  4. The Strategy Engine evaluates:
    • Pattern match β†’ checks for SQL injection, XSS payloads
    • Burst traffic heuristic β†’ detects abnormal request frequency
    • AI anomaly β†’ asks Ollama LLM to evaluate behavioral entropy
  5. If any strategy triggers, the visitor IP/token is written to Redis with a configurable TTL
  6. Future requests from this visitor are blocked at the gateway level in sub-millisecond time via Redis lookup
  7. The entire event is available in the Sentinel Dashboard

πŸ† Key Highlights

  • ⚑ Sub-millisecond blacklist enforcement using Reactive Redis
  • 🧠 Fully local AI inference (Ollama) β€” no external API, no cost, full privacy
  • πŸ”„ 100% async, event-driven threat pipeline via Apache Kafka
  • 🧩 Strategy Pattern–based modular detection engine (easily extendable)
  • 🌐 Horizontally scalable β€” all services are stateless and service-discovery–enabled
  • 🐳 One-command full-stack deployment via Docker Compose
  • πŸ“Š Real-time security monitoring dashboard

πŸ‘¨β€πŸ’» Author

Shrihari Kulkarni Computer Engineering Student

Specializing in:

  • Distributed Systems & Microservice Architecture
  • Computer Networking (OSI / TCP-IP)
  • AI-Integrated Security Systems
  • High-Concurrency & Reactive Programming

πŸ“œ License

This project is licensed under the Apache License 2.0.

You are free to use, modify, and distribute this software in accordance with the terms of the license.

See the LICENSE file for full details.

About

SentientGate is a high-performance, behavior-aware API gateway that monitors traffic patterns, enforces real-time rate limiting, and triggers adaptive defensive actions using event-driven logging and anomaly detection.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors