Hybrid Persistence Architecture
The system uses a composite use case to orchestrate dual persistence:application/use_cases/composite_save_movie_with_actors_use_case.py:25
PostgreSQL Persistence
Schema Design
The database implements a normalized relational schema:sql/01_schema.sql
MoviePostgresRepository
The PostgreSQL repository uses stored procedures for data integrity:infrastructure/persistence/postgres/repositories/movie_postgres_repository.py:16
Upsert Stored Procedure
The database uses stored procedures to handle INSERT/UPDATE logic:sql/02_procedures.sql
Query Operations
The repository provides query methods:infrastructure/persistence/postgres/repositories/movie_postgres_repository.py:43
Connection Configuration
shared/config/config.py:70
CSV Persistence
MovieCsvRepository
The CSV repository handles file-based persistence with thread safety:infrastructure/persistence/csv/repositories/movie_csv_repository.py:12
Thread-Safe Operations
The CSV repository uses threading locks to prevent race conditions:infrastructure/persistence/csv/repositories/movie_csv_repository.py:10
CSV Query Operations
infrastructure/persistence/csv/repositories/movie_csv_repository.py:56
Repository Pattern Benefits
Interface Abstraction
Both repositories implement the same interface:domain/repositories/movie_repository.py
Dependency Injection
The repository implementation is injected at runtime, allowing easy swapping:Use Case Orchestration
Composite Use Case
The composite pattern allows executing multiple persistence strategies:application/use_cases/composite_save_movie_with_actors_use_case.py
Data Flow
CSV Output Format
movies.csv
actors.csv
movie_actor.csv
data/
Configuration
PostgreSQL Settings
CSV Settings
CSV files are automatically created in thedata/ directory with proper headers and UTF-8 encoding.
Error Handling
PostgreSQL Error Recovery
CSV Error Recovery
CSV operations are wrapped in locks and automatically create missing directories:Next Steps
Scraping Engine
Learn how data is extracted
Concurrency
Explore parallel data processing