Skip to content

smirk-dev/gemini-hackathon

Repository files navigation

LegalMind Logo

πŸ›οΈ LegalMind

AI-Powered Legal Intelligence Platform

Transforming Contract Analysis & Legal Research with Advanced AI

Python 3.11+ FastAPI Next.js Gemini Firestore License


πŸš€ Quick Start β€’ 🌍 Deployment β€’ πŸ“š Features β€’ πŸ—οΈ Architecture β€’ πŸ“– Docs β€’ πŸ’» Demo


🌟 Overview

LegalMind is a cutting-edge, Google Cloud-native platform that revolutionizes legal contract analysis and research. Powered by Google's Gemini 2.0 Flash AI model, it orchestrates 6 specialized legal agents with 14+ intelligent tools to provide comprehensive contract intelligence, compliance verification, risk assessment, and automated legal documentation.

Perfect for legal teams, compliance officers, contract managers, and enterprises seeking AI-powered legal analysis at scale.


πŸ“Έ Platform Screenshots

🏠 Homepage - Elegant Legal Intelligence Dashboard

LegalMind Homepage

πŸ’¬ AI Response - Comprehensive Contract Analysis

Contract Analysis Response

πŸ“Š Detailed Insights - Multi-Agent Legal Intelligence

Detailed Legal Analysis

✨ Core Features

Powerful AI-Driven Legal Capabilities

πŸ“‹ Smart Contract Analysis

  • βœ“ Automated clause extraction & classification
  • βœ“ Intelligent risk scoring & assessment
  • βœ“ Structured data extraction from PDFs
  • βœ“ Comprehensive obligation mapping

πŸ“š Legal Research Engine

  • βœ“ AI-powered precedent analysis
  • βœ“ Legal framework research & recommendations
  • βœ“ Real-time regulatory tracking
  • βœ“ Automated citation management

βœ… Compliance Verification

  • βœ“ GDPR compliance checking & validation
  • βœ“ HIPAA requirements assessment
  • βœ“ CCPA obligations verification
  • βœ“ SOX compliance analysis

🎯 Risk Management

  • βœ“ Multi-dimensional contract risk scoring
  • βœ“ Automated liability identification
  • βœ“ Critical red flag detection
  • βœ“ Financial exposure analysis

πŸ“„ Document Generation

  • βœ“ Professional legal memo creation
  • βœ“ Automated compliance reports
  • βœ“ Executive summaries & briefs
  • βœ“ Multi-format export (PDF, DOCX, MD)

🧠 Transparent AI Reasoning

  • βœ“ Detailed thinking logs & reasoning traces
  • βœ“ Full decision transparency
  • βœ“ Step-by-step analysis breakdown
  • βœ“ Complete audit trails for compliance

πŸ—οΈ Architecture

Multi-Agent System πŸ€–

+--------------------+        +-----------------------------+
|        User        |        |     Next.js Dashboard      |
|  (Uploads Legal    |<------>|   (Review & Interactions)  |
|        PDF)        |        +--------------^-------------+
+---------+----------+                       |
          |                                  |
          v                                  |
+---------------------------+                |
|   Upload & Ingestion      |                |
|  (FastAPI / Cloud Run)    |                |
+-------------+-------------+                |
              |                              |
              v                              |
      +--------------------+                 |
      |  Router / Query    |                 |
      |     Classifier     |-----------------+
      +----+-------+-------+
           |       |
   +-------+       +-----------------------------+
   |                             |              |
   v                             v              v
+----------+              +-------------+  +-------------+
| Risk    |              | Compliance  |  |  Summary    |
| Agent   |              | Agent       |  | Agent       |
+----+----+              +------+------ +--+-----+------+
     |                          |               |
     +-----------+--------------+---------------+
                 v
        +----------------------------+
        |      Firestore Memory      |
        |  (Insights, Flags, Notes)  |
        +--------------+-------------+
                       |
                       v
            +------------------------+
            |  Aggregation / API     |
            |   (FastAPI Backend)    |
            +------------------------+

Tech Stack πŸ› οΈ

🎨 Layer ⚑ Technology πŸ“Œ Purpose
πŸ–₯️ Frontend Next.js 15 β€’ React 18 β€’ TypeScript β€’ Tailwind CSS Modern UI with real-time updates
βš™οΈ Backend FastAPI β€’ Python 3.11 β€’ Uvicorn High-performance async API
πŸ€– AI/ML Google Gemini 2.0 Flash Advanced reasoning & function calling
πŸ’Ύ Database Google Cloud Firestore Scalable document database (99.999% SLA)
πŸ“¦ Storage Google Cloud Storage Secure PDF & document management
☁️ Infrastructure Google Cloud Platform Serverless, auto-scaling deployment

