How belashov641618/tradeshield works
Project type and purpose
• TradeShield is a containerized full-stack web application for automated analysis of customs-tariff regulation measures (TTR).
• Users enter a product name or HS code; the system fetches trade and statistical data, applies rule‐based measures (from the measures library), and produces recommendations and PDF reports.
File structure
• Top-level directories:
• frontend/ – web UI (Flask app.py, index.html, startup script)
• backend/ – API server (main.py, requirements.txt, docker-compose.yml)
• measures/ – domain logic: per-measure Python clauses and JSON descriptions
• postgres/ – database schema (tables.py), initialization script, docker-compose.yml
• redis/ – message broker container definition
• workers/ – background services:
– data_extractor/ (pull external data)
– report_creator/ (generate PDF reports)
• utilities/ – helper scripts (gitpull for updating code, load_clauses for loading measure definitions)
• Each service has its own Docker Compose file, indicating a microservice‐style deployment.
README insights
• System gathers: customs stats, Rosstat data, WTO obligations.
• Applies algorithms and rule sets to recommend measures (tariffs, certification, anti-dumping).
• Outputs both explanation and PDF reports.
Main components and interactions
a. Components:
• User Web Browser
• Frontend Flask App
• Backend API Server
• Redis (queue/cache)
• PostgreSQL database
• Data Extractor Worker
• Report Creator Worker
• Measures Library (measures/*)
• Utilities (load_clauses, gitpull)
• External Data Sources (Customs API, Rosstat API, WTO API)
b. Relationships & data flow:
1. User → Frontend (HTTP request)
2. Frontend → Backend API (HTTP)
3. Backend checks Redis cache; if miss, enqueues tasks in Redis for data extraction
4. Data Extractor reads queue → fetches external data → writes to Postgres → notifies via Redis
5. Backend loads measure definitions via utilities/load_clauses → applies rules to data in Postgres
6. Backend enqueues report creation task → Report Creator reads from Redis → generates PDF → stores result (DB or file store)
7. Backend responds to Frontend with recommendations and report link
c. Architectural patterns:
• Separation of concerns: UI layer, API layer, worker layer, data layer
• Event‐driven via Redis message queues
• Pluggable rule engine: measures directory loaded at runtime
• Containerized microservices with Docker Compose
d. Key technologies:
• Python + Flask (frontend & backend)
• Redis (broker/cache)
• PostgreSQL (persistent storage)
• Docker & Docker Compose (container orchestration)
• PDF generation libraries (in report_creator)
• External HTTP APIs for data ingestion
• Clear, descriptive labels on every component
• Containers by Docker network or Compose project
• Notes on dynamic loading of rules from measures/*.json and *.py