# ossamalouati/legal-ai_project architecture

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

- Interactive diagram: https://gitdiagram.com/ossamalouati/legal-ai_project
- Repository: https://github.com/ossamalouati/legal-ai_project

## Overview

##### Project type and purpose
- Full-stack web application for automated legal document analysis.
- Frontend: Next.js/TypeScript web app (UI, authentication, API proxy).
- Backend: Flask server (machine-learning inference, NLP pipelines, data files).

##### Main components
a. User & Browser
b. Frontend Service (“web_app” container)
– Next.js server (Node.js + React + TypeScript)
– NextAuth authentication module
– Pages & API routes (pages/api/*)
– Static assets (public/assets)
c. Backend Service (“flask_server” container)
– Flask web server (app.py)
– ML modules:
- predict.py (reading comprehension, SQuAD-based QA)
- paraphrase.py (T5-based paraphrasing)
- sentiment analysis (TextBlob)
– Data store (flat files: contracts, questions, responses.json, nbest.json)
d. Container orchestration
– Docker Compose (docker-compose.yml)
e. External resources (optionally highlight datasets/ML models on Hugging Face, SQuAD, CUAD)

##### Relationships & data flows
- Users ↔ Browser → HTTP/HTTPS → Next.js Frontend
- Frontend (API routes) → HTTP → Flask server endpoints (e.g., /predict, /paraphrase)
- Flask server → local data files & ML modules → compute inferences → returns JSON → Frontend
- Frontend → renders results + charts/summary → Browser
- Docker Compose → orchestrates two containers + shared network

##### Architectural patterns & design principles
- Client-Server separation (UI vs. ML backend)
- Microservice-style split (two independently containerized services)
- Layered architecture: Presentation (Next.js), Application (Flask APIs), Data/ML layer
- Use of containerization for environment parity

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User / Browser"]:::external

    subgraph "Docker Compose"
        Compose["Docker Compose"]:::orchestration

        subgraph "web_app"
            NextJS["Next.js Server"]:::frontend
            Auth["NextAuth Module"]:::frontend
            API["API Routes (pages/api/)"]:::frontend
            UI["Pages UI (pages/*.tsx)"]:::frontend
            Assets["Static Assets"]:::frontend
            FDocker["Dockerfile"]:::orchestration
            FPackage["package.json"]:::frontend
        end

        subgraph "flask_server"
            Flask["Flask App (app.py)"]:::backend
            Predict["Predict Module"]:::ML
            Paraphrase["Paraphrase Module"]:::ML
            Sentiment["Sentiment Analysis"]:::ML
            DataStore["Data Store (data/)"]:::data
            JSONFiles["Responses & Candidates JSON"]:::data
            BDocker["Dockerfile"]:::orchestration
            Requirements["requirements.txt"]:::backend
        end
    end

    User -->|"HTTP GET/POST"| NextJS
    NextJS -->|"Auth Flow"| Auth
    NextJS -->|"API call: /predict, /paraphrase"| API
    API -->|"HTTP/REST"| Flask
    Flask -->|"reads data files"| DataStore
    Flask -->|"reads/writes JSON"| JSONFiles
    Flask -->|"calls"| Predict
    Flask -->|"calls"| Paraphrase
    Flask -->|"calls"| Sentiment
    Flask -->|"JSON response"| NextJS
    NextJS -->|"renders UI"| User

    click Compose "https://github.com/ossamalouati/legal-ai_project/blob/main/docker-compose.yml"
    click NextJS "https://github.com/ossamalouati/legal-ai_project/tree/main/web_app/pages/"
    click Auth "https://github.com/ossamalouati/legal-ai_project/blob/main/web_app/pages/api/auth/[...nextauth].ts"
    click API "https://github.com/ossamalouati/legal-ai_project/tree/main/web_app/pages/api/"
    click UI "https://github.com/ossamalouati/legal-ai_project/tree/main/web_app/pages/"
    click Assets "https://github.com/ossamalouati/legal-ai_project/tree/main/web_app/public/assets/"
    click FDocker "https://github.com/ossamalouati/legal-ai_project/tree/main/web_app/Dockerfile"
    click FPackage "https://github.com/ossamalouati/legal-ai_project/blob/main/web_app/package.json"
    click Flask "https://github.com/ossamalouati/legal-ai_project/blob/main/flask_server/app.py"
    click Predict "https://github.com/ossamalouati/legal-ai_project/blob/main/flask_server/predict.py"
    click Paraphrase "https://github.com/ossamalouati/legal-ai_project/blob/main/flask_server/paraphrase.py"
    click Sentiment "https://github.com/ossamalouati/legal-ai_project/blob/main/flask_server/app.py"
    click DataStore "https://github.com/ossamalouati/legal-ai_project/tree/main/flask_server/data/"
    click JSONFiles "https://github.com/ossamalouati/legal-ai_project/blob/main/flask_server/responses.json"
    click JSONFiles "https://github.com/ossamalouati/legal-ai_project/blob/main/flask_server/nbest.json"
    click BDocker "https://github.com/ossamalouati/legal-ai_project/tree/main/flask_server/Dockerfile"
    click Requirements "https://github.com/ossamalouati/legal-ai_project/blob/main/flask_server/requirements.txt"

    classDef external fill:#cccccc,stroke:#888888,color:#333333;
    classDef frontend fill:#cce5ff,stroke:#66b0ff,color:#004085;
    classDef backend fill:#d4edda,stroke:#8fd19e,color:#155724;
    classDef ML fill:#fff3cd,stroke:#ffe08a,color:#856404;
    classDef data fill:#ffe5b4,stroke:#ffcc80,color:#804000;
    classDef orchestration fill:#e2e3e5,stroke:#bcbabe,color:#41464b;
```