πŸ“Š System Capabilities

🎯 Component πŸ“ˆ Count πŸ“ Details
πŸ€– Legal Agents 6 Specialized AI agents for different legal tasks
πŸ› οΈ Tools 14+ Contract, compliance, risk, document, clause tools
πŸ”Œ API Endpoints 31 29 REST + 2 WebSocket for real-time communication
πŸ’Ύ Collections 6 Sessions, messages, contracts, clauses, logs, docs
πŸ’» Lines of Code 9,000+ ~6,000 backend + ~3,000 frontend
βœ… Test Coverage 97% 34/35 tests passing

πŸš€ Quick Start

Get LegalMind Running in 3 Steps

Prerequisites

βœ… Python 3.11+ βœ… Node.js 18+ βœ… Google Gemini API Key βœ… Google Cloud Project with Firestore

πŸ“¦ Installation

Step 1️⃣: Clone & Navigate

git clone https://github.com/smirk-dev/gemini-hackathon.git
cd gemini-hackathon

Step 2️⃣: Configure Environment

# Create backend/.env.local with your secrets
GEMINI_API_KEY=your_api_key_here
GOOGLE_CLOUD_PROJECT=legalmind-486106
APP_ENV=development
DEBUG=true

Step 3️⃣: Start Services

πŸͺŸ Option A: Automated (Windows)

start-legalmind.bat

🌍 Option B: Manual (All Platforms)

# Terminal 1: Backend
cd backend
python main_new.py

# Terminal 2: Frontend
cd frontend
npm install
npm run dev

🌐 Access the Platform

🎯 Service πŸ”— URL πŸ“ Description
🌐 Web App http://localhost:3000 Main application interface
βš™οΈ API http://localhost:8000 Backend API server
πŸ“– API Docs http://localhost:8000/docs Interactive Swagger UI

🌍 Deployment

Deploy LegalMind to Google Cloud in 5 Minutes ☁️

πŸš€ Quick Deploy (One-Command Setup)

# 1️⃣ Run setup script to configure GCP
./setup-gcp.ps1          # Windows
# or
./setup-gcp.sh           # macOS/Linux

# 2️⃣ Add GitHub secrets (from script output)
# - GCP_PROJECT_ID
# - WIF_PROVIDER
# - WIF_SERVICE_ACCOUNT
# - FIREBASE_SERVICE_ACCOUNT

# 3️⃣ Push to main branch
git push origin main

# ✨ GitHub Actions automatically deploys:
# - Backend β†’ Cloud Run
# - Frontend β†’ Firebase Hosting

πŸ—οΈ Production Architecture

🌐 Frontend Firebase Hosting (Global CDN + Auto-scaling)
βš™οΈ Backend Google Cloud Run (Serverless, Auto-scaling)
πŸ’Ύ Database Firestore (99.999% SLA, Global Replication)
πŸ“¦ Storage Cloud Storage (PDFs & Documents)

πŸ’° Estimated Costs

☁️ Cloud Run ~$0.40 per million requests
🌐 Firebase Hosting Free tier (10 GB/month)
πŸ’Ύ Firestore Free tier (25k reads + writes/day)
πŸ’΅ Total $5-15/month for moderate usage

πŸ“– Full Deployment Guides:


🎯 Use Cases

Transform Legal Operations Across Your Organization

πŸ‘¨β€βš–οΈ For Legal Teams

  • πŸ“‹ Automate contract review processes
  • ⚑ Accelerate due diligence workflows
  • 🎯 Standardize analysis procedures
  • πŸ’Ύ Maintain searchable contract archives
  • πŸ“Š Generate comprehensive legal reports

βœ… For Compliance Officers

  • πŸ” Verify regulatory compliance automatically
  • πŸ“ˆ Track compliance evolution over time
  • πŸ“Š Generate detailed compliance reports
  • 🚨 Flag potential violations early
  • πŸ“ Document compliance processes

πŸ“ For Contract Managers

  • πŸ”Ž Extract and structure contract data
  • 🏷️ Identify key obligations & milestones
  • πŸ“… Track important dates and deadlines
  • πŸ’° Calculate financial exposure
  • πŸ“ˆ Monitor contract lifecycle

🏒 For Enterprises

  • πŸš€ Scale legal operations efficiently
  • πŸ“ˆ Improve efficiency by 10x
  • πŸ’‘ Reduce manual work dramatically
  • πŸŽ“ Train teams on best practices
  • πŸ’Ό Optimize legal budgets

πŸ“š Documentation

