# reneilwekeoagile061/bdap-server architecture

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

- Interactive diagram: https://gitdiagram.com/reneilwekeoagile061/bdap-server
- Repository: https://github.com/reneilwekeoagile061/bdap-server

## Overview

#### Purpose and execution modes
This Node.js batch integration exports Botswana SIMS subscriber data from BOCRA and transfers CSV extracts to BDAP. `Server.js` is the primary entry point: default execution performs a limited test download; `node Server.js --production` removes page limits and runs the full export. It also installs a weekly Monday 1 AM Botswana-time job. `scheduled-test.js` supports scheduled-run validation.

#### Bootstrap and configuration boundary
Startup validates runtime configuration, then initializes API and transfer connectivity before extraction. BDAP host, port, credentials, and remote directory are environment-supplied; `env.template` defines the expected contract and `check-env.js` validates it. No application database or web-serving layer is represented.
Paths: `Server.js`, `check-env.js`, `env.template`

#### BOCRA SIMS acquisition client
The core server uses an Axios-based HTTP client to call BOCRA SIMS endpoints with authentication, timeouts, retries, and optional SSL verification. It supports endpoint variants and response-shape variants (`content`, direct arrays, wrapped data/subscribers) to tolerate API differences. API calls are an external-service boundary; failures trigger retry/fallback behavior rather than persisting raw API state.
Path: `Server.js`

#### Natural-subscriber export pipeline
For each verification class—verified, failed verification, and pending verification—the service pages through natural-subscriber API results, extracts phone/document details, normalizes fields, and writes one standardized CSV. State mapping adapts API values such as `ACTIVE`, `FAILED`, and `PENDING` to export categories. If normal verification endpoints fail, MSISDN range scanning is an alternative acquisition route.
Paths: `Server.js`, `resources/verified_natural-subscriber_2025-04-29T12-54-14-442Z.csv`, `resources/pending_verification_natural-subscriber_2025-04-29T12-54-11-970Z.csv`

#### Juristic-subscriber enrichment pipeline
Juristic exports follow a distinct flow: list subscribers, request each subscriber’s detail and contact-person data, retrieve associated phone numbers, consolidate those records, then emit a single standardized CSV. This per-subscriber fan-out is the principal control-flow difference from paginated natural exports.
Path: `Server.js`

#### Local artifact boundary
CSV output is the durable handoff artifact between extraction and delivery. Output is date/timestamp partitioned and existing `resources/` files demonstrate separate natural-subscriber exports by state and run time. Text cleanup and field normalization occur before file writes, preserving a consistent downstream schema.
Paths: `resources/`, `resources/failed_verification_natural-subscriber_2025-04-29T12-53-44-481Z.csv`

#### BDAP delivery and scheduling
After each completed CSV is generated, the service tests BDAP reachability and transfers artifacts using password-authenticated SCP to the configured remote directory. Transfer is an infrastructure boundary independent of BOCRA acquisition. A cron-driven weekly full run and an explicit one-time push function orchestrate automated versus ad hoc delivery; logging and optional notifications expose failures.
Paths: `Server.js`, `scheduled-test.js`

