🧱 ROGLAG · Tech Stack

สแตกจริงของระบบ Security Log RAG + Realtime Threat Console

Python 3.12stdlib http.server Vanilla JSThree.js Rule + RAGFastAPI SQLAlchemyDockerOpenRouter

NOW ที่รันอยู่จริงในเดโม่ · PROD สแตกระดับ production ที่อยู่ใน repo เดียวกัน

ภาพรวมสถาปัตยกรรม

เดโม่ปัจจุบันเน้น zero-dependency รันได้ทันที, แต่ใน repo มีสแตก production พร้อมไปต่อ

Log sources
auth/nginx/fw/system
Generator / CSV
ingest
Rule classifier
detect_rule
In-memory index
TF-IDF + vector
HTTP/JSON API Dashboard
vanilla JS
เดโม่ใช้ Python stdlib ล้วน (ไม่ต้องลง dependency) เก็บ log ใน memory + ตอบ JSON API; ส่วน production ใช้ FastAPI + SQLAlchemy + Docker (หัวข้อ 6)

Frontend NOW

หน้าเดียว ไม่มี build step: โหลดเร็ว แก้ง่าย

ส่วนใช้หมายเหตุ
Markup/LogicHTML5 + Vanilla JavaScript (ES2020+)ไฟล์เดียว web/index.html ไม่มี framework/bundler
3D GlobeThree.js 0.160.0 (CDN)WebGL globe + arcs + particles ในหน้า Overview
ChartsSVG เขียนเองThreat activity graph (เส้น risk + bar severity) ไม่ใช้ chart lib
Realtime monitorPolling (fetch + setInterval)tail-f log monitor, sort by time, ดึง events จาก ingest API
StylingCSS เขียนเอง (custom properties)dark theme, ไม่มี Tailwind/Bootstrap
FontsIBM Plex Mono + system fontsโทน console/SOC

Backend เดโม่ NOW

server.py: stdlib ล้วน ไม่มี dependency ภายนอก

ส่วนใช้หมายเหตุ
RuntimePython 3.12 (รองรับ 3.10+)ใช้ type hints แบบ PEP 604
HTTP serverhttp.server.ThreadingHTTPServerstdlib, multithread, ไม่มี framework
StorageIn-memory (Python lists/dicts)โหลด JSONL เข้า RAM ตอน start + append สดผ่าน add_rows()
Vector storeSQLite (stdlib sqlite3)lograg_vectors.sqlite เก็บ float32 embedding
HTTP clienturllib.requestเรียก OpenRouter โดยไม่ต้องลง requests

API endpoints

MethodPathหน้าที่
GET/api/health · /api/stats · /api/logs · /api/alertsdashboard data
POST/api/search · /api/askRAG retrieval + Q&A
POST/api/mock/emitยิง mock log realtime (คืน events)
POST/api/ingest/csvอัปโหลด CSV → classify
GET/api/generate/csvสร้าง CSV ใหม่ (unseeded)

Detection & RAG NOW

ส่วนใช้หมายเหตุ
ClassifierRule-based (regex patterns)detect_rule() → 7 categories + MITRE ATT&CK + risk score, ทำงานออฟไลน์
Keyword retrievalTF-IDF เขียนเอง (postings + idf)query expansion ไทย/อังกฤษ, ไม่ใช้ search engine
Vector retrievalcosine similarity (SQLite blobs)optional, ใช้เมื่อมี index + API key
EmbeddingsOpenRouter nvidia/llama-nemotron-embedoptional; fallback keyword เสมอ
LLM answerOpenRouter (openrouter/free)optional; มี local rule-based summary สำรอง
ทุกชั้นมี fallback: vector → keyword → rule-based local answer → ระบบไม่ล่มแม้ไม่มี API key

Data & Generator NOW

ส่วนใช้หมายเหตุ
DatasetJSONL (synthetic security logs)10k / 50k records, 7 categories
GeneratorPython (app/generator.py)สุ่มไม่ซ้ำทุกครั้ง (unseeded), profile: mixed/attack/realistic
CSV I/Ocsv stdlibgenerate + ingest ผ่าน DictReader/DictWriter
Categoriesbrute_force, port_scan, web_attack, priv_esc, data_exfil, c2_beacon, benignmap → MITRE + runbook

Production stack PROD

อยู่ใน repo เดียวกัน (app/ + Docker) สำหรับ deploy จริง / self-host เต็มรูปแบบ

ชั้นใช้เวอร์ชัน
Web frameworkFastAPI0.115.6
ASGI serverUvicorn (standard)0.34.0
ORM / DB toolkitSQLAlchemy (async)2.0.36
DB driverasyncpg (Postgres) / aiosqlite (SQLite)0.30.0 / 0.20.0
HTTP clienthttpx (async)0.28.1
File uploadpython-multipart0.0.20
RealtimeWebSocket (FastAPI native)fan-out broadcast in-process
DatabasePostgreSQL 16 / SQLiteportable ด้วย DATABASE_URL
ContainerDocker + docker-composepython:3.12-slim, postgres:16-alpine

External / Optional services

บริการใช้ทำอะไรสถานะ
OpenRouterLLM answer + embeddingsoptional (มี local fallback)
Qdrantvector DB สำหรับ production RAGoptional (ตั้งผ่าน env)
n8nautomation: alert → enrich → ticket/notifyแนะนำใน plan
Verceldeploy static + Python serverless (api/*.py)มี vercel.json

สรุป Full Stack

Layerเดโม่ (NOW)Production (PROD)
FrontendVanilla JS + Three.js + SVGเหมือนเดิม (เพิ่ม WebSocket realtime)
Backendstdlib http.serverFastAPI + Uvicorn
StorageIn-memory + SQLitePostgreSQL (SQLAlchemy async)
RealtimePollingWebSocket
RetrievalTF-IDF + SQLite vectorQdrant / pgvector
DetectionRule-based (regex + MITRE)เหมือนเดิม + ML ในอนาคต
LLMOpenRouter (optional)OpenRouter / self-host Ollama
Deployรันตรง python3 server.pyDocker Compose / Vercel
Automationไม่มีn8n workflows
ปรัชญา: เดโม่ต้องรันได้ทันทีแบบ zero-dependency และออฟไลน์ แล้วค่อยสเกลขึ้น production ด้วยสแตกที่เตรียมไว้ในโปรเจกต์เดียวกัน