Comprehensive Guides & Resources

πŸš€ Getting Started


πŸ—οΈ Technical Guides

🎨 Development Guides


πŸ“Š System Status


πŸ”Œ API Endpoints

31 REST & WebSocket Endpoints for Complete Legal Operations

πŸ’¬ Chat API

POST   /api/chat                    # Send message to legal agents
GET    /api/chat/sessions           # List all chat sessions
POST   /api/chat/session            # Create new session
WS     /ws/chat/{session_id}        # Real-time WebSocket chat

πŸ“„ Contract API

POST   /api/contracts/upload        # Upload contract PDF
GET    /api/contracts               # List all contracts
GET    /api/contracts/{id}          # Get contract details
GET    /api/contracts/{id}/clauses  # Extract clauses
GET    /api/contracts/{id}/download # Download contract

βœ… Compliance & Risk API

GET    /api/compliance/frameworks   # List compliance frameworks
GET    /api/compliance/check/{id}   # Check compliance status
GET    /api/risk/assess/{id}        # Assess contract risks

βš™οΈ System API

GET    /api/health                  # System health check
GET    /api/agents                  # List all agents
GET    /api/agents/{id}             # Get agent details

πŸ“– Full Documentation: Visit http://localhost:8000/docs for interactive Swagger UI


πŸ§ͺ Testing

Comprehensive Test Suite with 97% Coverage

πŸ” Run Backend Tests

cd backend
python test_backend.py

πŸ“Š Expected Results: 34/35 tests passing (97% coverage)

πŸ’š Health Check

# Quick health verification
curl http://localhost:8000/api/health

# Expected response:
# {"status": "healthy", "version": "1.0.0"}

πŸ“ Project Structure

gemini-hackathon/
β”œβ”€β”€ πŸ“‚ backend/                          # FastAPI Server
β”‚   β”œβ”€β”€ services/                        # Google Cloud integrations
β”‚   β”‚   β”œβ”€β”€ gemini_service.py           # Gemini API wrapper
β”‚   β”‚   β”œβ”€β”€ firestore_service.py        # Database service
β”‚   β”‚   └── storage_service.py          # Cloud Storage service
β”‚   β”œβ”€β”€ agents/                          # Legal AI agents
β”‚   β”‚   β”œβ”€β”€ agent_definitions_new.py    # 6 specialized agents
β”‚   β”‚   └── agent_strategies_new.py     # Query routing logic
β”‚   β”œβ”€β”€ tools/                           # 14+ legal tools
β”‚   β”‚   β”œβ”€β”€ contract_tools.py           # Contract analysis
β”‚   β”‚   β”œβ”€β”€ compliance_tools.py         # Compliance checking
β”‚   β”‚   β”œβ”€β”€ risk_tools.py               # Risk assessment
β”‚   β”‚   β”œβ”€β”€ clause_tools.py             # Clause extraction
β”‚   β”‚   β”œβ”€β”€ document_tools.py           # Document generation
β”‚   β”‚   └── logging_tools.py            # Thinking logs
β”‚   β”œβ”€β”€ api/                             # REST API
β”‚   β”‚   β”œβ”€β”€ endpoints_new.py            # 31 endpoints
β”‚   β”‚   └── app_new.py                  # FastAPI setup
β”‚   β”œβ”€β”€ managers/                        # Business logic
β”‚   β”‚   └── chatbot_manager_new.py      # Session orchestration
β”‚   β”œβ”€β”€ config/                          # Configuration
β”‚   β”‚   └── settings.py                 # Environment settings
β”‚   β”œβ”€β”€ main_new.py                     # Entry point
β”‚   β”œβ”€β”€ .env.local                      # Secrets (gitignored)
β”‚   β”œβ”€β”€ .env.example                    # Config template
β”‚   └── firestore.rules                 # Security rules
β”‚
β”œβ”€β”€ πŸ“‚ frontend/                         # Next.js Application
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ page.tsx                    # Landing page
β”‚   β”‚   β”œβ”€β”€ chat/                       # Chat interface
β”‚   β”‚   β”œβ”€β”€ contracts/                  # Contract management
β”‚   β”‚   β”œβ”€β”€ dashboard/                  # Analytics dashboard
β”‚   β”‚   β”œβ”€β”€ reports/                    # Documents & reports
β”‚   β”‚   β”œβ”€β”€ thinking-logs/              # Agent reasoning
β”‚   β”‚   └── api/                        # API proxy routes
β”‚   β”œβ”€β”€ components/                      # Reusable UI components
β”‚   β”œβ”€β”€ lib/                             # Utilities & helpers
β”‚   └── app/globals.css                 # Theme (legal blue)
β”‚
β”œβ”€β”€ πŸ“‚ docs/                             # Documentation
β”‚   β”œβ”€β”€ PROJECT_STATUS.md
β”‚   β”œβ”€β”€ IMPLEMENTATION_PLAN.md
β”‚   β”œβ”€β”€ FRONTEND_CHANGES.md
β”‚   └── CODE_TRANSFORMATION_GUIDE.md
β”‚
β”œβ”€β”€ πŸš€ start-legalmind.bat              # Quick start script
β”œβ”€β”€ πŸ” .env.local                       # Your secrets
β”œβ”€β”€ πŸ“– README.md                        # This file
β”œβ”€β”€ ⚑ QUICK_START.md                   # Quick reference
β”œβ”€β”€ βœ… COMPLETE_SETUP.md                # Full guide
β”œβ”€β”€ πŸ—„οΈ FIRESTORE_SETUP.md               # Database setup
β”œβ”€β”€ πŸ“Š STATUS.txt                       # System overview
└── πŸ“œ LICENSE.md                       # Apache-2.0

