# ferdesmello/sci-fi-novels-evolution architecture

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

- Interactive diagram: https://gitdiagram.com/ferdesmello/sci-fi-novels-evolution
- Repository: https://github.com/ferdesmello/sci-fi-novels-evolution

## Overview

1. **Project purpose**
   - This repository is a data pipeline for studying how sci-fi novel plots change over time.
   - The output is a set of CSV datasets and final figures, not an application or service.

2. **Main pipeline stages**
   - The workflow is: collect book metadata → clean and reduce it → enrich it with Wikipedia plot text → query an LLM for structured plot attributes → aggregate results into figures.
   - Each stage writes intermediate files that become the input to the next stage.

3. **Data ingestion layer**
   - `scripts/1_Goodreads_scraper_SHELF.py` and `scripts/2_Goodreads_scraper_LISTS.py` gather book metadata from Goodreads shelf/list pages.
   - The repo expects scraped or downloaded HTML inputs for at least part of this step, so the data source boundary is partly offline and manually prepared.

4. **Raw and intermediate data boundary**
   - `data/` is the central working area, with subfolders for raw-ish inputs, filtered datasets, model answers, and variability experiments.
   - The repository keeps most processing artifacts as CSV files, making the pipeline file-driven rather than database-driven.

5. **Cleaning and reduction subsystem**
   - `scripts/3_Data_reducer_FILTERED.py` merges the collected sources and removes duplicates, bad records, and non-target books.
   - `scripts/4_Data_reducer_TOP.py` builds the analysis sample by selecting the top 200 novels per decade, plus a smaller test set.
   - `scripts/5_Data_fixer.py` exists to reconcile downstream files when the filtered/top sample changes.

6. **Wikipedia enrichment boundary**
   - `scripts/6_Wikipedia_plot_scraper.py` adds plot sections from Wikipedia for books in the top/test sets.
   - This step shifts the dataset from Goodreads-derived metadata to richer narrative text, which is preferred for the later AI analysis.

7. **LLM annotation subsystem**
   - `scripts/7_AI_asker_AI_ANSWERS.py` sends each novel’s data to OpenAI’s API and stores structured answers in `data/answers/`.
   - `scripts/8_AI_asker_AI_ANSWERS_GENDER.py` is a separate annotation pass that infers author gender per unique author.
   - These scripts are the main external-service dependency points; they require an API key and budget.

8. **Model variability experiment**
   - `data/variability_in_answers/` contains repeated answer runs for the test set.
   - This supports measuring how stable the model’s responses are across runs, and it feeds the test/variance figures rather than the main results.

9. **Analysis and visualization layer**
   - `scripts/9_Figure_maker_novels.py`, `scripts/9_Figure_maker_questions.py`, and `scripts/9_Figure_maker_tests.py` turn the CSV outputs into plots.
   - The figure scripts read from the AI answer files, gender file, and variability files, then write final images into `figures/`.

10. **Repository structure for reproducibility**
    - `paths.py` likely centralizes filesystem locations so the scripts can share the same directory conventions.
    - This matters because the workflow depends heavily on consistent relative paths between raw data, filtered data, answers, and figures.

11. **Archived/previous-model branch**
    - `old/` contains prior versions of the same pipeline and outputs for GPT-4o and Gemini 2.0 Flash.
    - Architecturally, this is an experiment archive rather than part of the active production path.

12. **End-to-end data flow to diagram**
    - A useful architecture diagram should show three major boundaries: external data sources (Goodreads, Wikipedia, OpenAI), local CSV-based processing stages, and final visualization outputs.
    - The key artifacts moving between stages are: scraped book metadata, filtered/top samples, Wikipedia-enriched text, LLM answer CSVs, and figures.

