🧱 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/Logic | HTML5 + Vanilla JavaScript (ES2020+) | ไฟล์เดียว web/index.html ไม่มี framework/bundler |
| 3D Globe | Three.js 0.160.0 (CDN) | WebGL globe + arcs + particles ในหน้า Overview |
| Charts | SVG เขียนเอง | Threat activity graph (เส้น risk + bar severity) ไม่ใช้ chart lib |
| Realtime monitor | Polling (fetch + setInterval) | tail-f log monitor, sort by time, ดึง events จาก ingest API |
| Styling | CSS เขียนเอง (custom properties) | dark theme, ไม่มี Tailwind/Bootstrap |
| Fonts | IBM Plex Mono + system fonts | โทน console/SOC |
Backend เดโม่ NOW
server.py: stdlib ล้วน ไม่มี dependency ภายนอก
| ส่วน | ใช้ | หมายเหตุ |
| Runtime | Python 3.12 (รองรับ 3.10+) | ใช้ type hints แบบ PEP 604 |
| HTTP server | http.server.ThreadingHTTPServer | stdlib, multithread, ไม่มี framework |
| Storage | In-memory (Python lists/dicts) | โหลด JSONL เข้า RAM ตอน start + append สดผ่าน add_rows() |
| Vector store | SQLite (stdlib sqlite3) | lograg_vectors.sqlite เก็บ float32 embedding |
| HTTP client | urllib.request | เรียก OpenRouter โดยไม่ต้องลง requests |
API endpoints
| Method | Path | หน้าที่ |
| GET | /api/health · /api/stats · /api/logs · /api/alerts | dashboard data |
| POST | /api/search · /api/ask | RAG 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
| ส่วน | ใช้ | หมายเหตุ |
| Classifier | Rule-based (regex patterns) | detect_rule() → 7 categories + MITRE ATT&CK + risk score, ทำงานออฟไลน์ |
| Keyword retrieval | TF-IDF เขียนเอง (postings + idf) | query expansion ไทย/อังกฤษ, ไม่ใช้ search engine |
| Vector retrieval | cosine similarity (SQLite blobs) | optional, ใช้เมื่อมี index + API key |
| Embeddings | OpenRouter nvidia/llama-nemotron-embed | optional; fallback keyword เสมอ |
| LLM answer | OpenRouter (openrouter/free) | optional; มี local rule-based summary สำรอง |
ทุกชั้นมี fallback: vector → keyword → rule-based local answer → ระบบไม่ล่มแม้ไม่มี API key
Data & Generator NOW
| ส่วน | ใช้ | หมายเหตุ |
| Dataset | JSONL (synthetic security logs) | 10k / 50k records, 7 categories |
| Generator | Python (app/generator.py) | สุ่มไม่ซ้ำทุกครั้ง (unseeded), profile: mixed/attack/realistic |
| CSV I/O | csv stdlib | generate + ingest ผ่าน DictReader/DictWriter |
| Categories | brute_force, port_scan, web_attack, priv_esc, data_exfil, c2_beacon, benign | map → MITRE + runbook |
Production stack PROD
อยู่ใน repo เดียวกัน (app/ + Docker) สำหรับ deploy จริง / self-host เต็มรูปแบบ
| ชั้น | ใช้ | เวอร์ชัน |
| Web framework | FastAPI | 0.115.6 |
| ASGI server | Uvicorn (standard) | 0.34.0 |
| ORM / DB toolkit | SQLAlchemy (async) | 2.0.36 |
| DB driver | asyncpg (Postgres) / aiosqlite (SQLite) | 0.30.0 / 0.20.0 |
| HTTP client | httpx (async) | 0.28.1 |
| File upload | python-multipart | 0.0.20 |
| Realtime | WebSocket (FastAPI native) | fan-out broadcast in-process |
| Database | PostgreSQL 16 / SQLite | portable ด้วย DATABASE_URL |
| Container | Docker + docker-compose | python:3.12-slim, postgres:16-alpine |
External / Optional services
| บริการ | ใช้ทำอะไร | สถานะ |
| OpenRouter | LLM answer + embeddings | optional (มี local fallback) |
| Qdrant | vector DB สำหรับ production RAG | optional (ตั้งผ่าน env) |
| n8n | automation: alert → enrich → ticket/notify | แนะนำใน plan |
| Vercel | deploy static + Python serverless (api/*.py) | มี vercel.json |
สรุป Full Stack
| Layer | เดโม่ (NOW) | Production (PROD) |
| Frontend | Vanilla JS + Three.js + SVG | เหมือนเดิม (เพิ่ม WebSocket realtime) |
| Backend | stdlib http.server | FastAPI + Uvicorn |
| Storage | In-memory + SQLite | PostgreSQL (SQLAlchemy async) |
| Realtime | Polling | WebSocket |
| Retrieval | TF-IDF + SQLite vector | Qdrant / pgvector |
| Detection | Rule-based (regex + MITRE) | เหมือนเดิม + ML ในอนาคต |
| LLM | OpenRouter (optional) | OpenRouter / self-host Ollama |
| Deploy | รันตรง python3 server.py | Docker Compose / Vercel |
| Automation | ไม่มี | n8n workflows |
ปรัชญา: เดโม่ต้องรันได้ทันทีแบบ zero-dependency และออฟไลน์ แล้วค่อยสเกลขึ้น production ด้วยสแตกที่เตรียมไว้ในโปรเจกต์เดียวกัน