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 PlatformGemini 2.0 Flash AIFastAPINext.jsFirestore



⚖️ 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