How sabbirhosen44/booking-attractions works
Purpose and Entry Points
This is a Django batch-import system for Booking.com attraction JSON datasets. Its primary entry point is the Django management command at apps/attractions/management/commands/import_attractions.py, invoked through manage.py import_attractions. Django can also run through standard WSGI/ASGI entry points at core/wsgi.py and core/asgi.py, though the repository’s central workload is offline ingestion rather than HTTP serving.
Runtime and Infrastructure
Python 3.12+ runs Django and the ORM. PostgreSQL 16 is the persistent store, with PostGIS 3.4 enabled for present or future spatial data. Docker Compose provisions the application and database environment through docker-compose.yml; the Django image is defined in docker/django/Dockerfile. Database access uses Psycopg and Django ORM bulk operations; JSON input is streamed with ijson.
Import Orchestration
apps/attractions/management/commands/import_attractions.py coordinates the end-to-end import. It discovers/configures input sources, processes attraction details, reviews, and score data, and controls batch/parallel execution. Import behavior is centrally loaded from TOML-backed configuration in core/configuration.py and core/utils/import_config.py, with the local template at core/app_config.toml.example.
Domain Persistence Boundary
The attractions Django app owns the import domain and database schema:
• apps/attractions/models.py defines persisted attraction-related entities, including the core attraction data and associated localized, photo, review, and score records.
• apps/attractions/migrations/0001_initial.py establishes the database schema.
• apps/attractions/db_services.py isolates conflict-safe bulk create/upsert and database-write concerns from parsing and orchestration.
• apps/attractions/services.py provides higher-level domain import/service operations.
This layer is the boundary between normalized application records and PostgreSQL/PostGIS.
Streaming Transformation Pipeline
Large JSON files are handled incrementally rather than loaded wholesale. Row builders transform raw source records into persistence-ready representations:
• core/utils/attraction_row_builder.py
• core/utils/review_row_builder.py
• core/utils/price_row_builder.py
Resolution utilities normalize linked/reference data such as countries and locations before rows reach the database layer:
• core/utils/country_resolver.py
• core/utils/location_resolver.py
The resulting flow is: source JSON → streamed records → normalized/domain row construction → buffered bulk write/upsert.
Throughput, Partitioning, and Write Safety
Batch accumulation is encapsulated by core/utils/batch_buffer.py; partitioning supports splitting work for parallel processing in core/utils/partition_manager.py. Since workers may write concurrently, core/utils/locked_write.py provides a thread-safe write boundary. core/utils/skip_counter.py tracks rejected or unusable records without stopping the overall import. These utilities allow partial-data tolerance while maintaining database consistency.
Django Composition
core/settings.py configures Django, database connectivity, installed apps, and PostGIS-related runtime settings. core/urls.py is the HTTP routing root, while apps/attractions/views.py and apps/attractions/admin.py expose the app to Django’s web/admin surfaces. Those interfaces are secondary to the management-command ingestion path.
Main entry points: import_attractions.py Import Command · settings.py Django Settings · configuration.py Import Configuration · attraction_row_builder.py Row Builders
Components 21
Django Runtime
- Docker Compose · Provisions the Django application and database.
docker-compose.yml - Django Image
docker/django/Dockerfile - Django Settings
core/settings.py - PostgreSQL + PostGIS · Persistent relational and spatial database.
Import Pipeline
- manage.py
manage.py - Import Command · Coordinates source discovery, processing, batching, and parallel import.
apps/attractions/management/commands/import_attractions.py - Import Configuration · Central import behavior and input-source configuration.
core/configuration.py - Import Config Loader
core/utils/import_config.py - Config Template
core/app_config.toml.example - Booking JSON Datasets · Attraction details, reviews, and score source files.
- Row Builders · Build persistence-ready attraction, review, and price rows.
core/utils/attraction_row_builder.py - Country & Location Resolvers
core/utils/country_resolver.py - Batching & Partitioning · Buffers records and partitions work for parallel execution.
core/utils/batch_buffer.py - Locked Write · Makes concurrent worker writes thread-safe.
core/utils/locked_write.py - Skip Counter · Tracks rejected records while allowing partial imports.
core/utils/skip_counter.py
Attractions Domain
- Domain Services · Higher-level attraction import operations.
apps/attractions/services.py - Database Services · Conflict-safe bulk create and upsert boundary.
apps/attractions/db_services.py - Attraction Models · Attractions and localized, photo, review, and score records.
apps/attractions/models.py - Initial Schema Migration
apps/attractions/migrations/0001_initial.py
Secondary Interfaces
- Web & Admin Surfaces · Secondary HTTP routing, views, and admin exposure.
core/urls.py - WSGI / ASGI Entrypoints
core/wsgi.py
Connections 22
- Docker Compose → Django Image: builds
- Docker Compose → PostgreSQL + PostGIS: provisions
- Django Image → Django Settings: runs Django with
- Django Settings → PostgreSQL + PostGIS: configures connection
- manage.py → Import Command: invokes · import_attractions
- Import Command → Import Configuration: loads
- Import Configuration → Import Config Loader: uses
- Config Template → Import Configuration: templates
- Import Command → Booking JSON Datasets: streams
- Booking JSON Datasets → Row Builders: raw records
- Country & Location Resolvers → Row Builders: normalizes references
- Row Builders → Batching & Partitioning: buffers rows
- Import Command → Batching & Partitioning: coordinates
- Batching & Partitioning → Locked Write: parallel batches
- Import Command → Skip Counter: records rejected rows
- Locked Write → Domain Services: submits writes
- Domain Services → Database Services: delegates persistence
- Database Services → Attraction Models: bulk creates / upserts
- Attraction Models → PostgreSQL + PostGIS: persists through ORM
- Initial Schema Migration → Attraction Models: establishes schema
- WSGI / ASGI Entrypoints → Django Settings: boots Django
- Web & Admin Surfaces → Domain Services: accesses domain operations