How oreo1906/news-article-categorization works
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: main.py FastAPI app · analyzer.py Article analyzer · analyze.py Analyze endpoint · model_loader.py Model loader
Components 19
API layer
- FastAPI app
backend/app/main.py - Analyze endpoint
backend/app/routers/analyze.py - Health endpoint
backend/app/routers/health.py - Request schema
backend/app/models/request_models.py - Response schema
backend/app/models/response_models.py - Error handlers
backend/app/core/exceptions.py
Analysis services
- Article analyzer
backend/app/services/analyzer.py - Text summarizer
backend/app/services/summarization/summarizer.py - Keyword extractor
backend/app/services/keywords/extractor.py - Sentiment analyzer
backend/app/services/sentiment/sentiment.py - Reading-time estimator
backend/app/services/reading_time.py
Model inference
- News classifier
backend/app/services/classification/classifier.py - Model loader
backend/app/core/model_loader.py - Classifier assets
backend/news_classifier
Runtime support
- Service dependency
backend/app/core/dependencies.py - Settings
backend/app/config/settings.py - Resource monitor
backend/app/utils/resource_usage.py - Application logger
backend/app/utils/logger.py
Other components
- API client
Connections 26
- API client → Analyze endpoint: submits text
backend/app/routers/analyze.py - FastAPI app → Analyze endpoint: registers route
backend/app/main.py - FastAPI app → Health endpoint: registers route
backend/app/main.py - FastAPI app → Error handlers: registers handlers
backend/app/main.py - FastAPI app → Service dependency: loads analyzer
backend/app/main.py - FastAPI app → Settings: configures app
backend/app/main.py - FastAPI app → Application logger: logs lifecycle
backend/app/main.py - FastAPI app → Resource monitor: logs memory
backend/app/main.py - Analyze endpoint → Request schema: validates input
backend/app/routers/analyze.py - Analyze endpoint → Response schema: returns payload
backend/app/routers/analyze.py - Analyze endpoint → Service dependency: gets analyzer
backend/app/routers/analyze.py - Service dependency → Article analyzer: creates singleton
backend/app/core/dependencies.py - Analyze endpoint → Article analyzer: invokes analysis
backend/app/routers/analyze.py - Article analyzer → News classifier: classifies text
backend/app/services/analyzer.py - Article analyzer → Text summarizer: generates text outputs
backend/app/services/analyzer.py - Article analyzer → Keyword extractor: extracts keywords
backend/app/services/analyzer.py - Article analyzer → Sentiment analyzer: analyzes sentiment
backend/app/services/analyzer.py - Article analyzer → Reading-time estimator: estimates reading time
backend/app/services/analyzer.py - News classifier → Model loader: gets model and tokenizer
backend/app/services/classification/classifier.py - News classifier → Settings: uses inference settings
backend/app/services/classification/classifier.py - News classifier → Resource monitor: logs memory
backend/app/services/classification/classifier.py - Model loader → Classifier assets: loads configured assets
backend/app/core/model_loader.py - Model loader → Settings: reads model configuration
backend/app/core/model_loader.py - Model loader → Resource monitor: logs memory
backend/app/core/model_loader.py - Health endpoint → Settings: reports configuration
backend/app/routers/health.py - Health endpoint → Model loader: checks model status
backend/app/routers/health.py