How tanujkumar24/e-commerce-swot-analysis works
Project Type and Purpose
• This is a backend-focused, API-driven SWOT Analysis tool written in Python.
• It exposes a Flask /analyze endpoint, integrates with external NLP and search APIs, classifies sentiment into SWOT categories, and generates PDF reports.
• It also provides FastMCP integration so LLM agents can invoke the tool in an MCP-compatible environment.
Top-Level Components
a. Client Layer
– REST client (could be curl, Postman, or any HTTP client)
– FastMCP inspector CLI (via npx @modelcontextprotocol/inspector python main.py)
b. API Layer
– app.py (Flask application exposing /analyze)
– test_swot.py (automated tests invoking the endpoint)
c. Business Logic Layer
– Review scraper & fetcher (Google Custom Search API module)
– NLP analyzer (Hugging Face Transformers using DistilBERT)
– Data processor (Pandas for data frames, Matplotlib for charts)
– SWOT classifier (aggregates sentiment into Strengths, Weaknesses, Opportunities, Threats)
d. Persistence & Reporting
– analysis_results/* (JSON snapshots of raw and processed data)
– pdf_reports/* (generated PDF reports via FPDF)
e. External Services
– Google Custom Search API (for product reviews)
– Hugging Face inference endpoint (for sentiment analysis)
– FastMCP Inspector (npm package that wraps your tool for LLM agents)
Relationships & Data Flow
1. Client (or FastMCP) sends POST /analyze → Flask (app.py)
2. Flask handler extracts product_name → calls Review Scraper
3. Scraper invokes Google API → returns raw reviews
4. Raw reviews → NLP Analyzer → produces sentiment scores
5. Sentiment data → Data Processor → generates charts, aggregates metrics
6. Aggregated metrics → SWOT Classifier → constructs strengths/weaknesses/etc.
7. JSON result →
• Stored in analysis_results/
• Returned synchronously in HTTP response
8. Post-processing:
• PDF Generator reads classification + charts → writes to pdf_reports/
9. test_swot.py runs as a separate process → hits the same /analyze endpoint → validates JSON schema
Architectural Patterns & Design Principles
– Layered pattern separating API, business logic, and persistence
– Modular components for scraper, analyzer, classifier, PDF generator
– Single responsibility per module for easier testing and replacement
– Externalization of credentials (Google API key, Search Engine ID)
– FastMCP wrapper exposes identical /analyze functionality to LLM-based clients
Essential Elements
– Clear labels for: Client, FastMCP Inspector, Flask API, Scraper, NLP Analyzer, Classifier, PDF Generator, Storage folders, Test script