πŸ” Security

Enterprise-Grade Security Features

πŸ›‘οΈ Current Setup (Development)

  • βœ… .env.local contains API keys (never committed)
  • βœ… Firestore security rules deployed
  • βœ… CORS configured for local development
  • βœ… Debug logging enabled for troubleshooting

πŸš€ Production Checklist

  • ⬜ Update Firestore rules with authentication
  • ⬜ Create service account for Google Cloud
  • ⬜ Enable Cloud Run deployment
  • ⬜ Configure custom domain with SSL
  • ⬜ Set up monitoring & alerting
  • ⬜ Enable production logging

πŸ“– See COMPLETE_SETUP.md for detailed production deployment.


πŸ“ˆ Performance Metrics

🎯 Metric ⚑ Value πŸ“Š Status
Backend Startup < 3 seconds 🟒 Optimal
Frontend Build 12.7 seconds 🟒 Fast
API Response Time < 100ms (local) 🟒 Excellent
Chat Response Time 2-5 seconds 🟒 Quick
Test Coverage 97% 🟒 High
Firestore SLA 99.999% 🟒 Enterprise

🀝 Contributing

We Welcome Contributions!

Help us make LegalMind even better for the legal community.

# 1️⃣ Fork the repository
git clone https://github.com/your-username/gemini-hackathon.git

# 2️⃣ Create feature branch
git checkout -b feature/amazing-feature

# 3️⃣ Commit your changes
git commit -m 'Add amazing feature'

# 4️⃣ Push to branch
git push origin feature/amazing-feature

# 5️⃣ Open Pull Request

πŸ’‘ Ideas for Contributions:

  • πŸ› Bug fixes and improvements
  • ✨ New legal tools or agents
  • πŸ“š Documentation enhancements
  • πŸ§ͺ Additional test coverage
  • 🌍 Internationalization support

πŸ“ž Support & Resources

Helpful Links & Resources

☁️ Cloud Platforms

πŸ“š Frameworks & Libraries

πŸ’¬ Getting Help

πŸ“– Read COMPLETE_SETUP.md for detailed guide
πŸ’¬ Check STATUS.txt for system overview
πŸ“ Review docs/ directory for technical details


πŸ“„ License

Apache License 2.0

This project is licensed under the Apache License 2.0 - see LICENSE.md for details.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

Free to use for commercial and non-commercial purposes βœ…


πŸ™ Acknowledgments

Built with ❀️ Using World-Class Technologies


Technology Purpose
☁️ Google Cloud Platform Enterprise-grade cloud infrastructure
πŸ€– Google Gemini 2.0 Flash Advanced AI capabilities & reasoning
⚑ FastAPI High-performance backend framework
βš›οΈ Next.js Modern React-based frontend
πŸ’Ύ Firestore Scalable NoSQL database
🌍 Open Source Community Amazing tools & libraries

Special thanks to all contributors and the legal tech community!


🌟 Ready to Transform Legal Analysis? 🌟

Get Started in 60 Seconds

πŸ“– Option 1: Quick Start

Start with QUICK_START.md for a guided walkthrough

πŸš€ Option 2: Instant Launch

start-legalmind.bat

🌐 Then Visit



πŸ’‘ Built with Cutting-Edge Technology

Google Cloud Platform β€’ Gemini 2.0 Flash AI β€’ FastAPI β€’ Next.js β€’ Firestore



βš–οΈ Empowering legal teams with enterprise-grade AI intelligence



Made with ❀️ for the modern legal world

About

Your Pocket Legal AI Agent

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors