# rohan111427/suits-legal architecture

> Architecture diagram of the GitHub repository rohan111427/suits-legal, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rohan111427/suits-legal
- Repository: https://github.com/rohan111427/suits-legal

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["Client Browser"]:::client
        Templates["Jinja2 Templates"]:::internal
        StaticAssets["Static Assets (CSS/JS)"]:::internal
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        FastAPI["FastAPI App<br/>(main.py)"]:::internal
        Startup["Startup Scripts"]:::internal
        DockerfileNode["Dockerfile"]:::internal
        Env[".env.example"]:::internal
        Req["requirements.txt"]:::internal
        DownloadModel["download_model.py"]:::internal
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        AuthMod["Authentication Module<br/>(utils/auth.py)"]:::internal
        TextExt["Text-Extraction Module<br/>(utils/text_extraction.py)"]:::internal
        AISvc["AI Services Module<br/>(utils/ai_services.py)"]:::internal
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        ModelsDB["SQLite Database<br/>(models/database.py)"]:::persistence
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Gemini["Google Gemini API"]:::external
        Tesseract["Tesseract OCR"]:::external
        PyMuPDF["PyMuPDF"]:::external
    end

    %% Interactions
    Browser -->|"HTTP GET/POST"| FastAPI
    FastAPI -->|render| Templates
    FastAPI -->|serve| StaticAssets
    FastAPI -->|"ORM CRUD"| ModelsDB
    FastAPI -->|authenticate| AuthMod
    FastAPI -->|extract text| TextExt
    TextExt -->|uses| PyMuPDF
    TextExt -->|uses| Tesseract
    FastAPI -->|summarize| AISvc
    AISvc -->|BART model| DownloadModel
    AISvc -->|chat| Gemini
    FastAPI -->|response| Browser

    %% Startup and Deployment
    Startup -->|start app| FastAPI
    DockerfileNode -->|build container| FastAPI
    Env -->|config| FastAPI
    Req -->|deps| FastAPI
    DownloadModel -->|pre-download| AISvc

    %% Click Events
    click FastAPI "https://github.com/rohan111427/suits-legal/blob/main/main.py"
    click Startup "https://github.com/rohan111427/suits-legal/blob/main/run.py"
    click Startup "https://github.com/rohan111427/suits-legal/blob/main/run_system.py"
    click Startup "https://github.com/rohan111427/suits-legal/blob/main/start.sh"
    click DockerfileNode "https://github.com/rohan111427/suits-legal/tree/main/Dockerfile"
    click Env "https://github.com/rohan111427/suits-legal/blob/main/.env.example"
    click Req "https://github.com/rohan111427/suits-legal/blob/main/requirements.txt"
    click Templates "https://github.com/rohan111427/suits-legal/tree/main/frontend/templates/"
    click StaticAssets "https://github.com/rohan111427/suits-legal/blob/main/static/css/style.css"
    click StaticAssets "https://github.com/rohan111427/suits-legal/tree/main/static/images/"
    click ModelsDB "https://github.com/rohan111427/suits-legal/blob/main/models/database.py"
    click AuthMod "https://github.com/rohan111427/suits-legal/blob/main/utils/auth.py"
    click TextExt "https://github.com/rohan111427/suits-legal/blob/main/utils/text_extraction.py"
    click AISvc "https://github.com/rohan111427/suits-legal/blob/main/utils/ai_services.py"
    click DownloadModel "https://github.com/rohan111427/suits-legal/blob/main/download_model.py"

    %% Styles
    classDef client fill:#e2e8f0,stroke:#1e40af,color:#1e40af,stroke-width:2px
    classDef internal fill:#d1fae5,stroke:#166534,color:#166534,stroke-width:2px
    classDef persistence fill:#fef3c7,stroke:#92400e,color:#92400e,stroke-width:2px
    classDef external fill:#dbeafe,stroke:#1e3a8a,color:#1e3a8a,stroke-width:2px
```
