# nemryz/identity-generator architecture

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

- Interactive diagram: https://gitdiagram.com/nemryz/identity-generator
- Repository: https://github.com/nemryz/identity-generator

## Overview

#### Purpose and Runtime
`identity-generator` is a Python 3.10+ command-line application for generating locale-consistent fictional identity profiles, optionally provisioning temporary email inboxes, persisting profiles locally, and exporting them. It runs synchronously as a single process; no server or database is required.

Core runtime dependencies include Faker for localized data, Requests for email-provider HTTP calls, Colorama for terminal output, and Pyperclip for clipboard export. Container execution is defined by `Dockerfile`.

#### CLI Orchestration
`main.py` is the executable entry point. It parses command-line modes—single or batch generation, history lookup, inbox reads, email usage reporting, locale listing, and exports—then coordinates generation, persistence, output, and optional delay.

`applog.py` initializes shared file/stderr logging. The CLI establishes UTF-8 output and is the boundary between user-facing terminal behavior and domain modules.

Paths: `main.py`, `applog.py`, `Dockerfile`.

#### Identity Generation
`generator.py` constructs the canonical identity dictionary. It selects or accepts a Faker locale, generates regional personal fields, derives age/country/usernames/nicknames, creates IDs and timestamps, and produces secure passwords. It also applies locale-aware document providers where Faker supports them and supplies plausible passport formats otherwise.

Generation consumes committed address data for supported locales to keep city, postcode, street naming, and address format internally consistent; other locales fall back to Faker.

Paths: `generator.py`, `data/addresses/en_US.json`, `data/addresses/es_ES.json`.

#### Address Dataset Boundary
The committed JSON files under `data/addresses/` are runtime data assets, containing population-weighted cities, postcodes, street names, and attribution for eleven locales. They make address generation deterministic with respect to local data availability and avoid runtime geographic API calls.

`tools/build_datasets.py` is an offline maintenance pipeline, not normal application flow. It refreshes these assets from GeoNames and OpenStreetMap through public Overpass mirrors, with cached downloads and retry behavior.

Paths: `data/addresses/`, `tools/build_datasets.py`, `data/addresses/pt_BR.json`.

#### Email Provisioning and Inbox Reads
`email_api.py` enriches a generated identity with email address, provider, and optional inbox token. Provider selection is a resilience chain: configured custom catch-all domains, tempmail.lol, mail.tm, then an offline disposable-domain fallback. HTTP calls have bounded timeouts and usage counters prevent known provider limits from being exceeded.

Inbox reads use the persisted provider/token and therefore are separate from identity generation. Custom-domain addresses are deliverable but cannot be read through an API. External boundaries are public tempmail.lol and mail.tm APIs; no credentials are required.

Paths: `email_api.py`, `domains.example.json`.

#### Local Persistence and Concurrency
`history.py` owns local JSON persistence for generated profiles. The CLI appends one profile or a batch, retrieves recent entries, looks up profiles by UUID for inbox checks, and locates reusable inboxes. Writes use an exclusive lock and atomic replace to protect concurrent CLI processes and interrupted writes; corrupt files are backed up before recovery.

Email provider usage is also persisted locally by the email subsystem. These mutable runtime artifacts are intentionally gitignored.

Paths: `history.py`, `email_api.py`, `.gitignore`.

#### Output and Data Flow
Normal flow is: CLI arguments → `generator.py` → `email_api.py` (unless offline/reused as applicable) → `history.py` append → terminal rendering and optional export. Batch mode creates multiple profiles, commits them in one history operation, and exports CSV rows.

`exporter.py` is the final delivery boundary: per-identity JSON files, batch `identities.csv` without inbox tokens, or formatted clipboard text. Clipboard export depends on host desktop support and is unavailable in typical containers.

Paths: `exporter.py`, `main.py`, `history.py`.

