# oreo1906/news-article-categorization architecture

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

- Interactive diagram: https://gitdiagram.com/oreo1906/news-article-categorization
- Repository: https://github.com/oreo1906/news-article-categorization

## Overview

SmartNews AI Backend is a FastAPI service for analyzing news articles. A client submits article text to the analysis endpoint, which validates the request and delegates to a shared analyzer; the analyzer returns a category and confidence alongside a headline, summary, key points, keywords, reading-time estimate, and sentiment. Classification uses a shared Hugging Face model, while the other analysis stages use dedicated services. The repository also includes health checks and centralized error responses. Edges reflect shown calls or registrations; the reading-time service connection is supported by the analyzer’s indexed references, though its implementation was not excerpted.

Main entry points: [`backend/app/main.py`](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/main.py) (FastAPI app), [`backend/app/services/analyzer.py`](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/services/analyzer.py) (Article analyzer), [`backend/app/routers/analyze.py`](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/routers/analyze.py) (Analyze endpoint), [`backend/app/core/model_loader.py`](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/core/model_loader.py) (Model loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API layer"]
  node_app["FastAPI app<br/>[main.py]"]
  node_analyze["Analyze endpoint<br/>[analyze.py]"]
  node_health["Health endpoint<br/>[health.py]"]
  node_request["Request schema<br/>[request_models.py]"]
  node_response["Response schema<br/>[response_models.py]"]
  node_errors["Error handlers<br/>[exceptions.py]"]
end

subgraph group_analysis["Analysis services"]
  node_analyzer["Article analyzer<br/>[analyzer.py]"]
  node_summarizer["Text summarizer<br/>[summarizer.py]"]
  node_keywords["Keyword extractor<br/>[extractor.py]"]
  node_sentiment["Sentiment analyzer<br/>[sentiment.py]"]
  node_reading_time["Reading-time estimator<br/>[reading_time.py]"]
end

subgraph group_model["Model inference"]
  node_classifier["News classifier<br/>[classifier.py]"]
  node_model_loader["Model loader<br/>[model_loader.py]"]
  node_model_assets["Classifier assets"]
end

subgraph group_runtime["Runtime support"]
  node_dependencies["Service dependency<br/>[dependencies.py]"]
  node_settings["Settings<br/>[settings.py]"]
  node_resources["Resource monitor<br/>[resource_usage.py]"]
  node_logger["Application logger<br/>[logger.py]"]
end

node_client(("API client"))

node_client -->|"submits text"| node_analyze
node_app -->|"registers route"| node_analyze
node_app -->|"registers route"| node_health
node_app -->|"registers handlers"| node_errors
node_app -->|"loads analyzer"| node_dependencies
node_app -->|"configures app"| node_settings
node_app -->|"logs lifecycle"| node_logger
node_app -->|"logs memory"| node_resources
node_analyze -->|"validates input"| node_request
node_analyze -->|"returns payload"| node_response
node_analyze -->|"gets analyzer"| node_dependencies
node_dependencies -->|"creates singleton"| node_analyzer
node_analyze -->|"invokes analysis"| node_analyzer
node_analyzer -->|"classifies text"| node_classifier
node_analyzer -->|"generates text outputs"| node_summarizer
node_analyzer -->|"extracts keywords"| node_keywords
node_analyzer -->|"analyzes sentiment"| node_sentiment
node_analyzer -->|"estimates reading time"| node_reading_time
node_classifier -->|"gets model and tokenizer"| node_model_loader
node_classifier -->|"uses inference settings"| node_settings
node_classifier -->|"logs memory"| node_resources
node_model_loader -->|"loads configured assets"| node_model_assets
node_model_loader -->|"reads model configuration"| node_settings
node_model_loader -->|"logs memory"| node_resources
node_health -->|"reports configuration"| node_settings
node_health -->|"checks model status"| node_model_loader

click node_app "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/main.py"
click node_analyze "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/routers/analyze.py"
click node_health "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/routers/health.py"
click node_request "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/models/request_models.py"
click node_response "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/models/response_models.py"
click node_errors "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/core/exceptions.py"
click node_dependencies "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/core/dependencies.py"
click node_analyzer "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/services/analyzer.py"
click node_classifier "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/services/classification/classifier.py"
click node_model_loader "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/core/model_loader.py"
click node_model_assets "https://github.com/oreo1906/news-article-categorization/tree/main/backend/news_classifier"
click node_summarizer "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/services/summarization/summarizer.py"
click node_keywords "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/services/keywords/extractor.py"
click node_sentiment "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/services/sentiment/sentiment.py"
click node_reading_time "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/services/reading_time.py"
click node_settings "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/config/settings.py"
click node_resources "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/utils/resource_usage.py"
click node_logger "https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/utils/logger.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_analyze,node_health,node_request,node_response,node_errors,node_client toneBlue
class node_analyzer,node_summarizer,node_keywords,node_sentiment,node_reading_time toneAmber
class node_classifier,node_model_loader,node_model_assets toneMint
class node_dependencies,node_settings,node_resources,node_logger toneRose
```

## Components

### API layer

- [FastAPI app](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/main.py): `backend/app/main.py`
- [Analyze endpoint](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/routers/analyze.py): `backend/app/routers/analyze.py`
- [Health endpoint](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/routers/health.py): `backend/app/routers/health.py`
- [Request schema](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/models/request_models.py): `backend/app/models/request_models.py`
- [Response schema](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/models/response_models.py): `backend/app/models/response_models.py`
- [Error handlers](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/core/exceptions.py): `backend/app/core/exceptions.py`

### Analysis services

- [Article analyzer](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/services/analyzer.py): `backend/app/services/analyzer.py`
- [Text summarizer](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/services/summarization/summarizer.py): `backend/app/services/summarization/summarizer.py`
- [Keyword extractor](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/services/keywords/extractor.py): `backend/app/services/keywords/extractor.py`
- [Sentiment analyzer](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/services/sentiment/sentiment.py): `backend/app/services/sentiment/sentiment.py`
- [Reading-time estimator](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/services/reading_time.py): `backend/app/services/reading_time.py`

### Model inference

- [News classifier](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/services/classification/classifier.py): `backend/app/services/classification/classifier.py`
- [Model loader](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/core/model_loader.py): `backend/app/core/model_loader.py`
- [Classifier assets](https://github.com/oreo1906/news-article-categorization/tree/main/backend/news_classifier): `backend/news_classifier`

### Runtime support

- [Service dependency](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/core/dependencies.py): `backend/app/core/dependencies.py`
- [Settings](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/config/settings.py): `backend/app/config/settings.py`
- [Resource monitor](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/utils/resource_usage.py): `backend/app/utils/resource_usage.py`
- [Application logger](https://github.com/oreo1906/news-article-categorization/blob/main/backend/app/utils/logger.py): `backend/app/utils/logger.py`

### Other components

- **API client**

## Connections

- API client → Analyze endpoint: submits text (evidence: `backend/app/routers/analyze.py`)
- FastAPI app → Analyze endpoint: registers route (evidence: `backend/app/main.py`)
- FastAPI app → Health endpoint: registers route (evidence: `backend/app/main.py`)
- FastAPI app → Error handlers: registers handlers (evidence: `backend/app/main.py`)
- FastAPI app → Service dependency: loads analyzer (evidence: `backend/app/main.py`)
- FastAPI app → Settings: configures app (evidence: `backend/app/main.py`)
- FastAPI app → Application logger: logs lifecycle (evidence: `backend/app/main.py`)
- FastAPI app → Resource monitor: logs memory (evidence: `backend/app/main.py`)
- Analyze endpoint → Request schema: validates input (evidence: `backend/app/routers/analyze.py`)
- Analyze endpoint → Response schema: returns payload (evidence: `backend/app/routers/analyze.py`)
- Analyze endpoint → Service dependency: gets analyzer (evidence: `backend/app/routers/analyze.py`)
- Service dependency → Article analyzer: creates singleton (evidence: `backend/app/core/dependencies.py`)
- Analyze endpoint → Article analyzer: invokes analysis (evidence: `backend/app/routers/analyze.py`)
- Article analyzer → News classifier: classifies text (evidence: `backend/app/services/analyzer.py`)
- Article analyzer → Text summarizer: generates text outputs (evidence: `backend/app/services/analyzer.py`)
- Article analyzer → Keyword extractor: extracts keywords (evidence: `backend/app/services/analyzer.py`)
- Article analyzer → Sentiment analyzer: analyzes sentiment (evidence: `backend/app/services/analyzer.py`)
- Article analyzer → Reading-time estimator: estimates reading time (evidence: `backend/app/services/analyzer.py`)
- News classifier → Model loader: gets model and tokenizer (evidence: `backend/app/services/classification/classifier.py`)
- News classifier → Settings: uses inference settings (evidence: `backend/app/services/classification/classifier.py`)
- News classifier → Resource monitor: logs memory (evidence: `backend/app/services/classification/classifier.py`)
- Model loader → Classifier assets: loads configured assets (evidence: `backend/app/core/model_loader.py`)
- Model loader → Settings: reads model configuration (evidence: `backend/app/core/model_loader.py`)
- Model loader → Resource monitor: logs memory (evidence: `backend/app/core/model_loader.py`)
- Health endpoint → Settings: reports configuration (evidence: `backend/app/routers/health.py`)
- Health endpoint → Model loader: checks model status (evidence: `backend/app/routers/health.py`)
