# sudeepbogati7/threat-news-summarizer architecture

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

- Interactive diagram: https://gitdiagram.com/sudeepbogati7/threat-news-summarizer
- Repository: https://github.com/sudeepbogati7/threat-news-summarizer

## Overview

##### Project type and purpose
- This is a full-stack AI-powered chatbot application (“DeepCyberQ”) for querying recent cyber threats and news using RAG (Retrieval-Augmented Generation) and LangChain, with a FastAPI backend and a Next.js frontend.

##### File structure
- Top level:
- main.py – entrypoint for FastAPI
- news.db – SQLite DB for persisting news and user info
- src/api – FastAPI routers and endpoints (auth.py, news.py)
- src/core – configuration (config.py) and security (JWT, password hashing)
- src/database – database connection and session management
- src/middleware – request/response logging
- src/models & src/schemas – ORM models + Pydantic schemas for User and News
- src/services – business logic: news_fetcher (ingest/fetch news), rag (build and query vector store via LangChain)
- src/utils – custom exceptions

##### Key README insights
- Tech Stack: FastAPI, LangChain, RAG, Next.js
- Features: user registration/authentication, news browsing, chat interface that embeds RAG + LLM

##### Main components
a. Frontend (Next.js SPA)
b. API Gateway / Web Server (FastAPI)
- Middleware layer (logging)
- Auth module (core/security)
- Routers & endpoints (src/api)
c. Business Logic / Services
- NewsFetcher – retrieves, normalizes, and persists news into SQLite
- RAG service – builds vector store, invokes LLM via LangChain
d. Database (SQLite: news.db)
e. External services
- LLM provider (e.g. OpenAI)
- External News APIs or scrapers

##### Relationships & Data Flows
- User → (HTTPS) → Next.js UI
- Next.js → (HTTPS/API) → FastAPI
- Auth endpoints issue JWTs via core/security
- Chat endpoints call services/rag → LangChain → external LLM → response
- News endpoints call services/news_fetcher → database
- FastAPI ←→ SQLite (via src/database/db.py + ORM models)
- FastAPI → external News APIs when news_fetcher ingests data
- FastAPI → external LLM API via LangChain wrapper

##### Architectural patterns & principles
- Layered architecture:
- Presentation (frontend)
- API layer (routers + middleware)
- Service layer (business logic)
- Data access layer (ORM + database)
- Separation of concerns: auth, config, logging abstracted into core & middleware
- RAG pattern: retrieval store + LLM for dynamic answer generation

##### Final recommendations
- Be detailed: represent each subcomponent (middleware, routers, services).
- Data-flow: authentication handshake, RAG query pipeline, DB reads/writes.
- Don’t overthink: break the system into all logical pieces and show how they connect.
- Use sequence or flow annotations (e.g., 1: login, 2: fetch news, 3: chat query).
- It’s easy to follow for stakeholders and for onboarding new engineers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend" 
        direction TB
        NextJS["Next.js UI"]:::ui
    end

    %% Backend Layer
    subgraph "Backend (FastAPI)" 
        direction TB

        %% API Layer
        subgraph "API Layer"
            direction TB
            FastAPI["FastAPI App\n(main.py)"]:::api
            Logging["Request/Response Logging"]:::api
            RouterReg["Router Registration"]:::api
            AuthEP["Auth Endpoints"]:::api
            NewsEP["News Endpoints"]:::api
        end

        %% Core Configuration & Security
        subgraph "Core / Security"
            direction TB
            Config["Configuration\n(config.py)"]:::api
            Security["Security (JWT, Hash)"]:::api
        end

        %% Service Layer
        subgraph "Service Layer"
            direction TB
            NewsFetcher["NewsFetcher Service"]:::service
            RAGService["RAG Service"]:::service
        end

        %% Data Layer
        subgraph "Data Layer"
            direction TB
            DBConn["DB Connection & Session\n(db.py)"]:::data
            SQLiteDB["SQLite Database\n(news.db)"]:::data
            subgraph "Models & Schemas"
                direction TB
                UserModel["User Model"]:::data
                NewsModel["News Model"]:::data
                UserSchema["User Schemas"]:::data
                NewsSchema["News Schemas"]:::data
            end
        end
    end

    %% External Services
    subgraph "External Services"
        direction TB
        NewsAPI["External News APIs"]:::external
        LLM["LLM Provider (OpenAI)"]:::external
    end

    %% Connections
    NextJS -->|"HTTPS/API"| FastAPI
    FastAPI -->|uses| Logging
    FastAPI -->|registers| RouterReg
    RouterReg -->|includes| AuthEP
    RouterReg -->|includes| NewsEP
    FastAPI -->|loads| Config
    FastAPI -->|loads| Security

    AuthEP -->|JWT Auth| Security
    NewsEP -->|calls| NewsFetcher
    NewsEP -->|calls| DBConn
    NewsEP -->|reads/writes| SQLiteDB

    NewsFetcher -->|ingest| NewsAPI
    NewsFetcher -->|persist| DBConn
    DBConn -->|ORM| UserModel
    DBConn -->|ORM| NewsModel
    NewsModel -->|validate| NewsSchema
    UserModel -->|validate| UserSchema

    AuthEP -->|validate| DBConn
    AuthEP -->|validate| UserModel
    AuthEP -->|validate| UserSchema

    RAGService -->|retrieve| DBConn
    RAGService -->|invoke| LLM
    RAGService -->|vector store| NewsModel

    FastAPI -->|routes chat| RAGService

    %% Click Events
    click FastAPI "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/main.py"
    click Logging "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/src/middleware/logging.py"
    click RouterReg "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/src/api/routers.py"
    click AuthEP "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/src/api/endpoints/auth.py"
    click NewsEP "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/src/api/endpoints/news.py"
    click Config "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/src/core/config.py"
    click Security "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/src/core/security.py"
    click DBConn "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/src/database/db.py"
    click SQLiteDB "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/news.db"
    click UserModel "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/src/models/user.py"
    click NewsModel "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/src/models/news.py"
    click UserSchema "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/src/schemas/user.py"
    click NewsSchema "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/src/schemas/news.py"
    click NewsFetcher "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/src/services/news_fetcher.py"
    click RAGService "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/src/services/rag.py"
    click Exceptions "https://github.com/sudeepbogati7/threat-news-summarizer/blob/main/src/utils/exceptions.py"

    %% Styles
    classDef ui fill:#e0f7e9,stroke:#2e7d32,stroke-width:2px
    classDef api fill:#bbdefb,stroke:#1e88e5,stroke-width:2px
    classDef service fill:#90caf9,stroke:#1565c0,stroke-width:2px
    classDef data fill:#ffe0b2,stroke:#ef6c00,stroke-width:2px
    classDef external fill:#e1bee7,stroke:#6a1b9a,stroke-width:2px
```
