# shoaibrhman/week8 architecture

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

- Interactive diagram: https://gitdiagram.com/shoaibrhman/week8
- Repository: https://github.com/shoaibrhman/week8

## Overview

Week 8 is a FastAPI crop-disease decision-support API combining image classification with farmer-note analysis. Farmers can request an image-only prediction or submit an image and note for a case assessment. At startup, the API loads a checkpoint and prepares the model and image transforms. The case route authenticates and validates input, classifies the image, masks personal identifiers, extracts note fields and urgent terms, then decides whether to refer the case. The sampled implementation is all in app.py; external model-artifact handling is shown only as configured loading.

Main entry points: [`week8/app.py`](https://github.com/shoaibrhman/week8/blob/main/week8/app.py) (FastAPI routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API access"]
  node_api["FastAPI routes<br/>[app.py]"]
  node_auth["API-key check<br/>[app.py]"]
  node_upload["Image validation<br/>[app.py]"]
end

subgraph group_vision["Image classification"]
  node_lifecycle["Model startup<br/>[app.py]"]
  node_rebuild["Model rebuild<br/>[app.py]"]
  node_preprocess["Image transforms<br/>[app.py]"]
  node_classifier["Image classifier<br/>[app.py]"]
  node_prediction["Prediction<br/>[app.py]"]
end

subgraph group_notes["Case assessment"]
  node_mask["PII masking<br/>[app.py]"]
  node_fields["Field extraction<br/>[app.py]"]
  node_urgent["Urgent-term scan<br/>[app.py]"]
  node_decision["Referral decision<br/>[app.py]"]
  node_case["Case record<br/>[app.py]"]
end

node_farmer(("Farmer"))
node_artifact["Model checkpoint"]

node_farmer -->|"submits request"| node_api
node_api -->|"checks key"| node_auth
node_api -->|"reads image"| node_upload
node_lifecycle -->|"loads checkpoint"| node_artifact
node_lifecycle -->|"rebuilds model"| node_rebuild
node_lifecycle -->|"configures transforms"| node_preprocess
node_upload -->|"passes image"| node_classifier
node_classifier -->|"transforms image"| node_preprocess
node_classifier -->|"returns prediction"| node_prediction
node_api -->|"returns prediction"| node_prediction
node_api -->|"masks note"| node_mask
node_mask -->|"extracts fields"| node_fields
node_mask -->|"scans terms"| node_urgent
node_api -->|"assesses disease risk"| node_decision
node_api -->|"assembles case"| node_case
node_fields -->|"supplies fields"| node_case
node_urgent -->|"supplies terms"| node_case
node_decision -->|"sets referral"| node_case
node_prediction -->|"included in case"| node_case
node_api -->|"returns result"| node_farmer

click node_api "https://github.com/shoaibrhman/week8/blob/main/week8/app.py"
click node_auth "https://github.com/shoaibrhman/week8/blob/main/week8/app.py"
click node_upload "https://github.com/shoaibrhman/week8/blob/main/week8/app.py"
click node_lifecycle "https://github.com/shoaibrhman/week8/blob/main/week8/app.py"
click node_rebuild "https://github.com/shoaibrhman/week8/blob/main/week8/app.py"
click node_preprocess "https://github.com/shoaibrhman/week8/blob/main/week8/app.py"
click node_classifier "https://github.com/shoaibrhman/week8/blob/main/week8/app.py"
click node_prediction "https://github.com/shoaibrhman/week8/blob/main/week8/app.py"
click node_mask "https://github.com/shoaibrhman/week8/blob/main/week8/app.py"
click node_fields "https://github.com/shoaibrhman/week8/blob/main/week8/app.py"
click node_urgent "https://github.com/shoaibrhman/week8/blob/main/week8/app.py"
click node_decision "https://github.com/shoaibrhman/week8/blob/main/week8/app.py"
click node_case "https://github.com/shoaibrhman/week8/blob/main/week8/app.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,node_auth,node_upload toneBlue
class node_lifecycle,node_rebuild,node_preprocess,node_classifier,node_prediction toneAmber
class node_mask,node_fields,node_urgent,node_decision,node_case toneMint
class node_farmer,node_artifact toneIndigo
```

## Components

### API access

- [FastAPI routes](https://github.com/shoaibrhman/week8/blob/main/week8/app.py): `week8/app.py`
- [API-key check](https://github.com/shoaibrhman/week8/blob/main/week8/app.py): `week8/app.py`
- [Image validation](https://github.com/shoaibrhman/week8/blob/main/week8/app.py): `week8/app.py`

### Image classification

- [Model startup](https://github.com/shoaibrhman/week8/blob/main/week8/app.py): `week8/app.py`
- [Model rebuild](https://github.com/shoaibrhman/week8/blob/main/week8/app.py): `week8/app.py`
- [Image transforms](https://github.com/shoaibrhman/week8/blob/main/week8/app.py): `week8/app.py`
- [Image classifier](https://github.com/shoaibrhman/week8/blob/main/week8/app.py): `week8/app.py`
- [Prediction](https://github.com/shoaibrhman/week8/blob/main/week8/app.py): `week8/app.py`

### Case assessment

- [PII masking](https://github.com/shoaibrhman/week8/blob/main/week8/app.py): `week8/app.py`
- [Field extraction](https://github.com/shoaibrhman/week8/blob/main/week8/app.py): `week8/app.py`
- [Urgent-term scan](https://github.com/shoaibrhman/week8/blob/main/week8/app.py): `week8/app.py`
- [Referral decision](https://github.com/shoaibrhman/week8/blob/main/week8/app.py): `week8/app.py`
- [Case record](https://github.com/shoaibrhman/week8/blob/main/week8/app.py): `week8/app.py`

### Other components

- **Farmer**
- **Model checkpoint**

## Connections

- Farmer → FastAPI routes: submits request (evidence: `week8/app.py`)
- FastAPI routes → API-key check: checks key (evidence: `week8/app.py`)
- FastAPI routes → Image validation: reads image (evidence: `week8/app.py`)
- Model startup → Model checkpoint: loads checkpoint (evidence: `week8/app.py`)
- Model startup → Model rebuild: rebuilds model (evidence: `week8/app.py`)
- Model startup → Image transforms: configures transforms (evidence: `week8/app.py`)
- Image validation → Image classifier: passes image (evidence: `week8/app.py`)
- Image classifier → Image transforms: transforms image (evidence: `week8/app.py`)
- Image classifier → Prediction: returns prediction (evidence: `week8/app.py`)
- FastAPI routes → Prediction: returns prediction (evidence: `week8/app.py`)
- FastAPI routes → PII masking: masks note (evidence: `week8/app.py`)
- PII masking → Field extraction: extracts fields (evidence: `week8/app.py`)
- PII masking → Urgent-term scan: scans terms (evidence: `week8/app.py`)
- FastAPI routes → Referral decision: assesses disease risk (evidence: `week8/app.py`)
- FastAPI routes → Case record: assembles case (evidence: `week8/app.py`)
- Field extraction → Case record: supplies fields (evidence: `week8/app.py`)
- Urgent-term scan → Case record: supplies terms (evidence: `week8/app.py`)
- Referral decision → Case record: sets referral (evidence: `week8/app.py`)
- Prediction → Case record: included in case (evidence: `week8/app.py`)
- FastAPI routes → Farmer: returns result (evidence: `week8/app.py`)
