# sabbirhosen44/booking-attractions architecture

> Architecture diagram of the GitHub repository sabbirhosen44/booking-attractions, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sabbirhosen44/booking-attractions
- Repository: https://github.com/sabbirhosen44/booking-attractions

## Overview

#### 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: [`apps/attractions/management/commands/import_attractions.py`](https://github.com/sabbirhosen44/booking-attractions/blob/main/apps/attractions/management/commands/import_attractions.py) (Import Command), [`core/settings.py`](https://github.com/sabbirhosen44/booking-attractions/blob/main/core/settings.py) (Django Settings), [`core/configuration.py`](https://github.com/sabbirhosen44/booking-attractions/blob/main/core/configuration.py) (Import Configuration), [`core/utils/attraction_row_builder.py`](https://github.com/sabbirhosen44/booking-attractions/blob/main/core/utils/attraction_row_builder.py) (Row Builders)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Django Runtime"]
  node_compose["Docker Compose<br/>container environment<br/>[docker-compose.yml]"]
  node_django_image["Django Image<br/>Docker build"]
  node_settings["Django Settings<br/>runtime configuration<br/>[settings.py]"]
  node_postgres[("PostgreSQL + PostGIS<br/>persistent store")]
end

subgraph group_ingestion["Import Pipeline"]
  node_manage{{"manage.py<br/>Django CLI entry<br/>[manage.py]"}}
  node_import_command{{"Import Command<br/>management command"}}
  node_import_config["Import Configuration<br/>TOML configuration<br/>[configuration.py]"]
  node_import_config_utils["Import Config Loader<br/>configuration utility<br/>[import_config.py]"]
  node_config_template["Config Template<br/>TOML template"]
  node_json_sources["Booking JSON Datasets<br/>streamed input"]
  node_row_builders["Row Builders<br/>stream transformation"]
  node_resolvers["Country &amp; Location Resolvers<br/>reference normalization"]
  node_batching["Batching &amp; Partitioning<br/>throughput control<br/>[batch_buffer.py]"]
  node_locked_write["Locked Write<br/>write synchronization<br/>[locked_write.py]"]
  node_skip_counter["Skip Counter<br/>import telemetry<br/>[skip_counter.py]"]
end

subgraph group_domain["Attractions Domain"]
  node_services["Domain Services<br/>import service layer<br/>[services.py]"]
  node_db_services["Database Services<br/>bulk persistence layer<br/>[db_services.py]"]
  node_models["Attraction Models<br/>Django ORM models<br/>[models.py]"]
  node_migration["Initial Schema Migration<br/>Django migration<br/>[0001_initial.py]"]
end

subgraph group_interfaces["Secondary Interfaces"]
  node_web_surfaces["Web &amp; Admin Surfaces<br/>Django interface<br/>[urls.py]"]
  node_server_entrypoints{{"WSGI / ASGI Entrypoints<br/>server entrypoints<br/>[wsgi.py]"}}
end

node_compose -->|"builds"| node_django_image
node_compose -->|"provisions"| node_postgres
node_django_image -->|"runs Django with"| node_settings
node_settings -->|"configures connection"| node_postgres
node_manage -->|"invokes"| node_import_command
node_import_command -->|"loads"| node_import_config
node_import_config -->|"uses"| node_import_config_utils
node_config_template -.->|"templates"| node_import_config
node_import_command -->|"streams"| node_json_sources
node_json_sources -->|"raw records"| node_row_builders
node_resolvers -->|"normalizes references"| node_row_builders
node_row_builders -->|"buffers rows"| node_batching
node_import_command -->|"coordinates"| node_batching
node_batching -->|"parallel batches"| node_locked_write
node_import_command -->|"records rejected rows"| node_skip_counter
node_locked_write -->|"submits writes"| node_services
node_services -->|"delegates persistence"| node_db_services
node_db_services -->|"bulk creates / upserts"| node_models
node_models -->|"persists through ORM"| node_postgres
node_migration -->|"establishes schema"| node_models
node_server_entrypoints -->|"boots Django"| node_settings
node_web_surfaces -.->|"accesses domain operations"| node_services

