# hanoi0126/ai-paper-summarizer architecture

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

- Interactive diagram: https://gitdiagram.com/hanoi0126/ai-paper-summarizer
- Repository: https://github.com/hanoi0126/ai-paper-summarizer

## Overview

The AI Paper Summarizer project is a full-stack application tailored to process research papers and technical documents by summarizing them using LLM-based natural language processing. These summaries are then sent to Slack and saved in a Notion database, making the application an integration of text processing, external service communication, and serverless execution (via AWS Lambda).

##### Project Identification and Core Purpose
- This is an AI-powered summarization tool focused on research papers.
- Primary functions include summarizing documents (using an LLM), sending results through Slack (chat and post interactions), and recording results in a Notion database.
- The presence of a lambda_function.py and GitHub workflows (including lambda_deploy) indicates deployment as a serverless function on AWS Lambda.

##### File Structure and Its Architectural Implications
- Top-level directories/files include configuration (pyproject.toml, requirements.txt, Makefile), CI/CD scripts, and a clean separation between source code (src) and tests.
- The src directory is organized by layer:
- application: Contains the Slack handler, acting as the entry point for Slack messages.
- domain: Holds models and services – this is where core business logic and summarization service sit.
- infrastructure: Implements integration with external systems. It is subdivided into:
▪ file_downloader: Likely for retrieving remote documents.
▪ llm: Contains types, the main LLM integration for summarization, and utility functions.
▪ notion: Manages interaction with Notion’s API.
▪ slack: Manages lower-level Slack integration.
- dependency_injector: Indicates use of dependency injection to manage and decouple component responsibilities.
- The tests directory supports unit testing for validating core logic.

##### Breakdown of Main Components
a. External Clients & Communication:
- Slack: Classify as both an input (paper submission, Q&A messages) and output (summary delivery) channel.
- Notion: Mark as the external service for storing summary results.
- End User: Represent researchers or users interacting via Slack.
b. Application Layer:
- Slack Handler: Acts as the first receiver of Slack messages.
- Lambda Function: Deployment unit indicating serverless execution (likely triggered by Slack events).
c. Domain Layer:
- Summarization Service: Where the business logic for processing paper content takes place, leveraging LLM integration.
- Domain Models: Represent the information structure and summary objects.
d. Infrastructure Layer:
- File Downloader: Retrieves stored or linked document content.
- LLM Module: Handles communication with the large language model and processes tasks such as summarization.
- Slack Module (under infrastructure): Low-level operations for posting messages and handling Slack API interactions.
- Notion Module: Manages API communication with the Notion database.
e. Dependency Management:
- Dependency Injector: Coordinates and provides dependencies for different modules ensuring decoupling.

##### Relationships & Data Flows
- Data enters via Slack (user posts a paper for summarization).
- The Slack handler in the application layer receives the input, and the request flows toward the domain layer service.
- The summarization service calls on the LLM module to generate a summary.
- The result is then routed via the infrastructure layer:
- Sending summary back to Slack for immediate feedback.
- Saving detailed summary data to a Notion database.
- Auxiliary flows include retrieving documents via the file_downloader if needed.
- Deployment and orchestration are managed via AWS Lambda (lambda_function.py) and automated CI/CD workflows via GitHub Actions.

##### Architectural Patterns and Design Principles
- Clear separation of Concerns: Application, Domain, and Infrastructure layers.
- Dependency Injection: Managed by the dependency_injector module which enhances modularity and testability.
- Serverless Architecture: Lambda deployment supports scalability and cost efficiency.
- External API Integration: Both Slack and Notion are integrated as external services with dedicated infrastructure modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    EndUser("Researcher/End User"):::external

    %% Deployment/CI-CD
    GitHubActions("GitHub Actions (CI/CD)"):::cicd
    LambdaFunction("AWS Lambda (lambda_function)"):::deployment

    %% Application Layer
    subgraph "Application Layer"
        SlackHandler("Slack Handler"):::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        SummarizationService("Summarization Service"):::domain
        DomainModels("Domain Models"):::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        FileDownloader("File Downloader"):::infrastructure
        LLMModule("LLM Module"):::infrastructure
        SlackModule("Slack Module"):::infrastructure
        NotionModule("Notion Module"):::infrastructure
    end

    %% Dependency Management
    DependencyInjector("Dependency Injector"):::infrastructure

    %% External Services
    SlackAPI("Slack API"):::external
    NotionAPI("Notion API"):::external

    %% Data Flow Connections
    EndUser -->|"submit_paper"| SlackHandler
    SlackHandler -->|"trigger"| LambdaFunction
    LambdaFunction -->|"invoke"| SlackHandler

    SlackHandler -->|"pass_request"| SummarizationService
    SummarizationService -->|"uses"| DomainModels
    SummarizationService -->|"calls"| LLMModule
    SummarizationService -->|"retrieves_docs"| FileDownloader
    SummarizationService -->|"posts_summary"| SlackModule
    SummarizationService -->|"saves_summary"| NotionModule

    %% Infrastructure External integrations
    SlackModule -->|"communicates_with"| SlackAPI
    NotionModule -->|"communicates_with"| NotionAPI

    %% CI/CD Deployment Flow
    GitHubActions -->|"deploys"| LambdaFunction

    %% Dependency Injection Flow (dotted lines for management)
    DependencyInjector --- SlackHandler
    DependencyInjector --- SummarizationService
    DependencyInjector --- FileDownloader
    DependencyInjector --- LLMModule
    DependencyInjector --- SlackModule
    DependencyInjector --- NotionModule

    %% Click Events
    click SlackHandler "https://github.com/hanoi0126/ai-paper-summarizer/blob/main/src/application/slack_handler.py"
    click LambdaFunction "https://github.com/hanoi0126/ai-paper-summarizer/blob/main/src/lambda_function.py"
    click SummarizationService "https://github.com/hanoi0126/ai-paper-summarizer/blob/main/src/domain/services.py"
    click DomainModels "https://github.com/hanoi0126/ai-paper-summarizer/blob/main/src/domain/models.py"
    click FileDownloader "https://github.com/hanoi0126/ai-paper-summarizer/blob/main/src/infrastructure/file_downloader/file_downloader.py"
    click LLMModule "https://github.com/hanoi0126/ai-paper-summarizer/blob/main/src/infrastructure/llm/llm.py"
    click SlackModule "https://github.com/hanoi0126/ai-paper-summarizer/blob/main/src/infrastructure/slack/slack.py"
    click NotionModule "https://github.com/hanoi0126/ai-paper-summarizer/blob/main/src/infrastructure/notion/notion.py"
    click DependencyInjector "https://github.com/hanoi0126/ai-paper-summarizer/tree/main/src/dependency_injector"

    %% Styles
    classDef application fill:#cce5ff,stroke:#0056b3,stroke-width:2px
    classDef domain fill:#d4edda,stroke:#155724,stroke-width:2px
    classDef infrastructure fill:#fff3cd,stroke:#856404,stroke-width:2px
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px
    classDef deployment fill:#e2e3e5,stroke:#41464b,stroke-width:2px
    classDef cicd fill:#d1ecf1,stroke:#0c5460,stroke-width:2px
```