Main entry points: [`paths.py`](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/paths.py) (Paths), [`data/filtered/sci-fi_novels_FILTERED.csv`](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/filtered/sci-fi_novels_FILTERED.csv) (Filtered data), [`figures`](https://github.com/ferdesmello/sci-fi-novels-evolution/tree/main/figures) (Figures), [`data/filtered/sci-fi_novels_TEST_Wiki.csv`](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/filtered/sci-fi_novels_TEST_Wiki.csv) (Test Wiki)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_external["External sources"]
  node_goodreads_shelf["Shelf scraper<br/>ingest script"]
  node_goodreads_lists["List scraper<br/>ingest script"]
  node_wiki["Wikipedia plot<br/>enrichment script"]
  node_openai_answers["LLM answers<br/>annotation script"]
  node_openai_gender["Gender pass<br/>annotation script"]
end

subgraph group_pipeline["CSV pipeline"]
  node_paths["Paths<br/>path config<br/>[paths.py]"]
  node_filtered[("Filtered data<br/>csv dataset")]
  node_top[("Top sample<br/>csv dataset")]
  node_testset[("Test sample<br/>csv dataset")]
  node_top_wiki[("Top Wiki<br/>csv dataset")]
  node_test_wiki[("Test Wiki<br/>csv dataset")]
  node_answers[("AI answers<br/>csv dataset")]
  node_gender[("Gender data<br/>csv dataset")]
  node_variability[("Variability runs<br/>csv runs")]
end

subgraph group_analysis["Analysis and figures"]
  node_fig_novels["Novel figures<br/>figure script"]
  node_fig_questions["Question figures<br/>figure script"]
  node_fig_tests["Test figures<br/>figure script"]
  node_figures(("Figures<br/>output dir"))
end

subgraph group_archive["Archived experiments"]
  node_legacy_gpt4o["GPT-4o archive<br/>legacy run"]
  node_legacy_gemini["Gemini archive<br/>legacy run<br/>[gemini_2.0_flash]"]
end

node_paths -->|"shared paths"| node_goodreads_shelf
node_paths -->|"shared paths"| node_goodreads_lists
node_paths -->|"shared paths"| node_wiki
node_paths -->|"shared paths"| node_openai_answers
node_paths -->|"shared paths"| node_openai_gender
node_goodreads_shelf -->|"metadata"| node_filtered
node_goodreads_lists -->|"metadata"| node_filtered
node_filtered -->|"sample"| node_top
node_filtered -->|"sample"| node_testset
node_top -->|"enrich"| node_top_wiki
node_testset -->|"enrich"| node_test_wiki
node_top_wiki -->|"annotate"| node_openai_answers
node_test_wiki -->|"annotate"| node_openai_answers
node_filtered -->|"authors"| node_openai_gender
node_test_wiki -->|"repeat runs"| node_variability
node_answers -->|"input"| node_fig_novels
node_answers -->|"input"| node_fig_questions
node_gender -->|"input"| node_fig_novels
node_gender -->|"input"| node_fig_questions
node_variability -->|"input"| node_fig_tests
node_fig_novels -->|"write"| node_figures
node_fig_questions -->|"write"| node_figures
node_fig_tests -->|"write"| node_figures
node_legacy_gpt4o -.->|"archived outputs"| node_figures
node_legacy_gemini -.->|"archived outputs"| node_figures

click node_goodreads_shelf "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/1_Goodreads_scraper_SHELF.py"
click node_goodreads_lists "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/2_Goodreads_scraper_LISTS.py"
click node_wiki "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/6_Wikipedia_plot_scraper.py"
click node_openai_answers "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/7_AI_asker_AI_ANSWERS.py"
click node_openai_gender "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/8_AI_asker_AI_ANSWERS_GENDER.py"
click node_paths "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/paths.py"
click node_filtered "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/filtered/sci-fi_novels_FILTERED.csv"
click node_top "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/filtered/sci-fi_novels_TOP.csv"
click node_testset "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/filtered/sci-fi_novels_TEST.csv"
click node_top_wiki "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/filtered/sci-fi_novels_TOP_Wiki.csv"
click node_test_wiki "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/filtered/sci-fi_novels_TEST_Wiki.csv"
click node_answers "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/answers/sci-fi_novels_AI_ANSWERS.csv"
click node_gender "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/answers/sci-fi_novels_AI_ANSWERS_GENDER.csv"
click node_variability "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/variability_in_answers/sci-fi_novels_AI_ANSWERS_TEST_01.csv"
click node_fig_novels "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/9_Figure_maker_novels.py"
click node_fig_questions "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/9_Figure_maker_questions.py"
click node_fig_tests "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/9_Figure_maker_tests.py"
click node_figures "https://github.com/ferdesmello/sci-fi-novels-evolution/tree/main/figures"
click node_legacy_gpt4o "https://github.com/ferdesmello/sci-fi-novels-evolution/tree/main/old/gpt-4o"
click node_legacy_gemini "https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/old/gemini_2.0_flash"

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_goodreads_shelf,node_goodreads_lists,node_wiki,node_openai_answers,node_openai_gender toneBlue
class node_paths,node_filtered,node_top,node_testset,node_top_wiki,node_test_wiki,node_answers,node_gender,node_variability toneAmber
class node_fig_novels,node_fig_questions,node_fig_tests,node_figures toneMint
class node_legacy_gpt4o,node_legacy_gemini toneRose
```

## Components

### External sources

Offline and API-backed inputs used by the pipeline.

- [Shelf scraper](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/1_Goodreads_scraper_SHELF.py): ingest script · Collects Goodreads shelf-based metadata. · `scripts/1_Goodreads_scraper_SHELF.py`
- [List scraper](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/2_Goodreads_scraper_LISTS.py): ingest script · Collects Goodreads list-based metadata. · `scripts/2_Goodreads_scraper_LISTS.py`
- [Wikipedia plot](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/6_Wikipedia_plot_scraper.py): enrichment script · Scrapes plot sections for the selected books. · `scripts/6_Wikipedia_plot_scraper.py`
- [LLM answers](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/7_AI_asker_AI_ANSWERS.py): annotation script · Sends novels to OpenAI and stores structured plot answers. · `scripts/7_AI_asker_AI_ANSWERS.py`
- [Gender pass](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/8_AI_asker_AI_ANSWERS_GENDER.py): annotation script · Infers author gender per unique author via OpenAI. · `scripts/8_AI_asker_AI_ANSWERS_GENDER.py`

### CSV pipeline

Main file-driven processing stages and intermediate datasets.

- [Paths](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/paths.py): path config · Centralizes repository file locations for shared scripts. · `paths.py`
- [Filtered data](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/filtered/sci-fi_novels_FILTERED.csv): csv dataset · Merged and cleaned metadata after duplicate and target filtering. · `data/filtered/sci-fi_novels_FILTERED.csv`
- [Top sample](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/filtered/sci-fi_novels_TOP.csv): csv dataset · Main analysis sample with top novels per decade. · `data/filtered/sci-fi_novels_TOP.csv`
- [Test sample](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/filtered/sci-fi_novels_TEST.csv): csv dataset · Smaller test subset used for downstream checks and variability runs. · `data/filtered/sci-fi_novels_TEST.csv`
- [Top Wiki](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/filtered/sci-fi_novels_TOP_Wiki.csv): csv dataset · Top sample enriched with Wikipedia plot text. · `data/filtered/sci-fi_novels_TOP_Wiki.csv`
- [Test Wiki](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/filtered/sci-fi_novels_TEST_Wiki.csv): csv dataset · Test sample enriched with Wikipedia plot text. · `data/filtered/sci-fi_novels_TEST_Wiki.csv`
- [AI answers](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/answers/sci-fi_novels_AI_ANSWERS.csv): csv dataset · Main structured annotation output from the LLM. · `data/answers/sci-fi_novels_AI_ANSWERS.csv`
- [Gender data](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/answers/sci-fi_novels_AI_ANSWERS_GENDER.csv): csv dataset · Author-gender annotation output used by figure scripts. · `data/answers/sci-fi_novels_AI_ANSWERS_GENDER.csv`
- [Variability runs](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/data/variability_in_answers/sci-fi_novels_AI_ANSWERS_TEST_01.csv): csv runs · Repeated test-set answer files used to measure response stability. · `data/variability_in_answers/sci-fi_novels_AI_ANSWERS_TEST_01.csv`

### Analysis and figures

Scripts and outputs that turn annotated data into plots.

- [Novel figures](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/9_Figure_maker_novels.py): figure script · Builds plots about novel-level trends from annotated data. · `scripts/9_Figure_maker_novels.py`
- [Question figures](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/9_Figure_maker_questions.py): figure script · Builds plots summarizing question-level AI outputs. · `scripts/9_Figure_maker_questions.py`
- [Test figures](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/scripts/9_Figure_maker_tests.py): figure script · Builds plots for test-set and variability analysis. · `scripts/9_Figure_maker_tests.py`
- [Figures](https://github.com/ferdesmello/sci-fi-novels-evolution/tree/main/figures): output dir · Final visualization outputs produced by the analysis layer. · `figures`

### Archived experiments

Previous model runs and legacy pipeline outputs kept for reference.

- [GPT-4o archive](https://github.com/ferdesmello/sci-fi-novels-evolution/tree/main/old/gpt-4o): legacy run · Archived prior-model pipeline outputs and scripts. · `old/gpt-4o`
- [Gemini archive](https://github.com/ferdesmello/sci-fi-novels-evolution/blob/main/old/gemini_2.0_flash): legacy run · Archived Gemini 2.0 Flash pipeline outputs and scripts. · `old/gemini_2.0_flash`

## Connections

- Paths → Shelf scraper: shared paths · Uses shared filesystem conventions.
- Paths → List scraper: shared paths · Uses shared filesystem conventions.
- Paths → Wikipedia plot: shared paths · Uses shared filesystem conventions.
- Paths → LLM answers: shared paths · Uses shared filesystem conventions.
- Paths → Gender pass: shared paths · Uses shared filesystem conventions.
- Shelf scraper → Filtered data: metadata · Produces scraped Goodreads shelf metadata that feeds cleaning.
- List scraper → Filtered data: metadata · Produces scraped Goodreads list metadata that feeds cleaning.
- Filtered data → Top sample: sample · Reduced dataset is used to build the main analysis sample.
- Filtered data → Test sample: sample · Reduced dataset is also used to build the test subset.
- Top sample → Top Wiki: enrich · Top sample is augmented with Wikipedia plot text.
- Test sample → Test Wiki: enrich · Test sample is augmented with Wikipedia plot text.
- Top Wiki → LLM answers: annotate · Enriched top sample is sent for structured LLM annotation.
- Test Wiki → LLM answers: annotate · Enriched test sample is also sent for structured LLM annotation.
- Filtered data → Gender pass: authors · Filtered author list supports gender annotation.
- Test Wiki → Variability runs: repeat runs · Test set is repeatedly annotated to measure response stability.
- AI answers → Novel figures: input · Main AI answer CSV feeds novel-level charts.
- AI answers → Question figures: input · Main AI answer CSV feeds question-level charts.
- Gender data → Novel figures: input · Gender annotations support several novel-level plots.
- Gender data → Question figures: input · Gender annotations support question-level analysis.
- Variability runs → Test figures: input · Repeated runs feed stability and variance figures.
- Novel figures → Figures: write · Outputs final novel-level plots.
- Question figures → Figures: write · Outputs final question-level plots.
- Test figures → Figures: write · Outputs final test and variability plots.
- GPT-4o archive → Figures: archived outputs · Reference outputs from earlier GPT-4o runs.
- Gemini archive → Figures: archived outputs · Reference outputs from earlier Gemini runs.
