How avg-team/vn-law works
Project type and purpose
• This is a full-stack, microservice-based legal knowledge search and Q&A application (“VN LAW”) built on a monorepo layout.
• It serves user-facing front-ends (website, mobile, docs) and a suite of back-end microservices (Java Spring Boot, Python) behind a Kong API Gateway.
• It features: secure authentication/authorization, law document ingestion and indexing, generative‐AI-driven NLP (embeddings and Q&A), real-time chat, and crawl pipelines.
High-level file structure and architectural patterns
• Top level:
• api-gateway (Kong router + routing rules)
• auth-service, base-service, customer-service, law-service (Spring Boot microservices, each with its own Dockerfile, DB configs, caches, Kafka producers/consumers)
• chat-service (Python inference and training with Chroma DB embeddings)
• crawl (Python Flask + Celery ingestion pipeline)
• front-end:
– website (React/Vite)
– mobile (Flutter multi-platform)
– docs (Docusaurus)
• docker-compose.yml, pom.xml, prometheus.yml
• Architectural patterns:
• Microservice decomposition by domain (auth, law, customer, base library)
• API Gateway for request routing, SSL termination, rate-limiting (Kong)
• Event-driven flows via Kafka (document sync, notifications)
• Caching (Redis via Spring configs)
• Search indexing (Elasticsearch in law-service + ChromaDB in chat)
• Async task queue (Celery in crawl service)
• DevOps: Docker-Compose, Kubernetes (ArgoCD, Helm), Pulumi IaC, Observability (Prometheus, Grafana, Zipkin, Fluentd)
Main components
• Front-ends:
• Website (React)
• Mobile app (Flutter)
• Documentation portal (Docusaurus)
• API Gateway: Kong (kong.yml)
• Back-end microservices:
• auth-service: JWT, API-key filters, OAuth2, MySQL DB
• base-service: common entities, swagger, Redis-cache
• customer-service: domain logic, WebSocket chat, Kafka producers/consumers, MySQL
• law-service: document controllers, Kafka, Elasticsearch, Redis, MySQL
• crawl: Flask API, Celery workers, SQL ingestion, raw file processor
• chat-service: model inference server, embedding pipeline, Chroma DB storage
• Data stores and middleware:
• MySQL clusters (one per service or shared multi-schema)
• Redis for cache and Celery broker
• Kafka cluster for event streaming
• Elasticsearch for full-text law search
• ChromaDB for embedding vector search
• Observability & infra:
• Prometheus (prometheus.yml)
• Grafana, Zipkin, Fluentd
• CI/CD (Jenkins, ArgoCD), Pulumi IaC
Relationships and data flows
• User → [Website / Mobile] → API Gateway → appropriate microservice
• auth-service ↔ MySQL, issue JWT → gateways and other services
• law-service: CRUD & sync data → publish events to Kafka → Index to Elasticsearch
• customer-service: push notifications via Kafka → clients via WebSocket
• crawl: scheduled tasks (Celery) → ingest raw documents → store in MySQL → send sync events
• chat-service: user question → embed with model → query ChromaDB → return answer
• base-service: shared DTOs/entities → consumed by other services
Architectural patterns & design principles
• Single responsibility microservices
• API-first design behind a unified gateway
• Event-driven asynchronous communication (Kafka)
• CQRS style for search/indexing (law-service writes to ES, search reads from ES)
• Cache-aside pattern (Redis) for heavy read operations
• Separation of concerns: front-end vs back-end vs data layers vs integration