# kaz-py/deteccion-de-caidas architecture

> Architecture diagram of the GitHub repository kaz-py/deteccion-de-caidas, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kaz-py/deteccion-de-caidas
- Repository: https://github.com/kaz-py/deteccion-de-caidas

## Overview

#### Purpose and Entry Point

This is a local, real-time fall-detection program. It captures frames from the computer camera, applies Ultralytics YOLO person detection through OpenCV processing, and displays the live result until the user presses `q`.

Primary executable entry point:
- `src/deteccion_de_caidas/deteccion.py`

The package namespace is:
- `src/deteccion_de_caidas/__init__.py`

#### Runtime and Dependency Boundary

The application runs on Python 3.12+ and is managed with `uv`; resolved dependency versions are captured in:
- `pyproject.toml`
- `uv.lock`

It depends materially on:
- OpenCV for camera access, frame handling, visualization, and keyboard input.
- Ultralytics YOLO for object/person inference.
- A locally available camera device.

There is no indicated server, database, browser client, cloud service, or persistent storage boundary.

#### Camera Capture Stage

The detection loop begins by opening the default local camera and repeatedly reading image frames. Camera availability is an operational prerequisite; failure to access it prevents live inference.

This hardware/OS boundary is implemented in:
- `src/deteccion_de_caidas/deteccion.py`

Frames flow in-memory from the camera directly into the model-processing stage rather than through files or network transport.

#### YOLO Inference Stage

Each captured frame is passed to an Ultralytics YOLO model. The model produces detections, including bounding-box geometry and class/confidence metadata used by the fall-detection decision logic.

The inference integration and frame-level orchestration reside in:
- `src/deteccion_de_caidas/deteccion.py`

Model loading is a key startup boundary: its weights may need to be available locally or be obtained by the Ultralytics runtime, depending on the implementation.

#### Fall Classification Logic

The core domain decision is derived from detected person geometry: the program distinguishes a potential fall using the dimensions/orientation of a detected bounding box, rather than a temporal pose-tracking pipeline.

This means the decision is frame-local and heuristic-driven; it does not imply identity tracking, event persistence, alert delivery, or video recording.

Core logic location:
- `src/deteccion_de_caidas/deteccion.py`

#### Visualization and User Control

Processed frames are annotated and rendered in an OpenCV display window so the operator can observe detections and fall status in real time. The same loop listens for the `q` key as its explicit shutdown control.

UI/output and lifecycle handling are in:
- `src/deteccion_de_caidas/deteccion.py`

On exit, the application should release the camera and close OpenCV windows, returning control to the terminal.

#### Control Flow Summary

1. Start the Python script through `uv`.
2. Initialize YOLO and open the local camera.
3. Read one frame at a time.
4. Run YOLO inference on the frame.
5. Evaluate person-box geometry for a fall condition.
6. Draw/display results.
7. Continue until `q`, then clean up camera/display resources.

The repository is intentionally compact: nearly all application architecture is concentrated in:
- `src/deteccion_de_caidas/deteccion.py`