Main entry points: [`main.py`](https://github.com/nemryz/identity-generator/blob/main/main.py) (CLI orchestrator), [`email_api.py`](https://github.com/nemryz/identity-generator/blob/main/email_api.py) (Email subsystem), [`generator.py`](https://github.com/nemryz/identity-generator/blob/main/generator.py) (Identity generator), [`tools/build_datasets.py`](https://github.com/nemryz/identity-generator/blob/main/tools/build_datasets.py) (Dataset builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["CLI Runtime"]
  node_cli["CLI orchestrator<br/>Python entry point<br/>[main.py]"]
  node_logging["Shared logging<br/>logging setup<br/>[applog.py]"]
  node_docker["Container runtime<br/>Docker image"]
  node_exporter["Export delivery<br/>export module<br/>[exporter.py]"]
  node_terminal["Terminal and clipboard<br/>user output boundary"]
end

subgraph group_generation["Identity Generation"]
  node_generator["Identity generator<br/>domain generator<br/>[generator.py]"]
  node_faker{{"Faker providers"}}
  node_address_assets[("Address datasets<br/>committed JSON assets")]
end

subgraph group_email["Email Provisioning"]
  node_email_api["Email subsystem<br/>provider client<br/>[email_api.py]"]
  node_domain_config["Custom domains<br/>example configuration"]
  node_email_providers{{"Temporary mail APIs<br/>external HTTP APIs"}}
end

subgraph group_storage["Local Data"]
  node_history["History persistence<br/>JSON repository<br/>[history.py]"]
  node_runtime_files[("Mutable local artifacts<br/>gitignored JSON files<br/>[.gitignore]")]
end

subgraph group_maintenance["Offline Maintenance"]
  node_dataset_builder["Dataset builder<br/>offline maintenance tool<br/>[build_datasets.py]"]
  node_geodata_sources{{"GeoNames and Overpass<br/>external geodata sources"}}
end

node_cli -->|"initializes"| node_logging
node_cli -->|"generates profiles"| node_generator
node_generator -->|"localized fields"| node_faker
node_generator -->|"supported locale addresses"| node_address_assets
node_cli -->|"optional provision or inbox read"| node_email_api
node_email_api -->|"loads catch-all domains"| node_domain_config
node_email_api -->|"provisions and reads inboxes"| node_email_providers
node_email_api -->|"persists usage counters"| node_runtime_files
node_cli -->|"append, lookup, reuse"| node_history
node_history -->|"atomic locked persistence"| node_runtime_files
node_cli -->|"exports generated or retrieved profiles"| node_exporter
node_cli -->|"renders results"| node_terminal
node_exporter -->|"clipboard and formatted output"| node_terminal
node_dataset_builder -->|"downloads source data"| node_geodata_sources
node_dataset_builder -->|"refreshes"| node_address_assets
node_docker -.->|"runs"| node_cli

click node_cli "https://github.com/nemryz/identity-generator/blob/main/main.py"
click node_logging "https://github.com/nemryz/identity-generator/blob/main/applog.py"
click node_docker "https://github.com/nemryz/identity-generator/blob/main/Dockerfile"
click node_generator "https://github.com/nemryz/identity-generator/blob/main/generator.py"
click node_email_api "https://github.com/nemryz/identity-generator/blob/main/email_api.py"
click node_domain_config "https://github.com/nemryz/identity-generator/blob/main/domains.example.json"
click node_history "https://github.com/nemryz/identity-generator/blob/main/history.py"
click node_runtime_files "https://github.com/nemryz/identity-generator/blob/main/.gitignore"
click node_exporter "https://github.com/nemryz/identity-generator/blob/main/exporter.py"
click node_dataset_builder "https://github.com/nemryz/identity-generator/blob/main/tools/build_datasets.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_cli,node_logging,node_docker,node_exporter,node_terminal toneBlue
class node_generator,node_faker,node_address_assets toneAmber
class node_email_api,node_domain_config,node_email_providers toneMint
class node_history,node_runtime_files toneRose
class node_dataset_builder,node_geodata_sources toneIndigo
```

## Components

### CLI Runtime

- [CLI orchestrator](https://github.com/nemryz/identity-generator/blob/main/main.py): Python entry point · Parses modes and coordinates synchronous profile workflows. · `main.py`
- [Shared logging](https://github.com/nemryz/identity-generator/blob/main/applog.py): logging setup · `applog.py`
- [Container runtime](https://github.com/nemryz/identity-generator/blob/main/Dockerfile): Docker image · `Dockerfile`
- [Export delivery](https://github.com/nemryz/identity-generator/blob/main/exporter.py): export module · Produces identity JSON, batch CSV without tokens, or clipboard text. · `exporter.py`
- **Terminal and clipboard**: user output boundary

### Identity Generation

- [Identity generator](https://github.com/nemryz/identity-generator/blob/main/generator.py): domain generator · Builds canonical locale-consistent identity dictionaries. · `generator.py`
- **Faker providers**: library · Supplies localized personal and document data.
- **Address datasets**: committed JSON assets · Locale city, postcode, street, and format data for deterministic supported addresses.

### Email Provisioning

- [Email subsystem](https://github.com/nemryz/identity-generator/blob/main/email_api.py): provider client · Provisions addresses, tracks provider usage, and reads token-backed inboxes. · `email_api.py`
- [Custom domains](https://github.com/nemryz/identity-generator/blob/main/domains.example.json): example configuration · `domains.example.json`
- **Temporary mail APIs**: external HTTP APIs · tempmail.lol and mail.tm are tried after custom catch-all domains.

### Local Data

- [History persistence](https://github.com/nemryz/identity-generator/blob/main/history.py): JSON repository · Atomically appends, retrieves, and recovers local profile history. · `history.py`
- [Mutable local artifacts](https://github.com/nemryz/identity-generator/blob/main/.gitignore): gitignored JSON files · Profile history and provider usage counters persist outside version control. · `.gitignore`

### Offline Maintenance

- [Dataset builder](https://github.com/nemryz/identity-generator/blob/main/tools/build_datasets.py): offline maintenance tool · Refreshes address assets with cached, retried public-source downloads. · `tools/build_datasets.py`
- **GeoNames and Overpass**: external geodata sources

## Connections

- CLI orchestrator → Shared logging: initializes
- CLI orchestrator → Identity generator: generates profiles
- Identity generator → Faker providers: localized fields
- Identity generator → Address datasets: supported locale addresses
- CLI orchestrator → Email subsystem: optional provision or inbox read
- Email subsystem → Custom domains: loads catch-all domains
- Email subsystem → Temporary mail APIs: provisions and reads inboxes
- Email subsystem → Mutable local artifacts: persists usage counters
- CLI orchestrator → History persistence: append, lookup, reuse
- History persistence → Mutable local artifacts: atomic locked persistence
- CLI orchestrator → Export delivery: exports generated or retrieved profiles
- CLI orchestrator → Terminal and clipboard: renders results
- Export delivery → Terminal and clipboard: clipboard and formatted output
- Dataset builder → GeoNames and Overpass: downloads source data
- Dataset builder → Address datasets: refreshes
- Container runtime → CLI orchestrator: runs
