LexAI is a high-performance, hybrid C++/Python system designed for automated legal adjudication under Croatian Law. It combines a deterministic C++ core for legal logic with a Python FastAPI orchestration layer, integrated with a PostgreSQL database and a local LLM (Ollama) for natural language processing.
The system runs as a multi-container Docker application:
- LexAI App: FastAPI + C++ Core (Business Logic).
- PostgreSQL: Persistent storage for driver history (Recidivism checks).
- Ollama: Local LLM service running
mistralfor parsing case descriptions.
- C++ Core:
- Speeding: Calculates fines/points based on
config/rules.json. Checks DB for prior offenses (Recidivism doubles the fine). - Alcohol: Adjudicates based on driver category (Young, Professional, Standard).
- Interest: Calculates penalty interest (Civil Obligations Act).
- Severance: Calculates severance pay (Labor Act).
- Speeding: Calculates fines/points based on
- AI Parsing: Uses a local LLM (
mistral) to parse unstructured text (e.g., "Driver was drunk, 1.5 g/kg") into structured JSON. - PDF Generation: Generates official verdict documents using Jinja2 and WeasyPrint.
- Configuration: All legal parameters (fines, limits, rates) are hot-loadable from
config/rules.json.
This is the recommended way to run the full stack.
-
Start the System:
docker compose up --build
Note: The first run will take a few minutes to download the 4GB LLM model.
-
Access the UI: Open http://localhost:8000 in your browser.
-
Test the API:
# Speeding (checks DB for recidivism) curl -X POST "http://localhost:8000/judge/speeding" \ -H "Content-Type: application/json" \ -d '{"measured_speed": 130, "limit": 100, "tolerance": 10, "driver_id": "recidivist_1"}' # AI Parsing curl -X POST "http://localhost:8000/parse" \ -H "Content-Type: application/json" \ -d '{"text": "Driver detected with 1.5 g/kg alcohol, young driver."}'
src/core/: C++ business logic (Speeding, Alcohol, Interest, Severance).src/api/: Python FastAPI app, PDF generator, LLM parser.config/: External configuration (rules.json).docker/: Dockerfile and entrypoint scripts.tests/: Unit tests.
To develop locally, you need cmake, g++, python3.11, libpqxx-dev, and nlohmann-json3-dev.
-
Build C++ Core:
mkdir build && cd build cmake .. && make
-
Run API:
export PYTHONPATH=$PYTHONPATH:$(pwd)/build uvicorn src.api.main:app --reload
Note: Local run requires a running Postgres instance and Ollama service accessible at the URLs defined in the code.