Skip to content

Prcentos/studio

Repository files navigation

ContractWise - AI-Powered Contract Analysis Platform

ContractWise is a modern, full-stack web application built with Next.js, Genkit, and Google's Gemini AI. It provides an intelligent solution for analyzing legal contracts, identifying potential risks, and suggesting optimized terms for all parties involved.

Core Features

  • AI-Powered Risk Assessment: Leverages Google's Gemini model via Genkit to perform deep analysis of contract text, identifying risks across financial, legal, technical, and risk management domains.
  • Dual-Party Reporting: Generates distinct, comprehensive reports tailored for both parties (甲方 and 乙方), fostering fairer negotiations.
  • Interactive Term Optimization: Provides AI-generated suggestions for improving clauses, complete with explanations. Users can edit these suggestions directly in the UI.
  • Smart Document Handling: Supports .pdf, .docx, .txt, and .md file uploads. Includes a pre-check to ensure the uploaded document is a valid contract before performing a full analysis.
  • Multi-Language Support: Fully localized for both English and Chinese (中文), including UI and AI-generated report content.
  • Professional PDF Downloads: Users can download the detailed analysis reports as professionally formatted PDF files, ready for printing or sharing.

Tech Stack

Getting Started

Prerequisites

  • Node.js (v18 or later recommended)
  • npm, yarn, or pnpm

Setup

  1. Clone the repository:

    git clone <repository-url>
    cd <repository-name>
  2. Install dependencies:

    npm install
    # or
    # yarn install
    # or
    # pnpm install
  3. Set up environment variables: Create a .env file in the root of the project and add your Google Gemini API key:

    GEMINI_API_KEY="YOUR_GEMINI_API_KEY"
    

    You can obtain a key from Google AI Studio.

Running the Development Server

The application requires two separate processes to run concurrently: the Next.js frontend and the Genkit AI flows.

  1. Run the Next.js app: Open a terminal and run:

    npm run dev

    This will start the frontend on http://localhost:9002.

  2. Run the Genkit flows: Open a second terminal and run:

    npm run genkit:watch

    This starts the Genkit development server, which watches for changes in your AI flows. The Next.js app will communicate with this server for all AI-related tasks.

Now, you can open http://localhost:9002 in your browser to see the application.

Project Structure

.
├── src
│   ├── ai                  # Genkit AI core
│   │   ├── flows           # All Genkit flow definitions
│   │   ├── genkit.ts       # Genkit initialization and configuration
│   │   └── dev.ts          # Entry point for Genkit dev server
│   ├── app                 # Next.js App Router
│   │   ├── (pages)         # Route groups for pages
│   │   ├── actions.ts      # Server Actions for backend logic
│   │   ├── globals.css     # Global styles and Tailwind directives
│   │   └── layout.tsx      # Root layout
│   ├── components          # Reusable React components
│   │   ├── ui              # ShadCN/UI components
│   │   └── ...
│   ├── context             # React Context providers
│   ├── hooks               # Custom React hooks
│   ├── lib                 # Utility functions and libraries
│   └── locales             # Translation files (en.json, zh.json)
├── public                  # Static assets
└── ...                     # Config files (next.config.ts, tailwind.config.ts, etc.)

How It Works

  1. File Upload: The user uploads a contract document on the homepage (src/app/page.tsx).
  2. Pre-check: A Server Action (checkIfContract in src/app/actions.ts) sends the first ~2000 characters of the document to the isContractDocument Genkit flow. This is a quick, cheap way to validate the file.
  3. Full Analysis: If the file is a valid contract, the user can click "Analyze." This triggers the analyzeContractFromFile Server Action, which extracts the full text and runs three Genkit flows in parallel:
    • analyzeContractRisks: Finds risks for both parties.
    • suggestBetterContractTerms (for 甲方): Suggests improvements for Party A.
    • suggestBetterContractTerms (for 乙方): Suggests improvements for Party B.
  4. Display Results: The analysis results are stored in sessionStorage and the user is redirected to the /report page.
  5. Report Generation: On the report page, the user can click "Download Report." This calls the generateHtmlReport Server Action, which uses the generateReport Genkit flow to create a professional HTML report. This HTML is then converted to a PDF on the client-side using jspdf and html2canvas.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages