# mizunie/nexar architecture

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

- Interactive diagram: https://gitdiagram.com/mizunie/nexar
- Repository: https://github.com/mizunie/nexar

## Overview

1. **Repository shape**
   - This is a **TypeScript SDK package**, not an application server.
   - The main deliverable is a library that consumers install from npm and use from their own runtime.

2. **Public entry point**
   - `src/index.ts` is the package façade.
   - The README shows the main entry as `Nexar.init({ token, businessId, baseUrl? })`, so the package exposes a root `Nexar` object that creates a configured client instance.

3. **Core shared layer**
   - `src/core/httpClient.ts` is the shared transport abstraction.
   - `src/core/types.ts` defines common SDK shapes such as the response envelope used across modules.
   - This core layer is the boundary between typed SDK methods and raw HTTP calls to Nexar APIs.

4. **Module-based client design**
   - The SDK is split into domain modules under `src/modules/`.
   - There are at least two top-level service areas:
     - `whatsapp` for messaging operations
     - `iawaba` for the file/indexed-document API
   - Each module has its own client implementation, which keeps API-specific behavior isolated from the transport and package entry point.

5. **WhatsApp subsystem**
   - `src/modules/whatsapp/client.ts` and `src/modules/whatsapp/types.ts` define the WhatsApp API surface.
   - From the README, this module supports:
     - send text
     - quick text
     - templates
     - interactive messages with buttons
   - The data boundary here is mostly message payload construction and response typing.

6. **IA WABA subsystem**
   - `src/modules/iawaba/client.ts` handles the indexed-document/file API.
   - The README indicates operations for upload/update and soft delete, with automatic checksum generation handled by the SDK.
   - This module represents a separate business workflow from WhatsApp: document lifecycle management rather than messaging.

7. **Configuration and request flow**
   - The consumer provides `token` and `businessId` at initialization, plus optional `baseUrl`.
   - That config flows into the shared HTTP client and then into each module client.
   - All module methods ultimately call Nexar backend endpoints on the configured API host.

8. **API contract and responses**
   - The SDK standardizes responses around an `ApiResponse<T>`-style envelope with fields like `code`, `msg`, `data`, `errorDetail`, and optional pagination.
   - This means the library is not just a thin fetch wrapper; it normalizes backend responses into a typed SDK contract.

9. **Runtime and portability**
   - The README states support for Node.js 18+, Bun, Deno, Edge runtimes, and browsers if CORS is enabled.
   - Architecturally, that implies the SDK is designed around runtime-neutral HTTP access rather than Node-only APIs.

10. **External integration boundary**
   - All outbound communication goes to Nexar services, primarily the default API base `https://back.nexar.com.co` or a custom `baseUrl`.
   - The IA WABA endpoint is explicitly called out as `POST /iawaba/api-receptor/{businessId}`, showing that business identity is part of the request path, not just headers.

11. **Packaging and release**
   - `.github/workflows/publish.yml` indicates automated publishing to npm.
   - That workflow is part of the library distribution boundary rather than runtime behavior, but it is relevant to the overall architecture of how the SDK ships.

12. **How to diagram it**
   - A clean architecture diagram would show:
     - the consumer app at the edge
     - the `Nexar` initialization layer
     - shared `core/httpClient`
     - module clients for `whatsapp` and `iawaba`
     - outbound calls to Nexar REST APIs
   - The key separation is between **configuration + typed module methods** on the inside, and **HTTP/API endpoints** on the outside.

