# andersonmaina/facs architecture

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

- Interactive diagram: https://gitdiagram.com/andersonmaina/facs
- Repository: https://github.com/andersonmaina/facs

## Overview

FACS is a Flask-based ultrasound image anomaly-analysis service, with separate scripts and artifacts for preparing normal-image features and training category-specific autoencoders. The main user flow accepts an annotated image from a PC or Telegram client, preprocesses it, runs inference, and returns an anomaly score and diagnosis. Source excerpts establish the API-to-model call and model selection/inference; some crop and response details are visible only in partial excerpts, and no README was provided.

Main entry points: [`app.py`](https://github.com/andersonmaina/facs/blob/main/app.py) (Annotation API), [`model.py`](https://github.com/andersonmaina/facs/blob/main/model.py) (Prediction Pipeline), [`feature_extractor.py`](https://github.com/andersonmaina/facs/blob/main/feature_extractor.py) (Feature Extraction), [`train_autoencoder.py`](https://github.com/andersonmaina/facs/blob/main/train_autoencoder.py) (Autoencoder Training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and Results"]
  node_api_handler["Annotation API<br/>[app.py]"]
  node_image_prep["Image Decode and Crop<br/>[app.py]"]
  node_results["Score and Diagnosis<br/>[app.py]"]
end

subgraph group_inference["Anomaly Inference"]
  node_predict["Prediction Pipeline<br/>[model.py]"]
  node_model_select["View and Category Models<br/>[model.py]"]
  node_resnet["ResNet Features<br/>[model.py]"]
  node_autoencoder["Reconstruction and Error<br/>[model.py]"]
  node_weights[("Trained Weights")]
end

subgraph group_preparation["Feature Preparation"]
  node_feature_extractor["Feature Extraction"]
  node_feature_files[("Normal Feature Arrays")]
end

subgraph group_training["Model Training"]
  node_trainer["Autoencoder Training"]
end

node_pc(("PC Client"))
node_telegram(("Telegram Client"))
node_normal_images[("Annotated Images")]

node_pc -->|"submits annotation"| node_api_handler
node_telegram -->|"uploads image"| node_api_handler
node_api_handler -->|"decodes and crops"| node_image_prep
node_api_handler -->|"calls predict"| node_predict
node_predict -->|"selects weights"| node_model_select
node_model_select -->|"loads state"| node_weights
node_predict -->|"extracts features"| node_resnet
node_predict -->|"reconstructs features"| node_autoencoder
node_autoencoder -->|"returns error"| node_predict
node_api_handler -->|"builds response"| node_results
node_feature_extractor -->|"reads images"| node_normal_images
node_feature_extractor -->|"saves features"| node_feature_files
node_trainer -->|"loads features"| node_feature_files
node_trainer -->|"saves weights"| node_weights

click node_api_handler "https://github.com/andersonmaina/facs/blob/main/app.py"
click node_image_prep "https://github.com/andersonmaina/facs/blob/main/app.py"
click node_results "https://github.com/andersonmaina/facs/blob/main/app.py"
click node_predict "https://github.com/andersonmaina/facs/blob/main/model.py"
click node_model_select "https://github.com/andersonmaina/facs/blob/main/model.py"
click node_resnet "https://github.com/andersonmaina/facs/blob/main/model.py"
click node_autoencoder "https://github.com/andersonmaina/facs/blob/main/model.py"
click node_weights "https://github.com/andersonmaina/facs/tree/main/models"
click node_feature_extractor "https://github.com/andersonmaina/facs/blob/main/feature_extractor.py"
click node_feature_files "https://github.com/andersonmaina/facs/tree/main/features"
click node_trainer "https://github.com/andersonmaina/facs/blob/main/train_autoencoder.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_handler,node_image_prep,node_results,node_pc,node_telegram toneBlue
class node_predict,node_model_select,node_resnet,node_autoencoder,node_weights,node_normal_images toneAmber
class node_feature_extractor,node_feature_files toneMint
class node_trainer toneRose
```

## Components

### API and Results

- [Annotation API](https://github.com/andersonmaina/facs/blob/main/app.py): `app.py`
- [Image Decode and Crop](https://github.com/andersonmaina/facs/blob/main/app.py): `app.py`
- [Score and Diagnosis](https://github.com/andersonmaina/facs/blob/main/app.py): `app.py`

### Anomaly Inference

- [Prediction Pipeline](https://github.com/andersonmaina/facs/blob/main/model.py): `model.py`
- [View and Category Models](https://github.com/andersonmaina/facs/blob/main/model.py): `model.py`
- [ResNet Features](https://github.com/andersonmaina/facs/blob/main/model.py): `model.py`
- [Reconstruction and Error](https://github.com/andersonmaina/facs/blob/main/model.py): `model.py`
- [Trained Weights](https://github.com/andersonmaina/facs/tree/main/models): `models`

### Feature Preparation

- [Feature Extraction](https://github.com/andersonmaina/facs/blob/main/feature_extractor.py): `feature_extractor.py`
- [Normal Feature Arrays](https://github.com/andersonmaina/facs/tree/main/features): `features`

### Model Training

- [Autoencoder Training](https://github.com/andersonmaina/facs/blob/main/train_autoencoder.py): `train_autoencoder.py`

### Other components

- **PC Client**
- **Telegram Client**
- **Annotated Images**

## Connections

- PC Client → Annotation API: submits annotation (evidence: `app.py`)
- Telegram Client → Annotation API: uploads image (evidence: `app.py`)
- Annotation API → Image Decode and Crop: decodes and crops (evidence: `app.py`)
- Annotation API → Prediction Pipeline: calls predict (evidence: `app.py`)
- Prediction Pipeline → View and Category Models: selects weights (evidence: `model.py`)
- View and Category Models → Trained Weights: loads state (evidence: `model.py`)
- Prediction Pipeline → ResNet Features: extracts features (evidence: `model.py`)
- Prediction Pipeline → Reconstruction and Error: reconstructs features (evidence: `model.py`)
- Reconstruction and Error → Prediction Pipeline: returns error (evidence: `model.py`)
- Annotation API → Score and Diagnosis: builds response (evidence: `app.py`)
- Feature Extraction → Annotated Images: reads images (evidence: `feature_extractor.py`)
- Feature Extraction → Normal Feature Arrays: saves features (evidence: `feature_extractor.py`)
- Autoencoder Training → Normal Feature Arrays: loads features (evidence: `train_autoencoder.py`)
- Autoencoder Training → Trained Weights: saves weights (evidence: `train_autoencoder.py`)
