Inspiration
LexForge: Full-Stack AI System Documentation
1. Project Overview
LexForge is a full-stack AI-powered system built to handle two critical tasks:
- ⚖️ Contract Analysis (Lawyer Agent)
- 🛠️ Code Debugging & Fixing (Coding Agent) What makes it different is not the features, but the privacy-first pipeline. Data is sanitized before it ever touches AI. ## 2. Technology Stack ### 🌐 Frontend
- HTML → Structure
- CSS → Styling & themes
- JavaScript → Logic + API calls ### ⚙️ Backend
- FastAPI (Python)
- Async request handling
- File upload system ### 🤖 AI Engine
- Gemini Flash Lite ### 🛠️ Supporting Systems
- PyPDF2 → PDF extraction
- Redaction Engine → Privacy layer
- Workspace Storage → File handling ## 3. System Architecture Frontend (Browser UI) ↓ HTTP Requests (Fetch API) ↓ FastAPI Backend ↓ ↙ ↘ Lawyer Agent | Coding Agent ↘ ↙ Gemini API ↓ Response Processing ↓ Frontend Rendering ## 4. Frontend Design ### Core Layout
- Sidebar → Mode selection
- Topbar → Tabs + model status
- Workspace → Dynamic UI
- Right Panel → Info + explanation ### Lawyer Mode Flow Upload contract → Processing → Redaction → Results You see:
- 📊 Risk Scorecard
- 🃏 Risk Cards (High / Medium / Low)
- 💡 Fix Suggestions ### Code Mode Flow Upload code → AI Processing → Logs → Output Logs simulate:
- 📤 Sending to AI...
- 🔍 Analyzing code...
- ✅ Fix applied...
- 💾 Saved file.py ### Key Features
- switchMode() → instant UI switching
- Configurable backend URL (localStorage)
- API Calls: /analyze-contract and /fix-code
- ⚠️ Error display system
- 📜 Real-time log simulation ## 5. Backend System ### Framework
- FastAPI
- Async endpoints
- File handling ### Endpoints
- /analyze-contract: Upload file, extract text, apply redaction, AI analysis, return structured output.
- /fix-code: Upload code, send to AI, parse result, save file, return preview. ## 6. File Processing ### PDF Extraction
- PyPDF2: Reads all pages and combines into text. ### Upload Rules
- Max size: 5MB
- Formats (Lawyer): PDF, TXT
- Formats (Code): .py, .js, .cpp, .java, .txt ## 7. Privacy Layer (Core Strength) ### Redaction Pipeline Raw Text → redact_text() → PII Removed → Gemini API → restore_text_deep() → Original Restored ### ☑️ Removed Data
- 👤 Names
- 📞 Phone numbers
- 📧 Emails
- 🏦 IBAN
- 📍 Locations AI never sees real user data. That's the whole point. ## 8. AI Integration
- Model: Gemini Flash Lite
- Call Flow: generate_content()
- Retry System: 3 attempts
- Handles: 429 (rate limit) with exponential backoff
- Failure: 503 not handled → breaks system ## 9. Lawyer Agent
- Input: Contract text
- Output: JSON object with score, risks, and fixes.
- Features: Risk scoring, clause detection, severity tagging.
- UI Mapping: Score color, risks cards, fixes → suggestions. ## 10. Coding Agent
- Input: Raw code
- Expected Output: JSON with action: "write", filename, and content.
- Processing Flow: AI Response → clean_json() → json.loads() → write_to_disk().
- Safety: Prevents path traversal and protects critical files.
- Response: Status: "saved", file path, and first 300 chars preview. ## 11. Error System
- Backend Errors: Invalid file, file too large, empty file, AI failure.
- AI Errors: ☑ 429 handled | ☑ 503 not handled
- Frontend Errors: Displayed via UI alerts ## 12. Data Flow
- Code Agent: Upload → /fix-code → Backend → AI → Parse → Save → UI
- Lawyer Agent: Upload → Extract → Redact → AI → Restore → UI ## 13. Strengths
- 🛡️ Privacy-first design
- 🧩 Modular agents
- ✨ Clean UI
- 🔒 Secure file handling
- 🌍 Real-world usability
- 📈 Easily extendable ## 14. Conclusion LexForge is not just a basic AI tool. It's a structured multi-agent system combining legal intelligence and code debugging with a privacy-focused pipeline. ### Final Summary LexForge = Privacy-first AI system that analyzes contracts and fixes code using a FastAPI backend, Gemini AI, and a dynamic frontend UI. ₹ ## What it does
How we built it
Challenges we ran into
Accomplishments that we're proud of
What we learned
What's next for LexForge
Built With
- css
- fastapi
- gemini
- html5
- javascript
- presidio
- python
Log in or sign up for Devpost to join the conversation.