How abcd771321-crypto/crypto-prediction works
Project Type and Purpose
• This is a monolithic full-stack web application built on Flask.
• It serves server-rendered HTML pages with interactive Plotly charts and offers ML-driven price predictions (Linear, RF, SVR, LSTM), currency conversion, comparison, and technical indicators for cryptocurrencies.
• Data sources include local CSV files (historical data) and a remote CoinGecko-style API.
Top-Level Components
• Client (Browser)
• Requests HTML pages, submits forms.
• Flask Application (WSGI process)
• App factory (create_app()), configuration via .env, security headers, logging.
• Blueprints (routes.py) handling URL groups: main, detail, technical, predict, convert, compare, update.
• Service Layer (services.py)
• load_crypto_data() reads CSV and merges with cached JSON.
• Lazy singletons for in-memory data and currency converter.
• get_crypto_data(), update_prices_in_place() for safe in-memory price updates.
• Model Layer (models/)
• API Client (api_client.py): requests.Session with Retry and timeout, disk-cache of JSON responses.
• Prediction Models (prediction_models.py): data preparation, ensemble fallback logic.
• Technical Indicators (technical_indicators.py): computes RSI, MACD, Bollinger Bands, etc.
• Crypto Comparison & Converter.
• Data Stores
• CSV files under coin files csv/ (source of historical prices).
• JSON caches under crypto_analysis/cache/ (latest prices, descriptions, historical 30-day data).
• Templates & Static
• HTML templates (templates/) for each page.
• Static assets (static/) for CSS/JS (Plotly, day/night toggle).
• Configuration & Deployment
• Environment variables via .env (SECRET_KEY, FLASK_DEBUG, API_HTTP_TIMEOUT).
• Procfile for Heroku/Gunicorn.
• Logging to crypto_analysis/app.log with rotating handler.
Interactions and Data Flow
• Browser → HTTP request → Flask (Gunicorn)
• Flask routes invoke Service Layer → loads CSV or reads JSON cache
• Service may call Model Layer → for predictions or indicators
• Model Layer may call API Client → external API → updates JSON cache on disk
• Service returns data → Flask renders template with Plotly graphs
• Response → Browser
Architectural Patterns & Design Principles
• App Factory: isolates configuration and app creation.
• Blueprints: modular routing by feature.
• Layered Architecture: Presentation (Blueprints + Templates), Application (Services), Domain (Models), Infrastructure (File system cache, external API).
• Lazy Singletons: for in-memory data and converter to minimize startup cost.
• Retry/Timeout: ensures robust external HTTP calls.
• Fallback Ensemble Logic: resilience in prediction (LSTM → RF → Linear).
Essential Elements
• Client (Browser)
• Web Server (Gunicorn/Flask)
• Flask App Factory & Blueprints
• Service Layer
• Model Layer (API Client, Prediction, Technical Indicators)
• Data Stores (CSV files, JSON cache)
• External API
• Templates & Static Assets
• Config (.env) & Logging