How rohan111427/suits-legal works
Project Type & Purpose
• This is a full-stack AI-powered legal document analysis and chat application (“Suits AI”).
• Frontend: Jinja2 HTML/CSS/JS templates (with Tailwind CSS).
• Backend: FastAPI (Python) providing page routes and JSON APIs.
• Database: SQLite via SQLAlchemy ORM.
• AI services: Local BART summarization, Tesseract OCR, PyMuPDF for text extraction, Google Gemini API for advanced analysis and chat.
File-Structure Analysis
• Top level:
• main.py – FastAPI app entrypoint
• run.py/run_system.py/start.sh – startup scripts
• Dockerfile – container build
• requirements.txt & .env.example – dependencies & config
• download_model.py – BART model pre‐download
• Directories:
• frontend/templates – server-side rendered HTML pages & JS/CSS assets
• static – custom CSS/images
• models – database schema (database.py)
• utils – business logic layers (auth.py, text_extraction.py, ai_services.py)
• Patterns:
• MVC-style separation: templates (view), utils/models (controller/model), main.py routes (controller).
• Monolith with distinct layers, not microservices.
Key README Insights
• User flows: register/login → upload documents → automatic extraction & AI analysis → interactive chat.
• Endpoints: HTML routes and RESTful JSON POSTs for upload, chat, new-chat.
• DB schema: Users, Documents, Chat Sessions, Chat History.
• Deployment options: local, Docker, Hugging Face Spaces.
a. Main Components
• Client Browser (desktop/mobile)
• Frontend Server (FastAPI + Jinja2)
• Static Assets (CSS/JS)
• Database (SQLite)
• Text-Extraction Module (PyMuPDF, Tesseract)
• Summarization Service (BART model)
• AI Chat Service (Gemini API)
• Authentication Service (JWT/session cookies)
b. Relationships & Interactions
1. User ↔ Browser: HTTP GET/POST requests
2. Browser → FastAPI: serve templates or AJAX calls (/upload, /chat)
3. FastAPI → Database: SQLAlchemy ORM CRUD
4. FastAPI → Text-Extraction Module → raw_text
5. FastAPI → BART summarization → summary
6. FastAPI → Gemini API → structured_json & chat replies
7. FastAPI → Browser: render pages or JSON responses
c. Architectural Patterns & Principles
• Layered architecture: Presentation (templates/static), Application (FastAPI routes), Domain/Business (utils modules), Persistence (models/database).
• Dependency injection in FastAPI for database sessions, config.
• Session-based security: JWT in cookies, CSRF protection.
• Modular AI wrappers for plug-and-play service integration.
d. Technologies & Frameworks
• FastAPI, Uvicorn/Gunicorn (ASGI server)
• Jinja2 templating, Tailwind CSS, vanilla JS
• SQLite + SQLAlchemy
• PyMuPDF, Tesseract OCR
• Transformers (facebook/bart-large-cnn)
• Google Gemini API