# diegobejar1011/service-ocr architecture

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

- Interactive diagram: https://gitdiagram.com/diegobejar1011/service-ocr
- Repository: https://github.com/diegobejar1011/service-ocr

## Overview

This is a FastAPI service for evaluating handwriting exercises from an uploaded image against a target sentence. The workflow accepts an image and sentence, preprocesses the image, extracts Spanish text and OCR confidence, then combines confidence with sentence similarity into a score. The graph reflects the sampled runtime code; the request model is imported but not used in the shown route, and no README capabilities are documented.

Main entry points: [`features/text_evaluator/services/evaluate_text_from_image_service.py`](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/services/evaluate_text_from_image_service.py) (Evaluation service), [`features/text_evaluator/application/text_evaluator_di.py`](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/application/text_evaluator_di.py) (Dependency wiring), [`features/text_evaluator/controllers/evaluate_text_controller.py`](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/controllers/evaluate_text_controller.py) (Request controller), [`features/text_evaluator/data/repositories/cv2_improve_image.py`](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/data/repositories/cv2_improve_image.py) (OpenCV preprocessing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API"]
  node_app["FastAPI app<br/>[main.py]"]
  node_route["Evaluate route"]
  node_controller["Request controller"]
  node_di["Dependency wiring"]
end

subgraph group_evaluation["Evaluation"]
  node_service["Evaluation service"]
  node_imagefile["Temporary image"]
  node_improve_contract["Image improvement contract"]
  node_extract_contract["Text extraction contract"]
  node_similarity_contract["Similarity contract"]
  node_response["Evaluation result"]
end

subgraph group_adapters["Data adapters"]
  node_cv2["OpenCV preprocessing"]
  node_easyocr["EasyOCR extraction"]
  node_levenshtein["Levenshtein similarity"]
end

node_writer(("Client"))

node_writer -->|"uploads image"| node_route
node_app -->|"registers"| node_route
node_route -->|"dispatches"| node_controller
node_controller -->|"calls"| node_service
node_controller -->|"returns result"| node_writer
node_di -->|"constructs"| node_controller
node_di -->|"constructs"| node_service
node_di -->|"instantiates"| node_cv2
node_di -->|"instantiates"| node_easyocr
node_di -->|"instantiates"| node_levenshtein
node_service -->|"writes and removes"| node_imagefile
node_service -->|"calls"| node_cv2
node_service -->|"calls"| node_easyocr
node_service -->|"calls"| node_levenshtein
node_cv2 -->|"reads"| node_imagefile
node_service -->|"produces"| node_response
node_cv2 -->|"implements"| node_improve_contract
node_easyocr -->|"implements"| node_extract_contract
node_levenshtein -->|"implements"| node_similarity_contract

click node_app "https://github.com/diegobejar1011/service-ocr/blob/main/main.py"
click node_route "https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/routes/text_evaluate_router.py"
click node_controller "https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/controllers/evaluate_text_controller.py"
click node_di "https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/application/text_evaluator_di.py"
click node_service "https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/services/evaluate_text_from_image_service.py"
click node_imagefile "https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/services/evaluate_text_from_image_service.py"
click node_improve_contract "https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/domain/repositories/improve_image_repository.py"
click node_extract_contract "https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/domain/repositories/extract_text_repository.py"
click node_similarity_contract "https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/domain/repositories/calculate_similarity_repository.py"
click node_cv2 "https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/data/repositories/cv2_improve_image.py"
click node_easyocr "https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/data/repositories/easyocr_text_impl.py"
click node_levenshtein "https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/data/repositories/levenshtein_similarity_impl.py"
click node_response "https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/services/evaluate_text_from_image_service.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_app,node_route,node_controller,node_di,node_writer toneBlue
class node_service,node_imagefile,node_improve_contract,node_extract_contract,node_similarity_contract,node_response toneAmber
class node_cv2,node_easyocr,node_levenshtein toneMint
```

## Components

### API

- [FastAPI app](https://github.com/diegobejar1011/service-ocr/blob/main/main.py): `main.py`
- [Evaluate route](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/routes/text_evaluate_router.py): `features/text_evaluator/routes/text_evaluate_router.py`
- [Request controller](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/controllers/evaluate_text_controller.py): `features/text_evaluator/controllers/evaluate_text_controller.py`
- [Dependency wiring](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/application/text_evaluator_di.py): `features/text_evaluator/application/text_evaluator_di.py`

### Evaluation

- [Evaluation service](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/services/evaluate_text_from_image_service.py): `features/text_evaluator/services/evaluate_text_from_image_service.py`
- [Temporary image](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/services/evaluate_text_from_image_service.py): `features/text_evaluator/services/evaluate_text_from_image_service.py`
- [Image improvement contract](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/domain/repositories/improve_image_repository.py): `features/text_evaluator/domain/repositories/improve_image_repository.py`
- [Text extraction contract](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/domain/repositories/extract_text_repository.py): `features/text_evaluator/domain/repositories/extract_text_repository.py`
- [Similarity contract](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/domain/repositories/calculate_similarity_repository.py): `features/text_evaluator/domain/repositories/calculate_similarity_repository.py`
- [Evaluation result](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/services/evaluate_text_from_image_service.py): `features/text_evaluator/services/evaluate_text_from_image_service.py`

### Data adapters

- [OpenCV preprocessing](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/data/repositories/cv2_improve_image.py): `features/text_evaluator/data/repositories/cv2_improve_image.py`
- [EasyOCR extraction](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/data/repositories/easyocr_text_impl.py): `features/text_evaluator/data/repositories/easyocr_text_impl.py`
- [Levenshtein similarity](https://github.com/diegobejar1011/service-ocr/blob/main/features/text_evaluator/data/repositories/levenshtein_similarity_impl.py): `features/text_evaluator/data/repositories/levenshtein_similarity_impl.py`

### Other components

- **Client**

## Connections

- Client → Evaluate route: uploads image
- FastAPI app → Evaluate route: registers
- Evaluate route → Request controller: dispatches
- Request controller → Evaluation service: calls
- Request controller → Client: returns result
- Dependency wiring → Request controller: constructs
- Dependency wiring → Evaluation service: constructs
- Dependency wiring → OpenCV preprocessing: instantiates
- Dependency wiring → EasyOCR extraction: instantiates
- Dependency wiring → Levenshtein similarity: instantiates
- Evaluation service → Temporary image: writes and removes
- Evaluation service → OpenCV preprocessing: calls
- Evaluation service → EasyOCR extraction: calls
- Evaluation service → Levenshtein similarity: calls
- OpenCV preprocessing → Temporary image: reads
- Evaluation service → Evaluation result: produces
- OpenCV preprocessing → Image improvement contract: implements
- EasyOCR extraction → Text extraction contract: implements
- Levenshtein similarity → Similarity contract: implements
