This guide takes you on a journey through the codebase, tracing the lifecycle of the application from startup to query execution.
Unless running in a container, everything starts at com.lathadb.Main.
Before any UI is shown, we perform critical environment patches:
- GraalVM Fix: We explicitly set
java.hometo ensure native image compatibility. - FlatLaf: We initialize the
FlatLightLaflibrary to give Swing a modern, flat aesthetic.
Latha DB is a chameleon. Based on the arguments, it morphs:
java -jar latha.jar --server: BootsLathaServer, skipping the UI entirely for headless deployments.- (Default): Boots
LathaWindow, the Swing-based GUI for interactive use.
What happens when you type SELECT * FROM Users?
The user types the command into the Query Explorer text area in LathaWindow.
Because the core engine only speaks Lisp, we must translate.
- Detection: The translator checks if the string starts with
SELECT,INSERT, orCREATE. - Regex Parsing: It uses Regex capture groups to strip out columns and table names.
- Output:
SELECT * FROM Usersbecomes(select :all :from "Users").
The string is tokenized (broken into chunks) and built into an Abstract Syntax Tree (AST) of LispNode objects. (select ...) becomes a root node with children parameters.
The execute() method is the brain.
- It recursively evaluates the AST.
- It switches on the function name (e.g.,
select). - It calls the Storage Engine (
Table.java) to scan records, apply filters, and return a list ofLathaRecords.
The result bubbles back up:
- Text Result: A success message or record count is shown in the Console.
- Table Update: The central
JTableis refreshed with the new data. - Analytics: If the command was a
(plot), theAnalytics Dashboardrenders the JFreeChart.
- Server: Uses a
CachedThreadPoolto handle thousands of concurrent socket connections without blocking the main thread. - Client: Establishes a TCP connection and spawns a background
ReaderThreadto listen for asynchronousPUSHnotifications from the server (Real-time updates).
The cool "Physics Graph" is a simulation loop.
- The Loop: A Swing
Timerfires ~60 times a second. - Physics:
- Repulsion: All nodes push away from each other so they don't overlap.
- Attraction: Connected nodes pull toward each other like springs.
- Gravity: A gentle force pulls everything to the center so the graph doesn't fly off-screen.