# bekidiaz96/localizadorservice architecture

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

- Interactive diagram: https://gitdiagram.com/bekidiaz96/localizadorservice
- Repository: https://github.com/bekidiaz96/localizadorservice

## Overview

LocalizadorService collects vehicle sensor readings and GPS coordinates on a Raspberry Pi, validates and combines them, and stores each accepted record locally in SQLite. A separate sync loop retrieves unsynchronized records, inserts them into PostgreSQL, and marks successful records as synchronized. The repository also includes synthetic record generation and rotating file logging. The README documents the PostgreSQL sync workflow; relationships below are limited to calls visible in the provided source excerpts and that documentation.

Main entry points: [`db_handler.py`](https://github.com/bekidiaz96/localizadorservice/blob/main/db_handler.py) (SQLite handler), [`ard_gps.py`](https://github.com/bekidiaz96/localizadorservice/blob/main/ard_gps.py) (Serial collector), [`sync_service.py`](https://github.com/bekidiaz96/localizadorservice/blob/main/sync_service.py) (Sync worker), [`generar_datos.py`](https://github.com/bekidiaz96/localizadorservice/blob/main/generar_datos.py) (Sample generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Device capture"]
  node_collector["Serial collector<br/>[ard_gps.py]"]
  node_gps_parser["NMEA parser<br/>[ard_gps.py]"]
end

subgraph group_local["Local persistence"]
  node_sqlite[("Local records<br/>[vehiculos.db]")]
  node_db_handler["SQLite handler<br/>[db_handler.py]"]
end

subgraph group_sync["Remote synchronization"]
  node_sync_service["Sync worker<br/>[sync_service.py]"]
  node_postgres[("Central records")]
end

subgraph group_support["Logging and simulation"]
  node_generator["Sample generator<br/>[generar_datos.py]"]
  node_logger_setup["Logger setup<br/>[logger_setup.py]"]
end

node_arduino(("Arduino sensors"))
node_gps(("GPS receiver"))

node_arduino -->|"sends readings"| node_collector
node_gps -->|"sends NMEA"| node_gps_parser
node_collector -->|"reads coordinates"| node_gps_parser
node_collector -->|"initializes and inserts"| node_db_handler
node_db_handler -->|"reads and writes"| node_sqlite
node_generator -->|"initializes and inserts"| node_db_handler
node_collector -->|"configures logging"| node_logger_setup
node_sync_service -->|"fetches pending records"| node_db_handler
node_sync_service -->|"connects and inserts"| node_postgres
node_sync_service -->|"marks synchronized"| node_db_handler

click node_collector "https://github.com/bekidiaz96/localizadorservice/blob/main/ard_gps.py"
click node_gps_parser "https://github.com/bekidiaz96/localizadorservice/blob/main/ard_gps.py"
click node_sqlite "https://github.com/bekidiaz96/localizadorservice/blob/main/vehiculos.db"
click node_db_handler "https://github.com/bekidiaz96/localizadorservice/blob/main/db_handler.py"
click node_generator "https://github.com/bekidiaz96/localizadorservice/blob/main/generar_datos.py"
click node_logger_setup "https://github.com/bekidiaz96/localizadorservice/blob/main/logger_setup.py"
click node_sync_service "https://github.com/bekidiaz96/localizadorservice/blob/main/sync_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_collector,node_gps_parser toneBlue
class node_sqlite,node_db_handler toneAmber
class node_sync_service,node_postgres toneMint
class node_generator,node_logger_setup toneRose
class node_arduino,node_gps toneIndigo
```

## Components

### Device capture

- [Serial collector](https://github.com/bekidiaz96/localizadorservice/blob/main/ard_gps.py): `ard_gps.py`
- [NMEA parser](https://github.com/bekidiaz96/localizadorservice/blob/main/ard_gps.py): `ard_gps.py`

### Local persistence

- [Local records](https://github.com/bekidiaz96/localizadorservice/blob/main/vehiculos.db): `vehiculos.db`
- [SQLite handler](https://github.com/bekidiaz96/localizadorservice/blob/main/db_handler.py): `db_handler.py`

### Remote synchronization

- [Sync worker](https://github.com/bekidiaz96/localizadorservice/blob/main/sync_service.py): `sync_service.py`
- **Central records**

### Logging and simulation

- [Sample generator](https://github.com/bekidiaz96/localizadorservice/blob/main/generar_datos.py): `generar_datos.py`
- [Logger setup](https://github.com/bekidiaz96/localizadorservice/blob/main/logger_setup.py): `logger_setup.py`

### Other components

- **Arduino sensors**
- **GPS receiver**

## Connections

- Arduino sensors → Serial collector: sends readings (evidence: `ard_gps.py`)
- GPS receiver → NMEA parser: sends NMEA (evidence: `ard_gps.py`)
- Serial collector → NMEA parser: reads coordinates (evidence: `ard_gps.py`)
- Serial collector → SQLite handler: initializes and inserts (evidence: `ard_gps.py`)
- SQLite handler → Local records: reads and writes (evidence: `db_handler.py`)
- Sample generator → SQLite handler: initializes and inserts (evidence: `generar_datos.py`)
- Serial collector → Logger setup: configures logging (evidence: `ard_gps.py`)
- Sync worker → SQLite handler: fetches pending records (evidence: `sync_service.py`)
- Sync worker → Central records: connects and inserts (evidence: `sync_service.py`)
- Sync worker → SQLite handler: marks synchronized (evidence: `sync_service.py`)