Main entry points: [`src/index.ts`](https://github.com/mizunie/nexar/blob/master/src/index.ts) (Nexar init), [`src/modules/whatsapp/client.ts`](https://github.com/mizunie/nexar/blob/master/src/modules/whatsapp/client.ts) (WhatsApp client), [`src/core/httpClient.ts`](https://github.com/mizunie/nexar/blob/master/src/core/httpClient.ts) (HTTP client), [`src/modules/iawaba/client.ts`](https://github.com/mizunie/nexar/blob/master/src/modules/iawaba/client.ts) (IA WABA client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public API"]
  node_consumer["Consumer App<br/>sdk consumer"]
  node_facade["Nexar init<br/>entry facade<br/>[index.ts]"]
  node_config["Client config<br/>init config<br/>[index.ts]"]
  node_runtime(("Multi-runtime<br/>runtime support"))
end

subgraph group_core["Core"]
  node_httpclient["HTTP client<br/>transport<br/>[httpClient.ts]"]
  node_types["API types<br/>contract types<br/>[types.ts]"]
end

subgraph group_modules["Modules"]
  node_whatsappclient["WhatsApp client<br/>module client<br/>[client.ts]"]
  node_whatstypes["WhatsApp types<br/>payload types<br/>[types.ts]"]
  node_iawabaclient["IA WABA client<br/>module client<br/>[client.ts]"]
  node_whatssend(("Send flow<br/>messaging ops"))
  node_iawabaops(("Doc flow<br/>file ops"))
end

subgraph group_external["External APIs"]
  node_whatsappapi{{"WhatsApp API<br/>backend endpoint"}}
  node_iawabaapi{{"IA WABA API<br/>backend endpoint"}}
end

subgraph group_release["Release"]
  node_publish["Publish workflow<br/>release automation<br/>[publish.yml]"]
end

node_consumer -->|"imports"| node_facade
node_facade -->|"creates"| node_config
node_facade -->|"wires"| node_httpclient
node_facade -->|"exposes"| node_whatsappclient
node_facade -->|"exposes"| node_iawabaclient
node_httpclient -->|"normalizes"| node_types
node_whatsappclient -->|"uses"| node_whatstypes
node_whatsappclient -->|"calls"| node_httpclient
node_iawabaclient -->|"calls"| node_httpclient
node_whatsappclient -->|"implements"| node_whatssend
node_iawabaclient -->|"implements"| node_iawabaops
node_whatssend -->|"targets"| node_whatsappapi
node_iawabaops -->|"targets"| node_iawabaapi
node_config -.->|"supports"| node_runtime
node_publish -.->|"ships"| node_facade

click node_facade "https://github.com/mizunie/nexar/blob/master/src/index.ts"
click node_config "https://github.com/mizunie/nexar/blob/master/src/index.ts"
click node_httpclient "https://github.com/mizunie/nexar/blob/master/src/core/httpClient.ts"
click node_types "https://github.com/mizunie/nexar/blob/master/src/core/types.ts"
click node_whatsappclient "https://github.com/mizunie/nexar/blob/master/src/modules/whatsapp/client.ts"
click node_whatstypes "https://github.com/mizunie/nexar/blob/master/src/modules/whatsapp/types.ts"
click node_iawabaclient "https://github.com/mizunie/nexar/blob/master/src/modules/iawaba/client.ts"
click node_publish "https://github.com/mizunie/nexar/blob/master/.github/workflows/publish.yml"

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_consumer,node_facade,node_config,node_runtime toneBlue
class node_httpclient,node_types toneAmber
class node_whatsappclient,node_whatstypes,node_iawabaclient,node_whatssend,node_iawabaops toneMint
class node_whatsappapi,node_iawabaapi toneRose
class node_publish toneIndigo
```

## Components

### Public API

Package entry and consumer-facing initialization

- **Consumer App**: sdk consumer · Host application using the Nexar SDK
- [Nexar init](https://github.com/mizunie/nexar/blob/master/src/index.ts): entry facade · Root package entry that creates a configured client · `src/index.ts`
- [Client config](https://github.com/mizunie/nexar/blob/master/src/index.ts): init config · Token, businessId, and optional baseUrl passed into the SDK · `src/index.ts`
- **Multi-runtime**: runtime support · Node.js, Bun, Deno, edge, and browser-friendly HTTP access

### Core

Shared transport and SDK contract layer

- [HTTP client](https://github.com/mizunie/nexar/blob/master/src/core/httpClient.ts): transport · Shared runtime-neutral request layer · `src/core/httpClient.ts`
- [API types](https://github.com/mizunie/nexar/blob/master/src/core/types.ts): contract types · Common response envelope and shared SDK shapes · `src/core/types.ts`

### Modules

Domain-specific service clients

- [WhatsApp client](https://github.com/mizunie/nexar/blob/master/src/modules/whatsapp/client.ts): module client · Messaging operations for WhatsApp · `src/modules/whatsapp/client.ts`
- [WhatsApp types](https://github.com/mizunie/nexar/blob/master/src/modules/whatsapp/types.ts): payload types · WhatsApp message and response typing · `src/modules/whatsapp/types.ts`
- [IA WABA client](https://github.com/mizunie/nexar/blob/master/src/modules/iawaba/client.ts): module client · Indexed-document and file lifecycle operations · `src/modules/iawaba/client.ts`
- **Send flow**: messaging ops · Text, quick text, templates, and interactive messages
- **Doc flow**: file ops · Upload, update, checksum handling, and soft delete

### External APIs

Nexar backend endpoints consumed by the SDK

- **WhatsApp API**: backend endpoint · Nexar messaging service endpoints
- **IA WABA API**: backend endpoint · Nexar indexed-document endpoint on the business-scoped path

### Release

Packaging and publish automation

- [Publish workflow](https://github.com/mizunie/nexar/blob/master/.github/workflows/publish.yml): release automation · GitHub workflow that publishes the package to npm · `.github/workflows/publish.yml`

## Connections

- Consumer App → Nexar init: imports · Application code calls the package entry point
- Nexar init → Client config: creates · Initializes a client from token, businessId, and baseUrl
- Nexar init → HTTP client: wires · Passes configuration into the shared transport layer
- Nexar init → WhatsApp client: exposes · Makes WhatsApp operations available on the client
- Nexar init → IA WABA client: exposes · Makes IA WABA operations available on the client
- HTTP client → API types: normalizes · Wraps backend responses in a shared typed envelope
- WhatsApp client → WhatsApp types: uses · Builds and validates WhatsApp payloads
- WhatsApp client → HTTP client: calls · Sends module requests through the shared transport
- IA WABA client → HTTP client: calls · Sends file workflow requests through the shared transport
- WhatsApp client → Send flow: implements · Supports text, quick text, templates, and interactive messages
- IA WABA client → Doc flow: implements · Supports upload, update, checksum, and soft delete flows
- Send flow → WhatsApp API: targets · Routes messaging requests to Nexar WhatsApp endpoints
- Doc flow → IA WABA API: targets · Routes document requests to the business-scoped IA WABA endpoint
- Client config → Multi-runtime: supports · Designed to work across Node, Bun, Deno, edge, and browsers
- Publish workflow → Nexar init: ships · Automated release publishes the package entry and modules to npm