Main entry points: [`src/deteccion_de_caidas/deteccion.py`](https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py) (Frame capture), [`pyproject.toml`](https://github.com/kaz-py/deteccion-de-caidas/blob/master/pyproject.toml) (Dependencies), [`src/deteccion_de_caidas/__init__.py`](https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/__init__.py) (Package namespace), [`uv.lock`](https://github.com/kaz-py/deteccion-de-caidas/blob/master/uv.lock) (Resolved lockfile)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Local runtime"]
  node_entry["Detection executable<br/>Python entry point<br/>[deteccion.py]"]
  node_package["Package namespace<br/>Python package<br/>[__init__.py]"]
  node_dependencies["Dependencies<br/>uv project<br/>[pyproject.toml]"]
  node_lockfile["Resolved lockfile<br/>uv lockfile<br/>[uv.lock]"]
end

subgraph group_pipeline["Live detection loop"]
  node_camera{{"Local camera<br/>hardware device"}}
  node_capture["Frame capture<br/>OpenCV capture<br/>[deteccion.py]"]
  node_model["YOLO model<br/>Ultralytics inference<br/>[deteccion.py]"]
  node_detections["Person boxes<br/>frame detections<br/>[deteccion.py]"]
  node_fall_logic["Fall heuristic<br/>geometry classifier<br/>[deteccion.py]"]
  node_display["Annotated display<br/>OpenCV window<br/>[deteccion.py]"]
  node_keyboard["q shutdown control<br/>OpenCV keyboard input<br/>[deteccion.py]"]
  node_cleanup["Resource cleanup<br/>lifecycle handling<br/>[deteccion.py]"]
end

node_dependencies -->|"defines runtime"| node_entry
node_lockfile -->|"resolves versions"| node_dependencies
node_package -->|"contains"| node_entry
node_entry -->|"opens"| node_camera
node_camera -->|"frames"| node_capture
node_capture -->|"frame"| node_model
node_model -->|"inference output"| node_detections
node_detections -->|"box geometry"| node_fall_logic
node_fall_logic -->|"annotations and status"| node_display
node_capture -->|"source frame"| node_display
node_display -->|"polls input"| node_keyboard
node_keyboard -->|"q exits loop"| node_cleanup
node_cleanup -->|"releases"| node_camera

click node_entry "https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py"
click node_package "https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/__init__.py"
click node_dependencies "https://github.com/kaz-py/deteccion-de-caidas/blob/master/pyproject.toml"
click node_lockfile "https://github.com/kaz-py/deteccion-de-caidas/blob/master/uv.lock"
click node_capture "https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py"
click node_model "https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py"
click node_detections "https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py"
click node_fall_logic "https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py"
click node_display "https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py"
click node_keyboard "https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py"
click node_cleanup "https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.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_entry,node_package,node_dependencies,node_lockfile toneBlue
class node_camera,node_capture,node_model,node_detections,node_fall_logic,node_display,node_keyboard,node_cleanup toneAmber
```

## Components

### Local runtime

- [Detection executable](https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py): Python entry point · Starts initialization and the live frame loop. · `src/deteccion_de_caidas/deteccion.py`
- [Package namespace](https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/__init__.py): Python package · `src/deteccion_de_caidas/__init__.py`
- [Dependencies](https://github.com/kaz-py/deteccion-de-caidas/blob/master/pyproject.toml): uv project · Pins Python, OpenCV, and Ultralytics dependencies. · `pyproject.toml`
- [Resolved lockfile](https://github.com/kaz-py/deteccion-de-caidas/blob/master/uv.lock): uv lockfile · `uv.lock`

### Live detection loop

- **Local camera**: hardware device · Default camera supplies in-memory frames.
- [Frame capture](https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py): OpenCV capture · `src/deteccion_de_caidas/deteccion.py`
- [YOLO model](https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py): Ultralytics inference · Loads weights and produces person detections. · `src/deteccion_de_caidas/deteccion.py`
- [Person boxes](https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py): frame detections · Bounding boxes include geometry, class, and confidence. · `src/deteccion_de_caidas/deteccion.py`
- [Fall heuristic](https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py): geometry classifier · Classifies a potential fall from person-box orientation and dimensions. · `src/deteccion_de_caidas/deteccion.py`
- [Annotated display](https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py): OpenCV window · Renders live detections and fall status. · `src/deteccion_de_caidas/deteccion.py`
- [q shutdown control](https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py): OpenCV keyboard input · Ends the loop when q is pressed. · `src/deteccion_de_caidas/deteccion.py`
- [Resource cleanup](https://github.com/kaz-py/deteccion-de-caidas/blob/master/src/deteccion_de_caidas/deteccion.py): lifecycle handling · Releases camera and closes display windows. · `src/deteccion_de_caidas/deteccion.py`

## Connections

- Dependencies → Detection executable: defines runtime
- Resolved lockfile → Dependencies: resolves versions
- Package namespace → Detection executable: contains
- Detection executable → Local camera: opens
- Local camera → Frame capture: frames
- Frame capture → YOLO model: frame
- YOLO model → Person boxes: inference output
- Person boxes → Fall heuristic: box geometry
- Fall heuristic → Annotated display: annotations and status
- Frame capture → Annotated display: source frame
- Annotated display → q shutdown control: polls input
- q shutdown control → Resource cleanup: q exits loop
- Resource cleanup → Local camera: releases