click node_compose "https://github.com/sabbirhosen44/booking-attractions/blob/main/docker-compose.yml"
click node_django_image "https://github.com/sabbirhosen44/booking-attractions/tree/main/docker/django/Dockerfile"
click node_settings "https://github.com/sabbirhosen44/booking-attractions/blob/main/core/settings.py"
click node_manage "https://github.com/sabbirhosen44/booking-attractions/blob/main/manage.py"
click node_import_command "https://github.com/sabbirhosen44/booking-attractions/blob/main/apps/attractions/management/commands/import_attractions.py"
click node_import_config "https://github.com/sabbirhosen44/booking-attractions/blob/main/core/configuration.py"
click node_import_config_utils "https://github.com/sabbirhosen44/booking-attractions/blob/main/core/utils/import_config.py"
click node_config_template "https://github.com/sabbirhosen44/booking-attractions/blob/main/core/app_config.toml.example"
click node_row_builders "https://github.com/sabbirhosen44/booking-attractions/blob/main/core/utils/attraction_row_builder.py"
click node_resolvers "https://github.com/sabbirhosen44/booking-attractions/blob/main/core/utils/country_resolver.py"
click node_batching "https://github.com/sabbirhosen44/booking-attractions/blob/main/core/utils/batch_buffer.py"
click node_locked_write "https://github.com/sabbirhosen44/booking-attractions/blob/main/core/utils/locked_write.py"
click node_skip_counter "https://github.com/sabbirhosen44/booking-attractions/blob/main/core/utils/skip_counter.py"
click node_services "https://github.com/sabbirhosen44/booking-attractions/blob/main/apps/attractions/services.py"
click node_db_services "https://github.com/sabbirhosen44/booking-attractions/blob/main/apps/attractions/db_services.py"
click node_models "https://github.com/sabbirhosen44/booking-attractions/blob/main/apps/attractions/models.py"
click node_migration "https://github.com/sabbirhosen44/booking-attractions/blob/main/apps/attractions/migrations/0001_initial.py"
click node_web_surfaces "https://github.com/sabbirhosen44/booking-attractions/blob/main/core/urls.py"
click node_server_entrypoints "https://github.com/sabbirhosen44/booking-attractions/blob/main/core/wsgi.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_compose,node_django_image,node_settings,node_postgres toneBlue
class node_manage,node_import_command,node_import_config,node_import_config_utils,node_config_template,node_json_sources,node_row_builders,node_resolvers,node_batching,node_locked_write,node_skip_counter toneAmber
class node_services,node_db_services,node_models,node_migration toneMint
class node_web_surfaces,node_server_entrypoints toneRose
```

## Components

### Django Runtime

- [Docker Compose](https://github.com/sabbirhosen44/booking-attractions/blob/main/docker-compose.yml): container environment · Provisions the Django application and database. · `docker-compose.yml`
- [Django Image](https://github.com/sabbirhosen44/booking-attractions/tree/main/docker/django/Dockerfile): Docker build · `docker/django/Dockerfile`
- [Django Settings](https://github.com/sabbirhosen44/booking-attractions/blob/main/core/settings.py): runtime configuration · `core/settings.py`
- **PostgreSQL + PostGIS**: persistent store · Persistent relational and spatial database.

### Import Pipeline

- [manage.py](https://github.com/sabbirhosen44/booking-attractions/blob/main/manage.py): Django CLI entry · `manage.py`
- [Import Command](https://github.com/sabbirhosen44/booking-attractions/blob/main/apps/attractions/management/commands/import_attractions.py): management command · Coordinates source discovery, processing, batching, and parallel import. · `apps/attractions/management/commands/import_attractions.py`
- [Import Configuration](https://github.com/sabbirhosen44/booking-attractions/blob/main/core/configuration.py): TOML configuration · Central import behavior and input-source configuration. · `core/configuration.py`
- [Import Config Loader](https://github.com/sabbirhosen44/booking-attractions/blob/main/core/utils/import_config.py): configuration utility · `core/utils/import_config.py`
- [Config Template](https://github.com/sabbirhosen44/booking-attractions/blob/main/core/app_config.toml.example): TOML template · `core/app_config.toml.example`
- **Booking JSON Datasets**: streamed input · Attraction details, reviews, and score source files.
- [Row Builders](https://github.com/sabbirhosen44/booking-attractions/blob/main/core/utils/attraction_row_builder.py): stream transformation · Build persistence-ready attraction, review, and price rows. · `core/utils/attraction_row_builder.py`
- [Country & Location Resolvers](https://github.com/sabbirhosen44/booking-attractions/blob/main/core/utils/country_resolver.py): reference normalization · `core/utils/country_resolver.py`
- [Batching & Partitioning](https://github.com/sabbirhosen44/booking-attractions/blob/main/core/utils/batch_buffer.py): throughput control · Buffers records and partitions work for parallel execution. · `core/utils/batch_buffer.py`
- [Locked Write](https://github.com/sabbirhosen44/booking-attractions/blob/main/core/utils/locked_write.py): write synchronization · Makes concurrent worker writes thread-safe. · `core/utils/locked_write.py`
- [Skip Counter](https://github.com/sabbirhosen44/booking-attractions/blob/main/core/utils/skip_counter.py): import telemetry · Tracks rejected records while allowing partial imports. · `core/utils/skip_counter.py`

### Attractions Domain

- [Domain Services](https://github.com/sabbirhosen44/booking-attractions/blob/main/apps/attractions/services.py): import service layer · Higher-level attraction import operations. · `apps/attractions/services.py`
- [Database Services](https://github.com/sabbirhosen44/booking-attractions/blob/main/apps/attractions/db_services.py): bulk persistence layer · Conflict-safe bulk create and upsert boundary. · `apps/attractions/db_services.py`
- [Attraction Models](https://github.com/sabbirhosen44/booking-attractions/blob/main/apps/attractions/models.py): Django ORM models · Attractions and localized, photo, review, and score records. · `apps/attractions/models.py`
- [Initial Schema Migration](https://github.com/sabbirhosen44/booking-attractions/blob/main/apps/attractions/migrations/0001_initial.py): Django migration · `apps/attractions/migrations/0001_initial.py`

### Secondary Interfaces

- [Web & Admin Surfaces](https://github.com/sabbirhosen44/booking-attractions/blob/main/core/urls.py): Django interface · Secondary HTTP routing, views, and admin exposure. · `core/urls.py`
- [WSGI / ASGI Entrypoints](https://github.com/sabbirhosen44/booking-attractions/blob/main/core/wsgi.py): server entrypoints · `core/wsgi.py`

## Connections

- 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