Main entry points: [`Server.js`](https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js) (Server entry point), [`check-env.js`](https://github.com/reneilwekeoagile061/bdap-server/blob/main/check-env.js) (Runtime config validation), [`scheduled-test.js`](https://github.com/reneilwekeoagile061/bdap-server/blob/main/scheduled-test.js) (Scheduled-run validator), [`env.template`](https://github.com/reneilwekeoagile061/bdap-server/blob/main/env.template) (Environment contract)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Batch Runtime"]
  node_server["Server entry point<br/>Node.js batch<br/>[Server.js]"]
  node_scheduled_test["Scheduled-run validator<br/>Node.js script<br/>[scheduled-test.js]"]
  node_env_template["Environment contract<br/>env template<br/>[env.template]"]
  node_env_check["Runtime config validation<br/>validator<br/>[check-env.js]"]
  node_weekly_schedule(("Weekly Monday schedule<br/>cron job<br/>[Server.js]"))
end

subgraph group_bocra["BOCRA Acquisition"]
  node_bocra_api{{"BOCRA SIMS API<br/>external API"}}
  node_sims_client["Authenticated SIMS client<br/>Axios client<br/>[Server.js]"]
  node_range_fallback["MSISDN range fallback<br/>acquisition fallback<br/>[Server.js]"]
end

subgraph group_export["CSV Export"]
  node_natural_export["Natural subscriber export<br/>paged pipeline<br/>[Server.js]"]
  node_juristic_export["Juristic subscriber enrichment<br/>fan-out pipeline<br/>[Server.js]"]
  node_csv_artifacts["Timestamped CSV artifacts<br/>local files"]
end

subgraph group_delivery["BDAP Delivery"]
  node_bdap_connection{{"BDAP SCP endpoint<br/>external transfer"}}
  node_scp_transfer["CSV transfer<br/>SCP delivery<br/>[Server.js]"]
  node_logging_notifications["Failure visibility<br/>observability<br/>[Server.js]"]
end

node_env_template -->|"defines required values"| node_env_check
node_env_check -->|"validates at startup"| node_server
node_server -->|"initializes"| node_sims_client
node_sims_client -->|"authenticated HTTP calls"| node_bocra_api
node_server -->|"runs export classes"| node_natural_export
node_bocra_api -->|"paged natural records"| node_natural_export
node_natural_export -.->|"endpoint failure"| node_range_fallback
node_range_fallback -.->|"range queries"| node_bocra_api
node_server -->|"runs enrichment"| node_juristic_export
node_bocra_api -->|"subscriber, contact, phone data"| node_juristic_export
node_natural_export -->|"writes standardized CSV"| node_csv_artifacts
node_juristic_export -->|"writes standardized CSV"| node_csv_artifacts
node_csv_artifacts -->|"completed files"| node_scp_transfer
node_server -->|"orchestrates one-time push"| node_scp_transfer
node_scp_transfer -->|"SCP upload"| node_bdap_connection
node_server -->|"installs"| node_weekly_schedule
node_weekly_schedule -->|"full production run"| node_server
node_scheduled_test -.->|"validates scheduled execution"| node_server
node_scp_transfer -->|"reports failures"| node_logging_notifications

click node_server "https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js"
click node_scheduled_test "https://github.com/reneilwekeoagile061/bdap-server/blob/main/scheduled-test.js"
click node_env_template "https://github.com/reneilwekeoagile061/bdap-server/blob/main/env.template"
click node_env_check "https://github.com/reneilwekeoagile061/bdap-server/blob/main/check-env.js"
click node_weekly_schedule "https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js"
click node_sims_client "https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js"
click node_natural_export "https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js"
click node_range_fallback "https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js"
click node_juristic_export "https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js"
click node_scp_transfer "https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js"
click node_logging_notifications "https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js"

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_server,node_scheduled_test,node_env_template,node_env_check,node_weekly_schedule toneBlue
class node_bocra_api,node_sims_client,node_range_fallback toneAmber
class node_natural_export,node_juristic_export,node_csv_artifacts toneMint
class node_bdap_connection,node_scp_transfer,node_logging_notifications toneRose
```

## Components

### Batch Runtime

- [Server entry point](https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js): Node.js batch · Runs limited exports by default and full exports with --production. · `Server.js`
- [Scheduled-run validator](https://github.com/reneilwekeoagile061/bdap-server/blob/main/scheduled-test.js): Node.js script · `scheduled-test.js`
- [Environment contract](https://github.com/reneilwekeoagile061/bdap-server/blob/main/env.template): env template · Defines BDAP connection and destination variables. · `env.template`
- [Runtime config validation](https://github.com/reneilwekeoagile061/bdap-server/blob/main/check-env.js): validator · `check-env.js`
- [Weekly Monday schedule](https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js): cron job · Triggers a 1 AM Botswana-time full export. · `Server.js`

### BOCRA Acquisition

- **BOCRA SIMS API**: external API
- [Authenticated SIMS client](https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js): Axios client · Handles endpoint variants, retries, timeouts, and response shapes. · `Server.js`
- [MSISDN range fallback](https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js): acquisition fallback · Scans ranges when normal verification endpoints fail. · `Server.js`

### CSV Export

- [Natural subscriber export](https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js): paged pipeline · Exports verified, failed, and pending verification classes. · `Server.js`
- [Juristic subscriber enrichment](https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js): fan-out pipeline · Fetches subscriber details, contacts, and associated phone numbers. · `Server.js`
- **Timestamped CSV artifacts**: local files · Standardized durable handoff files partitioned by export state and run.

### BDAP Delivery

- **BDAP SCP endpoint**: external transfer · Password-authenticated SCP destination configured by environment.
- [CSV transfer](https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js): SCP delivery · Tests reachability and pushes completed artifacts to the remote directory. · `Server.js`
- [Failure visibility](https://github.com/reneilwekeoagile061/bdap-server/blob/main/Server.js): observability · Logs transfer and scheduled-run failures with optional notifications. · `Server.js`

## Connections

- Environment contract → Runtime config validation: defines required values
- Runtime config validation → Server entry point: validates at startup
- Server entry point → Authenticated SIMS client: initializes
- Authenticated SIMS client → BOCRA SIMS API: authenticated HTTP calls
- Server entry point → Natural subscriber export: runs export classes
- BOCRA SIMS API → Natural subscriber export: paged natural records
- Natural subscriber export → MSISDN range fallback: endpoint failure
- MSISDN range fallback → BOCRA SIMS API: range queries
- Server entry point → Juristic subscriber enrichment: runs enrichment
- BOCRA SIMS API → Juristic subscriber enrichment: subscriber, contact, phone data
- Natural subscriber export → Timestamped CSV artifacts: writes standardized CSV
- Juristic subscriber enrichment → Timestamped CSV artifacts: writes standardized CSV
- Timestamped CSV artifacts → CSV transfer: completed files
- Server entry point → CSV transfer: orchestrates one-time push
- CSV transfer → BDAP SCP endpoint: SCP upload
- Server entry point → Weekly Monday schedule: installs
- Weekly Monday schedule → Server entry point: full production run
- Scheduled-run validator → Server entry point: validates scheduled execution
- CSV transfer → Failure visibility: reports failures
