# arenan02/object-counter architecture

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

- Interactive diagram: https://gitdiagram.com/arenan02/object-counter
- Repository: https://github.com/arenan02/object-counter

## Overview

This Flask object-counter accepts an uploaded image and confidence threshold, obtains detections, filters and counts them, updates cumulative counts, and returns current and total counts. The CLI offers a separate invocation of the same domain action. Configuration selects fake in-memory adapters or real TensorFlow Serving and MongoDB adapters. The graph follows the sampled calls and README-described service boundaries; the internals of unsampled resources and integrations are not inferred beyond the documented or visible connections.

Main entry points: [`counter/domain/actions.py`](https://github.com/arenan02/object-counter/blob/main/counter/domain/actions.py) (Count Action), [`counter/config.py`](https://github.com/arenan02/object-counter/blob/main/counter/config.py) (Adapter Configuration), [`counter/domain/models.py`](https://github.com/arenan02/object-counter/blob/main/counter/domain/models.py) (Domain Models), [`counter/adapters/object_detector.py`](https://github.com/arenan02/object-counter/blob/main/counter/adapters/object_detector.py) (TensorFlow Detector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entrypoints"]
  node_webapp["Flask API<br/>[webapp.py]"]
  node_cli["CLI Runner<br/>[main.py]"]
end

subgraph group_domain["Counting Domain"]
  node_action["Count Action<br/>[actions.py]"]
  node_prediction_rules["Filter and Count<br/>[predictions.py]"]
  node_models["Domain Models<br/>[models.py]"]
  node_ports["Adapter Ports<br/>[ports.py]"]
  node_debug["Debug Image Output<br/>[debug.py]"]
end

subgraph group_adapters["External Adapters"]
  node_config["Adapter Configuration<br/>[config.py]"]
  node_fake_detector["Fake Detector<br/>[object_detector.py]"]
  node_tf_detector["TensorFlow Detector<br/>[object_detector.py]"]
  node_memory_repo[("In-Memory Counts<br/>[count_repo.py]")]
  node_mongo_repo[("Mongo Counts<br/>[count_repo.py]")]
end

node_client(("API Client"))
node_tf_serving["TensorFlow Serving"]
node_mongodb[("MongoDB")]

node_client -->|"uploads image"| node_webapp
node_webapp -->|"gets action"| node_config
node_webapp -->|"executes count"| node_action
node_cli -->|"gets action"| node_config
node_cli -->|"executes count"| node_action
node_config -->|"constructs"| node_action
node_config -->|"selects in dev"| node_fake_detector
node_config -->|"selects in dev"| node_memory_repo
node_config -->|"selects in prod"| node_tf_detector
node_config -->|"selects in prod"| node_mongo_repo
node_action -.->|"predicts via port"| node_tf_detector
node_action -->|"filters and counts"| node_prediction_rules
node_action -->|"draws debug images"| node_debug
node_action -.->|"updates and reads"| node_memory_repo
node_action -.->|"updates and reads"| node_mongo_repo
node_action -->|"builds response"| node_models
node_prediction_rules -->|"uses domain types"| node_models
node_fake_detector -->|"returns predictions"| node_models
node_tf_detector -->|"maps predictions"| node_models
node_tf_detector -->|"requests predictions"| node_tf_serving
node_memory_repo -->|"stores counts"| node_models
node_mongo_repo -->|"maps counts"| node_models
node_mongo_repo -->|"reads and writes"| node_mongodb
node_ports -->|"defines data types"| node_models

click node_webapp "https://github.com/arenan02/object-counter/blob/main/counter/entrypoints/webapp.py"
click node_cli "https://github.com/arenan02/object-counter/blob/main/counter/entrypoints/main.py"
click node_config "https://github.com/arenan02/object-counter/blob/main/counter/config.py"
click node_action "https://github.com/arenan02/object-counter/blob/main/counter/domain/actions.py"
click node_prediction_rules "https://github.com/arenan02/object-counter/blob/main/counter/domain/predictions.py"
click node_models "https://github.com/arenan02/object-counter/blob/main/counter/domain/models.py"
click node_ports "https://github.com/arenan02/object-counter/blob/main/counter/domain/ports.py"
click node_debug "https://github.com/arenan02/object-counter/blob/main/counter/debug.py"
click node_fake_detector "https://github.com/arenan02/object-counter/blob/main/counter/adapters/object_detector.py"
click node_tf_detector "https://github.com/arenan02/object-counter/blob/main/counter/adapters/object_detector.py"
click node_memory_repo "https://github.com/arenan02/object-counter/blob/main/counter/adapters/count_repo.py"
click node_mongo_repo "https://github.com/arenan02/object-counter/blob/main/counter/adapters/count_repo.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_webapp,node_cli,node_client toneBlue
class node_action,node_prediction_rules,node_models,node_ports,node_debug,node_mongodb toneAmber
class node_config,node_fake_detector,node_tf_detector,node_memory_repo,node_mongo_repo toneMint
class node_tf_serving toneIndigo
```

## Components

### Entrypoints

- [Flask API](https://github.com/arenan02/object-counter/blob/main/counter/entrypoints/webapp.py): `counter/entrypoints/webapp.py`
- [CLI Runner](https://github.com/arenan02/object-counter/blob/main/counter/entrypoints/main.py): `counter/entrypoints/main.py`

### Counting Domain

- [Count Action](https://github.com/arenan02/object-counter/blob/main/counter/domain/actions.py): `counter/domain/actions.py`
- [Filter and Count](https://github.com/arenan02/object-counter/blob/main/counter/domain/predictions.py): `counter/domain/predictions.py`
- [Domain Models](https://github.com/arenan02/object-counter/blob/main/counter/domain/models.py): `counter/domain/models.py`
- [Adapter Ports](https://github.com/arenan02/object-counter/blob/main/counter/domain/ports.py): `counter/domain/ports.py`
- [Debug Image Output](https://github.com/arenan02/object-counter/blob/main/counter/debug.py): `counter/debug.py`

### External Adapters

- [Adapter Configuration](https://github.com/arenan02/object-counter/blob/main/counter/config.py): `counter/config.py`
- [Fake Detector](https://github.com/arenan02/object-counter/blob/main/counter/adapters/object_detector.py): `counter/adapters/object_detector.py`
- [TensorFlow Detector](https://github.com/arenan02/object-counter/blob/main/counter/adapters/object_detector.py): `counter/adapters/object_detector.py`
- [In-Memory Counts](https://github.com/arenan02/object-counter/blob/main/counter/adapters/count_repo.py): `counter/adapters/count_repo.py`
- [Mongo Counts](https://github.com/arenan02/object-counter/blob/main/counter/adapters/count_repo.py): `counter/adapters/count_repo.py`

### Other components

- **API Client**
- **TensorFlow Serving**
- **MongoDB**

## Connections

- API Client → Flask API: uploads image (evidence: `README.md`)
- Flask API → Adapter Configuration: gets action (evidence: `counter/entrypoints/webapp.py`)
- Flask API → Count Action: executes count (evidence: `counter/entrypoints/webapp.py`)
- CLI Runner → Adapter Configuration: gets action (evidence: `counter/entrypoints/main.py`)
- CLI Runner → Count Action: executes count (evidence: `counter/entrypoints/main.py`)
- Adapter Configuration → Count Action: constructs (evidence: `counter/config.py`)
- Adapter Configuration → Fake Detector: selects in dev (evidence: `counter/config.py`)
- Adapter Configuration → In-Memory Counts: selects in dev (evidence: `counter/config.py`)
- Adapter Configuration → TensorFlow Detector: selects in prod (evidence: `counter/config.py`)
- Adapter Configuration → Mongo Counts: selects in prod (evidence: `counter/config.py`)
- Count Action → TensorFlow Detector: predicts via port
- Count Action → Filter and Count: filters and counts (evidence: `counter/domain/actions.py`)
- Count Action → Debug Image Output: draws debug images (evidence: `counter/domain/actions.py`)
- Count Action → In-Memory Counts: updates and reads
- Count Action → Mongo Counts: updates and reads
- Count Action → Domain Models: builds response (evidence: `counter/domain/actions.py`)
- Filter and Count → Domain Models: uses domain types (evidence: `counter/domain/predictions.py`)
- Fake Detector → Domain Models: returns predictions (evidence: `counter/adapters/object_detector.py`)
- TensorFlow Detector → Domain Models: maps predictions (evidence: `counter/adapters/object_detector.py`)
- TensorFlow Detector → TensorFlow Serving: requests predictions (evidence: `counter/adapters/object_detector.py`)
- In-Memory Counts → Domain Models: stores counts (evidence: `counter/adapters/count_repo.py`)
- Mongo Counts → Domain Models: maps counts (evidence: `counter/adapters/count_repo.py`)
- Mongo Counts → MongoDB: reads and writes (evidence: `counter/adapters/count_repo.py`)
- Adapter Ports → Domain Models: defines data types (evidence: `counter/domain/ports.py`)
