# limwualice/document-summarizer architecture

> Architecture diagram of the GitHub repository limwualice/document-summarizer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/limwualice/document-summarizer
- Repository: https://github.com/limwualice/document-summarizer

## Overview

##### Project type and purpose
- This is a lightweight full-stack web application (Flask) that exposes an HTTP API and HTML UI for summarizing documents.
- It acts as an API service and simple web front-end that delegates summarization to the external OpenAI GPT-3.5 endpoint.

##### File structure
- app.py – single Flask application entry point, defines routes and ties everything together
- requirements.txt – Python dependencies (Flask, openai, any rate-limiting library)
- templates/ – Jinja2 HTML templates (index.html for input form, result.html for summary output)
- venv/ – local virtual environment (isolates dependencies)
- .gitignore – excludes venv, __pycache__, etc.
There are no database layers, microservices, or build scripts; this is one monolithic service.

##### README for additional insights
- Summarization is done by calling OpenAI’s GPT-3.5 “text completion” API.
- The `/process` endpoint accepts JSON `{ "text": "…" }` and returns the summary.
- The app must handle rate-limit responses from OpenAI and retry or back off.

##### Main components
a. Client Tier
– Web Browser (user)
– cURL/HTTP client (for programmatic API access)
b. Web Server Tier
– Flask Application (app.py)
- Controller / Routes: `GET /` → index.html, `POST /process` → processes input
- Service Layer:
– SummarizationService (wraps OpenAI client, handles retries/rate-limit)
- Configuration Module (reads `OPENAI_API_KEY` env var)
c. Presentation Tier
– Jinja2 Templates (templates/index.html, templates/result.html)
d. External Services
– OpenAI GPT-3.5 API (cloud service)
e. Environment / Deployment
– Virtual Environment (venv)
– Environment Variables (OPENAI_API_KEY)

##### Relationships and interactions
1. User opens browser → HTTP GET → Flask `/` route → returns index.html
2. User inputs text & submits → HTTP POST `/process` → Flask Controller
3. Controller calls SummarizationService → invokes OpenAI API over HTTPS
4. OpenAI returns summary → Service handles rate-limit or errors → returns summary
5. Controller renders result.html (or JSON) → HTTP response to client

##### Architectural patterns / design principles
- MVC-style separation: Controllers (routes) vs. Views (templates) vs. Services (SummarizationService)
- Single Responsibility: each module does one job (routing, templating, API calls)
- External dependency encapsulation: wrapping OpenAI calls in a dedicated service layer
- Environment-driven configuration: secrets and rate-limit parameters come from env vars

##### Detail without over-complicating
- HTTP endpoints, configuration sources, and external dependencies.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Tier
    subgraph "Client Tier"
        direction TB
        Browser["Web Browser"]:::client
        HTTPClient["cURL/HTTP Client"]:::client
    end

    %% Flask Application
    subgraph "Flask Application"
        direction TB
        Routes["Controllers/Routes\nGET /, POST /process"]:::internal
        Service["SummarizationService\n(rate-limit, retries)"]:::internal
        Config["Configuration Module\n(env var handling)"]:::internal
        subgraph "Jinja2 Templates"
            direction TB
            TemplatesIndex["templates/index.html"]:::templates
            TemplatesResult["templates/result.html"]:::templates
        end
    end

    %% External Service
    OpenAICloud["OpenAI GPT-3.5 API"]:::external

    %% Deployment Artifacts
    subgraph "Environment / Deployment"
        direction TB
        Venv["venv/"]:::deployment
        EnvVars["Environment Variables\n(OPENAI_API_KEY)"]:::deployment
    end

    %% Data Flow
    Browser -->|"HTTP GET /"| Routes
    HTTPClient -->|"HTTP GET/POST"| Routes
    Routes -->|"invoke"| Service
    Service -->|"HTTPS call"| OpenAICloud
    OpenAICloud -->|"summary response"| Service
    Service -->|"return summary"| Routes
    Routes -->|"render result"| TemplatesResult
    Routes -->|"HTTP response"| Browser

    %% Deployment connections
    Venv -.-> Routes
    EnvVars -.-> Config

    %% Click Events
    click Routes "https://github.com/limwualice/document-summarizer/blob/main/app.py"
    click Service "https://github.com/limwualice/document-summarizer/blob/main/app.py"
    click Config "https://github.com/limwualice/document-summarizer/blob/main/app.py"
    click TemplatesIndex "https://github.com/limwualice/document-summarizer/blob/main/templates/index.html"
    click TemplatesResult "https://github.com/limwualice/document-summarizer/blob/main/templates/result.html"
    click Venv "https://github.com/limwualice/document-summarizer/tree/main/venv/"
    click EnvVars "https://github.com/limwualice/document-summarizer/blob/main/.gitignore"
    click Requirements "https://github.com/limwualice/document-summarizer/blob/main/requirements.txt"
    click README "https://github.com/limwualice/document-summarizer/blob/main/README.md"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef internal fill:#E0FFFF,stroke:#333,stroke-width:1px
    classDef templates fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#90EE90,stroke:#333,stroke-width:1px
    classDef deployment fill:#D3D3D3,stroke:#333,stroke-width:1px
```
