# dkim0048/tp10_ai architecture

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

- Interactive diagram: https://gitdiagram.com/dkim0048/tp10_ai
- Repository: https://github.com/dkim0048/tp10_ai

## Overview

Lexical Bridge AI provides three reading-support capabilities: age-based word difficulty estimates, an organized story library, and photo missions. The inference workflow runs through the FastAPI app to the word or image router, which prepares input, applies its model, and returns a result; the library clustering script produces a frontend-ready story catalog separately. The README documents the library’s filtering, topic and difficulty organization, while the excerpt shows its filtering and clustering implementation. Training and data-preparation scripts are intentionally omitted as they are not runtime components.

Main entry points: [`routers/word_difficulty.py`](https://github.com/dkim0048/tp10_ai/blob/main/routers/word_difficulty.py) (Word endpoints), [`routers/image_classification.py`](https://github.com/dkim0048/tp10_ai/blob/main/routers/image_classification.py) (Image endpoints), [`library_clustering/src/document_clustering.py`](https://github.com/dkim0048/tp10_ai/blob/main/library_clustering/src/document_clustering.py) (Filter and combine stories), [`main.py`](https://github.com/dkim0048/tp10_ai/blob/main/main.py) (FastAPI app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Inference API"]
  node_api_app["FastAPI app<br/>[main.py]"]
end

subgraph group_word["Word Difficulty"]
  node_word_routes["Word endpoints<br/>[word_difficulty.py]"]
  node_word_features["Word features<br/>[word_difficulty.py]"]
  node_word_regressor["AoA prediction<br/>[word_difficulty.py]"]
  node_word_category["Support category<br/>[word_difficulty.py]"]
  node_word_artifact["Trained AoA model"]
  node_word_training["Ridge training"]
end

subgraph group_library["Reading Library"]
  node_story_source["Story dataset<br/>[GlotStoryBook.csv]"]
  node_story_pipeline["Filter and combine stories"]
  node_story_topics["Topic clustering"]
  node_story_difficulty["Difficulty levels"]
  node_story_catalog["Story catalog<br/>[stories_final.json]"]
end

subgraph group_photo["Photo Missions"]
  node_photo_routes["Image endpoints"]
  node_image_prepare["Image validation"]
  node_cnn_model["Residual CNN"]
  node_cnn_checkpoint["CNN checkpoint<br/>[best_model.pth]"]
  node_photo_result["Class and theme"]
end

node_parent(("Parent / app client"))

node_parent -->|"sends requests"| node_api_app
node_api_app -->|"mounts router"| node_word_routes
node_api_app -->|"mounts router"| node_photo_routes
node_parent -.->|"imports catalog"| node_story_catalog
node_word_routes -->|"extracts features"| node_word_features
node_word_routes -->|"predicts AoA"| node_word_regressor
node_word_routes -->|"categorizes estimate"| node_word_category
node_word_routes -->|"loads artifact"| node_word_artifact
node_word_training -->|"exports model"| node_word_artifact
node_photo_routes -->|"validates upload"| node_image_prepare
node_photo_routes -->|"classifies image"| node_cnn_model
node_photo_routes -->|"loads checkpoint"| node_cnn_checkpoint
node_photo_routes -->|"returns labels"| node_photo_result
node_story_pipeline -->|"reads stories"| node_story_source
node_story_pipeline -->|"clusters topics"| node_story_topics
node_story_pipeline -.->|"assigns levels"| node_story_difficulty
node_story_pipeline -.->|"exports catalog"| node_story_catalog

click node_api_app "https://github.com/dkim0048/tp10_ai/blob/main/main.py"
click node_word_routes "https://github.com/dkim0048/tp10_ai/blob/main/routers/word_difficulty.py"
click node_word_features "https://github.com/dkim0048/tp10_ai/blob/main/routers/word_difficulty.py"
click node_word_regressor "https://github.com/dkim0048/tp10_ai/blob/main/routers/word_difficulty.py"
click node_word_category "https://github.com/dkim0048/tp10_ai/blob/main/routers/word_difficulty.py"
click node_word_artifact "https://github.com/dkim0048/tp10_ai/blob/main/word_difficulty_model/model/word_difficulty_model.json"
click node_word_training "https://github.com/dkim0048/tp10_ai/blob/main/word_difficulty_model/src/Ridge_Regression.py"
click node_story_source "https://github.com/dkim0048/tp10_ai/blob/main/library_clustering/data/GlotStoryBook.csv"
click node_story_pipeline "https://github.com/dkim0048/tp10_ai/blob/main/library_clustering/src/document_clustering.py"
click node_story_topics "https://github.com/dkim0048/tp10_ai/blob/main/library_clustering/src/document_clustering.py"
click node_story_difficulty "https://github.com/dkim0048/tp10_ai/blob/main/library_clustering/src/document_clustering.py"
click node_story_catalog "https://github.com/dkim0048/tp10_ai/blob/main/library_clustering/outputs/stories_final.json"
click node_photo_routes "https://github.com/dkim0048/tp10_ai/blob/main/routers/image_classification.py"
click node_image_prepare "https://github.com/dkim0048/tp10_ai/blob/main/routers/image_classification.py"
click node_cnn_model "https://github.com/dkim0048/tp10_ai/blob/main/routers/image_classification.py"
click node_cnn_checkpoint "https://github.com/dkim0048/tp10_ai/blob/main/photo_mission_image_classification/cnn/model/best_model.pth"
click node_photo_result "https://github.com/dkim0048/tp10_ai/blob/main/routers/image_classification.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_api_app,node_parent toneBlue
class node_word_routes,node_word_features,node_word_regressor,node_word_category,node_word_artifact,node_word_training toneAmber
class node_story_source,node_story_pipeline,node_story_topics,node_story_difficulty,node_story_catalog toneMint
class node_photo_routes,node_image_prepare,node_cnn_model,node_cnn_checkpoint,node_photo_result toneRose
```

## Components

### Inference API

- [FastAPI app](https://github.com/dkim0048/tp10_ai/blob/main/main.py): `main.py`

### Word Difficulty

- [Word endpoints](https://github.com/dkim0048/tp10_ai/blob/main/routers/word_difficulty.py): `routers/word_difficulty.py`
- [Word features](https://github.com/dkim0048/tp10_ai/blob/main/routers/word_difficulty.py): `routers/word_difficulty.py`
- [AoA prediction](https://github.com/dkim0048/tp10_ai/blob/main/routers/word_difficulty.py): `routers/word_difficulty.py`
- [Support category](https://github.com/dkim0048/tp10_ai/blob/main/routers/word_difficulty.py): `routers/word_difficulty.py`
- [Trained AoA model](https://github.com/dkim0048/tp10_ai/blob/main/word_difficulty_model/model/word_difficulty_model.json): `word_difficulty_model/model/word_difficulty_model.json`
- [Ridge training](https://github.com/dkim0048/tp10_ai/blob/main/word_difficulty_model/src/Ridge_Regression.py): `word_difficulty_model/src/Ridge_Regression.py`

### Reading Library

- [Story dataset](https://github.com/dkim0048/tp10_ai/blob/main/library_clustering/data/GlotStoryBook.csv): `library_clustering/data/GlotStoryBook.csv`
- [Filter and combine stories](https://github.com/dkim0048/tp10_ai/blob/main/library_clustering/src/document_clustering.py): `library_clustering/src/document_clustering.py`
- [Topic clustering](https://github.com/dkim0048/tp10_ai/blob/main/library_clustering/src/document_clustering.py): `library_clustering/src/document_clustering.py`
- [Difficulty levels](https://github.com/dkim0048/tp10_ai/blob/main/library_clustering/src/document_clustering.py): `library_clustering/src/document_clustering.py`
- [Story catalog](https://github.com/dkim0048/tp10_ai/blob/main/library_clustering/outputs/stories_final.json): `library_clustering/outputs/stories_final.json`

### Photo Missions

- [Image endpoints](https://github.com/dkim0048/tp10_ai/blob/main/routers/image_classification.py): `routers/image_classification.py`
- [Image validation](https://github.com/dkim0048/tp10_ai/blob/main/routers/image_classification.py): `routers/image_classification.py`
- [Residual CNN](https://github.com/dkim0048/tp10_ai/blob/main/routers/image_classification.py): `routers/image_classification.py`
- [CNN checkpoint](https://github.com/dkim0048/tp10_ai/blob/main/photo_mission_image_classification/cnn/model/best_model.pth): `photo_mission_image_classification/cnn/model/best_model.pth`
- [Class and theme](https://github.com/dkim0048/tp10_ai/blob/main/routers/image_classification.py): `routers/image_classification.py`

### Other components

- **Parent / app client**

## Connections

- Parent / app client → FastAPI app: sends requests (evidence: `README.md`)
- FastAPI app → Word endpoints: mounts router (evidence: `main.py`)
- FastAPI app → Image endpoints: mounts router (evidence: `main.py`)
- Parent / app client → Story catalog: imports catalog (evidence: `README.md`)
- Word endpoints → Word features: extracts features (evidence: `routers/word_difficulty.py`)
- Word endpoints → AoA prediction: predicts AoA (evidence: `routers/word_difficulty.py`)
- Word endpoints → Support category: categorizes estimate (evidence: `routers/word_difficulty.py`)
- Word endpoints → Trained AoA model: loads artifact (evidence: `routers/word_difficulty.py`)
- Ridge training → Trained AoA model: exports model (evidence: `README.md`)
- Image endpoints → Image validation: validates upload (evidence: `routers/image_classification.py`)
- Image endpoints → Residual CNN: classifies image (evidence: `routers/image_classification.py`)
- Image endpoints → CNN checkpoint: loads checkpoint (evidence: `routers/image_classification.py`)
- Image endpoints → Class and theme: returns labels (evidence: `routers/image_classification.py`)
- Filter and combine stories → Story dataset: reads stories (evidence: `library_clustering/src/document_clustering.py`)
- Filter and combine stories → Topic clustering: clusters topics (evidence: `library_clustering/src/document_clustering.py`)
- Filter and combine stories → Difficulty levels: assigns levels (evidence: `README.md`)
- Filter and combine stories → Story catalog: exports catalog (evidence: `README.md`)
