Skip to content

mandilkhadka/Smart-Contract-Analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Smart Contract Analyzer

A powerful AI-powered tool that helps users analyze contracts by automatically summarizing clauses, obligations, and potential risks.


πŸš€ Purpose

Manual contract review is time-consuming and error-prone. This app automates the process by extracting text from uploaded PDFs, identifying key clauses, and generating a comprehensive risk analysis reportβ€”helping users make informed decisions faster.


✨ Core Features

  • πŸ“„ Upload PDF/Images β€” Drag-and-drop interface for uploading contract documents
  • πŸ” AI-Powered Clause Detection β€” Automatically identifies sections like termination, payment, confidentiality, liability, governing law, intellectual property, and dispute resolution
  • βš–οΈ Risk Scoring Dashboard β€” Visualizes overall risk score (0-100) and categorizes risks by severity:
    • πŸ”΄ Critical Risks β€” Major exposure areas requiring immediate attention
    • 🟑 Moderate Risks β€” Clauses needing negotiation
    • 🟒 Low Risks β€” Standard clauses with minor impact
  • πŸ“Š Contract History β€” View all analyzed contracts in one place
  • πŸ—‘οΈ Delete Contracts β€” Manage your contract library
  • πŸ“ˆ Analytics Dashboard β€” View statistics across all analyzed contracts
  • πŸ“‘ Multiple Export Options β€” Export analysis reports as PDF or JSON
  • πŸ’¬ Custom Questions β€” Ask specific questions about your contract
  • ⏱️ Real-time Processing β€” Live updates during analysis

🧰 Tech Stack

  • Backend: Ruby on Rails 7+
  • Frontend: React 19 with React Router
  • Database: PostgreSQL
  • AI Integration: Gemini 2.5 Flash (via RubyLLM)
  • File Handling: Active Storage
  • PDF Processing: pdf-reader gem
  • PDF Generation: Prawn gem
  • Styling: SCSS with custom theme

πŸš€ Getting Started

Prerequisites

  • Ruby 3.2+
  • Rails 7+
  • PostgreSQL
  • Node.js 18+ (for frontend dependencies)

Installation

# Clone the repo
git clone https://github.com/yourusername/Smart-Contract-Analyzer
cd Smart-Contract-Analyzer

# Install Ruby dependencies
bundle install

# Install JavaScript dependencies
npm install

# Setup the database
rails db:create db:migrate db:seed

# Run the app (starts both Rails server and Vite dev server)
bin/dev

Then open http://localhost:3000 πŸŽ‰


πŸ“– Usage Guide

1. Upload a Contract

  • Navigate to the home page
  • Drag and drop a PDF or image file, or click to browse
  • Optionally add a custom question about the contract
  • Click "Analyze Contract" to start the analysis

2. View Analysis Results

  • After upload, you'll be redirected to the analysis page
  • View the overall risk score (0-100, lower = higher risk)
  • Review categorized risks (Critical, Moderate, Low)
  • Read the AI-generated summary

3. Export Reports

  • Click "Export PDF" to download a formatted PDF report
  • Click "Export JSON" to download raw data in JSON format

4. Manage Contracts

  • Click "History" in the navigation to view all contracts
  • Click on any contract to view its analysis
  • Delete contracts you no longer need

5. View Statistics

  • Click "Statistics" in the navigation
  • View overall analytics including:
    • Total contracts analyzed
    • Average risk score
    • Total risks by category

🎯 API Endpoints

Contracts API (/api/v1/contracts)

  • GET /api/v1/contracts - List all contracts
  • POST /api/v1/contracts - Upload and analyze a new contract
  • GET /api/v1/contracts/:id - Get contract details and analysis
  • DELETE /api/v1/contracts/:id - Delete a contract
  • GET /api/v1/contracts/:id/export - Export PDF report
  • GET /api/v1/contracts/:id/export_json - Export JSON data
  • GET /api/v1/contracts/statistics - Get analytics statistics

πŸ”§ Configuration

Environment Variables

⚠️ SECURITY WARNING: Never commit .env files or API keys to version control!

Create a .env file in the root directory with the following variables:

# Required: Gemini API Key for contract analysis
# Get your API key from: https://makersuite.google.com/app/apikey
GEMINI_API_KEY=your_gemini_api_key_here

# Optional: Cloudinary URL for file storage (defaults to local storage in development)
# Format: cloudinary://api_key:api_secret@cloud_name
CLOUDINARY_URL=your_cloudinary_url_here

# Production: Database password
SMART_CONTRACT_ANALYZER_DATABASE_PASSWORD=your_database_password_here

# Production: Rails Master Key (or use config/master.key file)
RAILS_MASTER_KEY=your_master_key_here

The application will automatically load these environment variables. The .env file is already included in .gitignore to prevent accidental commits.

For Production:

  • Use environment variables or Rails encrypted credentials (bin/rails credentials:edit)
  • Never hardcode secrets in your code
  • Ensure config/master.key is never committed (already in .gitignore)

πŸ”’ Security

Security Best Practices

  1. API Keys & Secrets

    • βœ… Never commit .env files or API keys to version control
    • βœ… Use environment variables for all sensitive configuration
    • βœ… Use Rails encrypted credentials for production secrets (bin/rails credentials:edit)
    • βœ… Rotate API keys immediately if exposed
  2. Error Handling

    • βœ… Error messages don't expose sensitive information in production
    • βœ… Sensitive parameters are filtered from logs
  3. File Uploads

    • βœ… File type validation (PDF, JPEG, PNG only)
    • βœ… File size limits (10MB maximum)
    • βœ… File validation at model level
  4. Production Security

    • βœ… SSL/TLS enforced (force_ssl = true)
    • βœ… Master key required for production
    • βœ… Error details hidden in production mode
    • βœ… Parameter filtering configured

Security Checklist for Deployment

  • Set all required environment variables
  • Ensure RAILS_MASTER_KEY is set or config/master.key exists
  • Verify .env is not tracked in git (git ls-files | grep .env)
  • Review and rotate any exposed API keys
  • Enable HTTPS/SSL in production
  • Configure database credentials securely
  • Review file storage configuration (local vs cloud)
  • Set up proper backup strategy for uploaded files

πŸ› οΈ Development

Running Tests

rails test

Code Style

The project follows Ruby and JavaScript best practices. Use standard linting tools.


πŸ“ License

This project is open source and available under the MIT License.


🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


πŸ“§ Support

For issues and questions, please open an issue on GitHub.


About

(In progress)An AI-powered tool that helps Users analyze contracts by automatically summarizing clauses, obligations, and potential risks.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors