# tomasonjo-labs/legal-tech-chat architecture

> Architecture diagram of the GitHub repository tomasonjo-labs/legal-tech-chat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tomasonjo-labs/legal-tech-chat
- Repository: https://github.com/tomasonjo-labs/legal-tech-chat

## Overview

##### Project Type and Purpose
- The README explains that the project processes the Contract Understanding Atticus Dataset (CUAD) using LangChain to extract structured data from legal contracts. It further builds a knowledge graph and provides intelligent query capabilities via a LangGraph-powered agent.
- This makes it a full-stack, data-processing application with AI-driven insights and a knowledge graph, targeted at automating contract analysis and querying.

##### File Structure
- Top-Level Directories:
- “backend”: Contains Python files such as agent.py, agent_manager.py, main.py, and utility scripts. This directory implements the server-side logic, including agent handling and integration with LangChain for contract processing.
- “frontend”: Contains a React-based (using TypeScript with Vite) UI that likely allows users to query, view results, and interact with the knowledge graph system.
- “research”: Provides notebooks and benchmarking assets. It is used to experiment with extraction benchmarks, import graphs, and analysis on the contract data.
- Configuration & Deployment:
- Dockerfiles in both “backend” and “frontend” along with docker-compose.yml indicate containerized deployment.
- Environment example files (.env.example) exist for setting runtime configurations.
- Architectural Patterns:
- The separation between frontend and backend hints at a multi-tier architecture.
- The usage of agent and agent manager components in the backend suggests a modular, microservice-like approach for processing legal contracts and performing intelligent queries.
- The research folder shows an iterative, experimental approach for performance evaluation and data processing validation, further reinforcing a layered design (operational system vs. prototyping/benchmarking).

a. Main Components:
- Frontend Client: Built with React (TypeScript) via Vite. It manages the UI including chat components, theme management, and UI widgets.
- Backend Service: A Python-based server that includes:
- The agent modules (agent.py, agent_manager.py) which implement LangChain and LangGraph capabilities.
- Utility modules under tools (e.g., contract_search_tool.py, utils.py) assisting with data processing.
- The main entry point (main.py) to initialize and run the service.
- Research/Benchmarking Components: This includes Jupyter notebooks and CSV/JSON data in “research” that are used for performance evaluation and tweaking extraction/import processes.
- Containerization & Deployment: Docker and docker-compose components that encapsulate both backend and frontend services.

b. Relationships and Interactions:
- Connectivity from the backend processing service to a “Knowledge Graph” component, representing the extraction and storage of contract data.
- Use a container-level view (Docker containers) to show that the frontend and backend are deployed as separate containerized services, linked via docker-compose.

c. Architectural Patterns and Design Principles:
- Separation of concerns:
- Frontend cleanly separated from backend.
- Backend modularity through distinct agent components and utility modules.
- Use of containerization for reproducible deployment.
- Iterative research/benchmarking process that feeds into system optimization.

d. Relevant Technologies and Frameworks:
- Frontend: React, TypeScript, Vite.
- Backend: Python, LangChain, LangGraph – potentially other libraries for contract extraction.
- Containerization: Docker, docker-compose.
- Data Storage: A placeholder for a graph database (or knowledge graph storage) if not explicitly defined (could be inferred/extended later).

##### Final Details
- Provide annotations where needed to clarify that while the research folder isn’t directly part of the runtime system, it plays a role in performance benchmarking and feature enhancement.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        FE["React App (Frontend)"]:::ui
    end

    subgraph "Backend Layer"
        BE_Main["Main (main.py)"]:::backend
        BE_Agent["Agent (agent.py)"]:::backend
        BE_AgentManager["Agent Manager (agent_manager.py)"]:::backend
        BE_Tools["Utility Modules (backend/tools)"]:::backend
        KG["Knowledge Graph"]:::data
    end

    subgraph "Research & Benchmarking"
        Research["Research/Benchmarking"]:::research
    end

    subgraph "Containerization & Deployment"
        FE_Docker["Frontend Docker"]:::container
        BE_Docker["Backend Docker"]:::container
        Compose["Docker Compose"]:::container
    end

    %% Data flows between segments
    FE -->|"API_call"| BE_Main
    BE_Main -->|"invokes"| BE_Agent
    BE_Main -->|"manages"| BE_AgentManager
    BE_Agent -->|"extracts_data"| KG
    BE_AgentManager -->|"coordinates"| KG
    BE_Tools -->|"supports_KG"| KG
    Research -->|"provides_insights"| BE_Main
    Compose -->|"deploys"| FE_Docker
    Compose -->|"deploys"| BE_Docker
    FE_Docker -->|"runs"| FE
    BE_Docker -->|"runs"| BE_Main

    %% Click Events
    click FE "https://github.com/tomasonjo-labs/legal-tech-chat/tree/main/frontend/src"
    click BE_Main "https://github.com/tomasonjo-labs/legal-tech-chat/blob/main/backend/main.py"
    click BE_Agent "https://github.com/tomasonjo-labs/legal-tech-chat/blob/main/backend/agent.py"
    click BE_AgentManager "https://github.com/tomasonjo-labs/legal-tech-chat/blob/main/backend/agent_manager.py"
    click BE_Tools "https://github.com/tomasonjo-labs/legal-tech-chat/tree/main/backend/tools"
    click Research "https://github.com/tomasonjo-labs/legal-tech-chat/tree/main/research"
    click FE_Docker "https://github.com/tomasonjo-labs/legal-tech-chat/tree/main/frontend/Dockerfile"
    click BE_Docker "https://github.com/tomasonjo-labs/legal-tech-chat/tree/main/backend/Dockerfile"
    click Compose "https://github.com/tomasonjo-labs/legal-tech-chat/blob/main/docker-compose.yml"

    %% Styles
    classDef ui fill:#f9e79f,stroke:#b9770e,stroke-width:2px;
    classDef backend fill:#d5f5e3,stroke:#117a65,stroke-width:2px;
    classDef data fill:#d6eaf8,stroke:#2874a6,stroke-width:2px;
    classDef research fill:#fdebd0,stroke:#d35400,stroke-width:2px;
    classDef container fill:#ebdef0,stroke:#884ea0,stroke-width:2px;
```
