How dipesh-ghimire/auto-nepse-stock-scrapers works
Project type and purpose
• From the file tree and README.md, this is a monolithic Django‐based full-stack web application with:
• A standard Django MVC structure (models, views, templates)
• Static assets (CSS/JS) for a Bootstrap 5-powered responsive frontend
• Celery for scheduled/async scraping tasks
• Selenium-based scrapers (“merolagani_scraper.py”, etc.) to fetch live stock prices from external sites
• A time-series forecasting component (ARIMA) for future price prediction
File structure
• Top-level “stockmarket” folder: Django project settings, ASGI/WSGI entrypoints, Celery setup
• “stocks” app: models.py (Company, PriceHistory, CompanyNews, Floorsheet), views, forms, templates, URLs, utility functions, and Celery tasks
• “stocks/scrapers”: three site-specific scraper implementations inheriting from base_scraper.py
• “stocks/tasks.py”: Celery tasks that schedule and invoke the scrapers, save results to the database, trigger forecasting
• Configuration files: requirements.txt, manage.py, .gitignore
README for additional insights
• Features list confirms CRUD for companies, news, price history; real-time scraping; ARIMA forecasting
• Mentions RESTful-style URL patterns and responsive frontend
High-level architecture components
a. Frontend (Browser)
– Static assets (CSS/JS) + Django templates served via HTTP
– User interactions (forms, list/detail views)
b. Backend Web Server
– Django application (ASGI/WSGI) handling HTTP requests
– URL routing → views → ORM → database
c. Database
– Relational datastore (e.g., PostgreSQL or SQLite) for Company, PriceHistory, CompanyNews, etc.
d. Celery Infrastructure
– Message broker (RabbitMQ or Redis) – not in file tree but implied by celery.py
– Celery beat scheduler (celerybeat-schedule files)
– Celery worker processes (execute tasks.py)
e. Scraper Subsystem
– Selenium-based scrapers that fetch live data from external services (Merolagani, Nepstock, Sharesansar)
– BaseScraper abstraction + site-specific implementations
f. Forecasting Module
– ARIMA model invoked within tasks or views for time-series prediction
g. External Services
– Third-party websites (Merolagani, Nepstock, Sharesansar) as data sources
Relationships and interactions
• Browser → HTTP → Django (front controller) → ORM → Database
• Celery beat → schedules tasks → Celery broker → Celery worker → scraper code → external sites → parsed data → back to Database
• User triggers manual scrape via Django view → Django enqueues Celery task → same flow
• Forecasting: Celery task or view loads historical prices from Database → runs ARIMA → writes predictions back or returns data to user
Architectural patterns & design principles
• MVC (Django’s MTV) for clear separation of data models, templates, and request handling
• Asynchronous task processing with Celery for non-blocking scrapes and long-running forecasts
• Modular scrapers via inheritance (base_scraper.py) to support multiple sources
• RESTful URL design for CRUD operations
• Single repository monolith, but logically separated into web/UI vs background processing
Step-by-step for the principal software engineer
3. Celery architecture: beat scheduler writing to broker, workers reading tasks.
– HTTP GET/POST from Browser → Django
– ORM read/write between Django → Database
– AMQP or Redis messages between Scheduler/Worker
– Data fetch from External sites → Worker
– Blue = user-facing flow,
– Orange = async/background flow,
– Green = data storage,
– Grey = external services