barkapi 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +112 -210
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,24 +1,20 @@
1
- <p align="center">
2
- <img src="https://em-content.zobj.net/source/apple/391/dog-face_1f436.png" width="80" />
3
- </p>
4
-
5
- <h1 align="center">BarkAPI</h1>
6
-
7
- <p align="center">
8
- <strong>Your API's watchdog.</strong><br/>
9
- Detects schema drift between your OpenAPI spec and live API responses — before things break in production.
10
- </p>
11
-
12
- <p align="center">
13
- <a href="https://www.npmjs.com/package/barkapi"><img src="https://img.shields.io/npm/v/barkapi" alt="npm version" /></a>
14
- <img src="https://img.shields.io/badge/node-%3E%3D18-brightgreen" alt="Node.js >= 18" />
15
- <img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT License" />
16
- <img src="https://img.shields.io/badge/typescript-strict-blue" alt="TypeScript" />
17
- </p>
1
+ <div align="center">
2
+ <img src="https://em-content.zobj.net/source/apple/391/dog-face_1f436.png" height="120" alt="BarkAPI Logo" />
3
+ <h1>BarkAPI</h1>
4
+ <p><strong>Your API's Watchdog.</strong></p>
5
+ <p><em>Detect schema drift between your OpenAPI spec and live responses before production breaks.</em></p>
6
+
7
+ <p>
8
+ <a href="https://www.npmjs.com/package/barkapi"><img src="https://img.shields.io/npm/v/barkapi?style=for-the-badge&color=2563EB" alt="npm version" /></a>
9
+ <img src="https://img.shields.io/badge/node-%3E%3D18-brightgreen?style=for-the-badge&color=10B981" alt="Node.js >= 18" />
10
+ <img src="https://img.shields.io/badge/license-MIT-blue?style=for-the-badge&color=8B5CF6" alt="MIT License" />
11
+ <img src="https://img.shields.io/badge/typescript-strict-blue?style=for-the-badge&color=3B82F6" alt="TypeScript" />
12
+ </p>
13
+ </div>
18
14
 
19
15
  ---
20
16
 
21
- **BarkAPI** parses your OpenAPI spec, hits your live endpoints, compares response shapes, and reports mismatches like **ESLint for your API contracts**. Ships with a CLI for your terminal and CI pipelines, plus a real-time web dashboard with schema visualization and drift annotations.
17
+ > **BarkAPI** parses your OpenAPI spec, hits your live endpoints, compares response shapes, and reports mismatches. It acts like **ESLint for your API contracts**. Ships with a CLI for your terminal and CI pipelines, plus a real-time web dashboard with schema visualizations.
22
18
 
23
19
  ```
24
20
  GET /api/users/:id
@@ -31,156 +27,93 @@ GET /api/orders
31
27
  ✗ 2 breaking ⚠ 1 warning ✓ 8 passing (12 endpoints checked)
32
28
  ```
33
29
 
34
- ---
30
+ ## ✨ Highlights & Features
35
31
 
36
- ## Features
37
-
38
- - **Zero-config setup** — auto-detects your OpenAPI spec and project type
39
- - **Recursive schema diffing** — catches type changes, missing fields, nullability shifts, and undocumented additions
40
- - **Severity classification** — `breaking` / `warning` / `info` so you know what matters
41
- - **CI-friendly** — exits with code 1 on breaking drift, plug it into any pipeline
42
- - **Continuous watch mode** — monitor endpoints on an interval
43
- - **`barkapi dev`**one command starts watch mode + dashboard, auto-opens browser
44
- - **Real-time dashboard** — bento grid layout, animated health rings, schema viewer with drift annotations
45
- - **Schema visualization** — interactive tree rendering of your OpenAPI spec with inline drift markers
46
- - **Alerting** — configure Slack webhook and email notifications
47
- - **Spec diffing** — compare two versions of an OpenAPI spec offline
48
- - **CI generation** — auto-generate GitHub Actions workflows
49
- - **Embedded SQLite** — no external database to set up or maintain
32
+ - 🛠 **Zero-config setup** — Auto-detects your OpenAPI spec and project framework.
33
+ - 🔍 **Recursive schema diffing** — Catches type changes, missing fields, nullability shifts, and undocumented fields.
34
+ - 🚥 **Severity grading** — Categorized into `breaking`, `warning`, and `info` so you prioritize what matters.
35
+ - 🚀 **CI-friendly**Exits with code `1` on breaking drift. Plug it directly into your pipelines.
36
+ - **Watch mode** — Monitor endpoints continuously on an interval.
37
+ - 🖥 **Bento Dashboard** — One command (`barkapi dev`) starts watch mode + an amazing real-time dashboard.
38
+ - 📈 **Visualizations**Interactive schema trees, endpoint health grids, timelines, and diff history.
39
+ - 🔔 **Alerting**Configure Slack webhooks and email notifications on new schema drifts.
40
+ - 🗄 **Embedded SQLite** — No external DBs needed. Data stays local, fast, and secure.
50
41
 
51
- ---
42
+ <br/>
43
+
44
+ ## 📖 Real-World Use Cases
45
+
46
+ ### 🛠 1. Local Development (The "Dev Server")
47
+ > *For developers actively writing or consuming the API who need real-time feedback.*
48
+ - **Action**: Run `barkapi dev` while building your app alongside your backend web server.
49
+ - **Outcome**: A beautiful dashboard opens at `localhost:3100`. As you iteratively code, if you accidentally rename `email` to `emailAddress` in your JSON payload without updating the spec, the dashboard instantly flashes red for a `breaking` drift. You catch the contract breach before even committing code.
50
+
51
+ ### 🛑 2. Continuous Integration (The "Pipeline Gatekeeper")
52
+ > *For engineering leaders wanting to prevent breaking API changes from reaching production.*
53
+ - **Action**: Use `barkapi ci-gen` to drop a GitHub Actions workflow into your repo that runs `barkapi check` against a staging deployment environment.
54
+ - **Outcome**: When a developer opens a Pull Request that introduces a database change, altering an API response scalar from `string` to `number`, BarkAPI throws a fatal error in CI and **exits with code 1**. The PR fails automatically, preventing mobile clients from crashing in the wild.
55
+
56
+ ### 🚨 3. Background Monitoring & Alerts (The "Production Watchdog")
57
+ > *For SREs and teams watching third-party APIs or checking critical production/staging environments for unauthorized drift.*
58
+ - **Action**: Run `barkapi watch --interval 300` (every 5 mins) with Slack/email webhooks configured in `.barkapi.yml`.
59
+ - **Outcome**: A rogue raw-SQL migration quietly exposes a sensitive internal `password_hash` column to the `GET /users` endpoint. BarkAPI immediately catches the undocumented field addition, classifies it, and fires an alert to your `#engineering-alerts` Slack channel to contain the spillage.
52
60
 
53
- ## Install
61
+ ### 🗂 4. Offline Schema Audits (The "Spec Compare")
62
+ > *For frontend engineers trying to understand exactly what changed in a massive updated `v2` OpenAPI spec delivery.*
63
+ - **Action**: Run `barkapi diff v1-openapi.yaml v2-openapi.yaml`.
64
+ - **Outcome**: Instead of scanning thousands of lines of raw YAML diffs, barkapi diff outputs exactly which fields were *added*, became *nullable*, or were *dropped*, letting you know where to update your TypeScript types.
65
+
66
+ <br/>
67
+
68
+ ## 📦 Installation
54
69
 
55
70
  ```bash
56
71
  npm install -g barkapi
57
72
  ```
58
73
 
59
74
  ### Prerequisites
60
-
61
75
  - **Node.js >= 18**
62
- - **Build tools** for native addon compilation (`better-sqlite3`):
76
+ - **Build tools** for SQLite (`better-sqlite3`):
63
77
  - macOS: `xcode-select --install`
64
78
  - Ubuntu/Debian: `sudo apt install build-essential python3`
65
- - Windows: install the "Desktop development with C++" workload from Visual Studio Build Tools
79
+ - Windows: Visual Studio Build Tools (C++ Workload)
66
80
 
67
- ---
81
+ <br/>
82
+
83
+ ## 🚀 Quick Start
68
84
 
69
- ## Quick Start
85
+ Launch the watchdog in just two commands:
70
86
 
71
87
  ```bash
72
88
  # 1. Navigate to your API project
73
89
  cd /path/to/your-api
74
90
 
75
- # 2. Initialize auto-detects your OpenAPI spec
91
+ # 2. Initialize (auto-detects spec + setups config)
76
92
  barkapi init --spec openapi.yaml --base-url http://localhost:3000
77
93
 
78
- # 3. Start dashboard + watch mode (opens browser automatically)
94
+ # 3. Start dashboard + watch mode
79
95
  barkapi dev
80
96
  ```
97
+ *The dashboard opens at `http://localhost:3100` and auto-refreshes every 3 seconds.*
81
98
 
82
- That's it — two commands. The dashboard opens at `http://localhost:3100` and auto-refreshes every 3 seconds.
83
-
84
- ---
85
-
86
- ## Commands
87
-
88
- ### `barkapi init`
89
-
90
- Scans your project for OpenAPI specs, detects project metadata, and generates a `.barkapi.yml` config file.
91
-
92
- ```bash
93
- barkapi init [options]
94
-
95
- Options:
96
- --spec <path> Path to OpenAPI spec file
97
- --base-url <url> Base URL for your API (default: http://localhost:3000)
98
- --name <name> Project name (default: from package.json)
99
- ```
100
-
101
- Auto-detects spec files at common paths: `openapi.yaml`, `swagger.json`, `docs/openapi.yml`, etc.
102
-
103
- ### `barkapi check`
104
-
105
- Parses your spec, calls each endpoint, diffs the response against the expected schema, and prints an ESLint-style report.
106
-
107
- ```bash
108
- barkapi check [options]
109
-
110
- Options:
111
- --config <path> Path to .barkapi.yml
112
- --spec <path> Override spec path
113
- --base-url <url> Override base URL
114
- ```
115
-
116
- **Exit code 1** if any breaking drift is detected — perfect for CI gates.
99
+ <br/>
117
100
 
118
- ### `barkapi dev`
101
+ ## ⌨️ CLI Commands
119
102
 
120
- The all-in-one development command. Starts the web dashboard and watch mode together. Auto-opens your browser.
103
+ | Command | Description | Example / Options |
104
+ |---------|-------------|-------------------|
105
+ | `barkapi init` | Scans project, finds spec, generates `.barkapi.yml` | `--spec <path> --base-url <url>` |
106
+ | `barkapi dev` | 🔥 Starts interactive web dashboard + watch checks | `--interval <sec> --port <port>` |
107
+ | `barkapi check` | One-shot run. Prints ESLint-style report. Fails on breaking. | `--config <path>` |
108
+ | `barkapi watch` | Runs continuous checks based on intervals | `--interval <sec>` |
109
+ | `barkapi diff` | Compares two offline OpenAPI specs for diffs | `<old-spec> <new-spec> --json` |
110
+ | `barkapi ci-gen` | Generates GitHub Actions workflow CI files | `--base-url-var <var>` |
121
111
 
122
- ```bash
123
- barkapi dev [options]
112
+ <br/>
124
113
 
125
- Options:
126
- --config <path> Path to .barkapi.yml
127
- --interval <seconds> Check interval (default: 30)
128
- --port <port> Dashboard port (default: 3100)
129
- --no-open Don't auto-open browser
130
- ```
131
-
132
- ### `barkapi watch`
114
+ ## ⚙️ Configuration (`.barkapi.yml`)
133
115
 
134
- Runs checks continuously on an interval.
135
-
136
- ```bash
137
- barkapi watch [options]
138
-
139
- Options:
140
- --config <path> Path to .barkapi.yml
141
- --interval <seconds> Check interval (default: 30)
142
- ```
143
-
144
- ### `barkapi diff`
145
-
146
- Compares two OpenAPI spec versions and shows schema differences between them.
147
-
148
- ```bash
149
- barkapi diff <old-spec> <new-spec> [options]
150
-
151
- Options:
152
- --json Output as JSON
153
- ```
154
-
155
- ### `barkapi ci-gen`
156
-
157
- Generates a GitHub Actions workflow file for automated contract checking.
158
-
159
- ```bash
160
- barkapi ci-gen [options]
161
-
162
- Options:
163
- --config <path> Path to .barkapi.yml
164
- --base-url-var <var> GitHub Actions variable name (default: vars.STAGING_URL)
165
- --output <path> Output path (default: .github/workflows/barkapi.yml)
166
- ```
167
-
168
- ### `barkapi report`
169
-
170
- Runs a check and prints results.
171
-
172
- ```bash
173
- barkapi report [options]
174
-
175
- Options:
176
- --config <path> Path to .barkapi.yml
177
- ```
178
-
179
- ---
180
-
181
- ## Configuration
182
-
183
- BarkAPI uses a `.barkapi.yml` file in your project root:
116
+ BarkAPI uses a simple YAML config file in your project root.
184
117
 
185
118
  ```yaml
186
119
  project: my-api
@@ -192,61 +125,40 @@ auth:
192
125
  type: bearer # bearer | header | query
193
126
  token_env: API_TOKEN # reads from environment variable
194
127
 
195
- # Optional: path parameters for parameterized endpoints
128
+ # Optional: Path parameters for simulated requests
196
129
  path_params:
197
130
  id: "1"
198
131
 
199
- # Optional: filter which endpoints to check
132
+ # Optional: Endpoint Filtering
200
133
  endpoints:
201
134
  include:
202
135
  - /api/users
203
- - /api/orders
204
136
  exclude:
205
137
  - /api/internal
206
138
  ```
207
139
 
208
- ### Auth Types
209
-
210
- | Type | Description | Config |
211
- |------|------------|--------|
212
- | `bearer` | `Authorization: Bearer <token>` header | `token_env`: env var name |
213
- | `header` | Custom header | `token_env` + `header_name` |
214
- | `query` | Query parameter | `token_env` + `query_param` |
215
-
216
- ---
140
+ <br/>
217
141
 
218
- ## Drift Detection
142
+ ## 🔬 Drift Detection Engine
219
143
 
220
- The diff engine performs recursive structural comparison between your OpenAPI spec schemas and actual API response shapes.
144
+ BarkAPI performs strict structural diffing between standard OpenAPI JSON Schemas and observed JavaScript object trees.
221
145
 
222
146
  | Drift Type | Severity | What it means |
223
147
  |------------|----------|---------------|
224
- | Removed required field | `breaking` | A field your consumers depend on is gone |
225
- | Removed optional field | `warning` | A field disappeared but wasn't required |
226
- | Type changed | `breaking` | Field type shifted (e.g. `string` → `number`) |
227
- | Nullable non-null | `breaking` | Consumers handling null will break |
228
- | Non-null nullable | `warning` | Field can now be null |
229
- | Required changed | `breaking` | Required/optional status changed |
230
- | Enum changed | `warning` | Allowed enum values differ |
231
- | Format changed | `warning` | Field format differs (e.g. `date-time` missing) |
232
- | Undocumented field added | `info` | Response has a field not in the spec |
148
+ | Removed required field | 🔴 `breaking` | A field your consumers depend on is gone |
149
+ | Type changed | 🔴 `breaking` | Field type shifted (e.g. `string` `number`) |
150
+ | Nullable non-null | 🔴 `breaking` | Consumers handling null will break |
151
+ | Required changed | 🔴 `breaking` | Required/optional status changed |
152
+ | Removed optional field | 🟡 `warning` | A field disappeared but wasn't explicitly required |
153
+ | Non-null nullable | 🟡 `warning` | Field can now be null |
154
+ | Enum changed | 🟡 `warning` | Allowed enum values differ |
155
+ | Undocumented field | 🔵 `info` | Response has a field not listed in the spec |
233
156
 
234
- ---
235
-
236
- ## Dashboard
157
+ <br/>
237
158
 
238
- The `barkapi dev` command launches a web dashboard at `http://localhost:3100` with:
159
+ ## 🖥 Dashboard Experience
239
160
 
240
- - **Bento grid layout** health ring, stat cards, drift distribution at a glance
241
- - **Schema viewer** — interactive tree of your OpenAPI schema with drift annotations inline
242
- - **Endpoint health map** — color-coded grid showing status of every endpoint
243
- - **Drift history** — grouped by field path with side-by-side expected vs actual diffs
244
- - **Timeline charts** — area charts showing drift trends over time
245
- - **Breadcrumb navigation** — always know where you are: `Projects > My API > GET /users/{id}`
246
- - **Alerting** — configure Slack webhook and email notifications
247
- - **Real-time updates** — auto-refreshes every 3s via shared SQLite database
248
-
249
- ### Dashboard Pages
161
+ The `barkapi dev` command launches a web dashboard at `http://localhost:3100` with real-time updates:
250
162
 
251
163
  | Page | Route | Description |
252
164
  |------|-------|-------------|
@@ -256,11 +168,11 @@ The `barkapi dev` command launches a web dashboard at `http://localhost:3100` wi
256
168
  | **Timeline** | `/projects/:id/timeline` | Area/line/bar charts + check run cards with mini health rings |
257
169
  | **Alerts** | `/projects/:id/alerts` | Configure Slack and email notifications with severity filters |
258
170
 
259
- ---
171
+ <br/>
260
172
 
261
- ## Example Project
173
+ ## 🧪 Example Project
262
174
 
263
- The [`examples/`](https://github.com/mruduljohn/BarkAPI/tree/main/examples) directory contains a complete demo with intentional drift:
175
+ The [`examples/`](https://github.com/mruduljohn/BarkAPI/tree/main/examples) directory contains a complete demo with intentional drift to see how BarkAPI reacts:
264
176
 
265
177
  ```bash
266
178
  # 1. Start the example API server (has intentional drift from spec)
@@ -277,9 +189,9 @@ The example server returns responses that intentionally differ from its OpenAPI
277
189
  - `GET /api/users/:id` — `email` is a number (spec says string), missing `created_at`, extra `avatar` field
278
190
  - `GET /api/products/:id` — `price` is a string (spec says number)
279
191
 
280
- ---
192
+ <br/>
281
193
 
282
- ## CI Integration
194
+ ## 🤖 CI Integration
283
195
 
284
196
  ### GitHub Actions
285
197
 
@@ -295,13 +207,13 @@ Or generate a workflow file automatically:
295
207
  barkapi ci-gen --base-url-var vars.STAGING_URL
296
208
  ```
297
209
 
298
- The `check` command exits with code 1 on breaking drift, failing your pipeline automatically.
210
+ > 💡 The `check` command gracefully exits with code 1 on breaking drift, failing your pipeline automatically.
299
211
 
300
- ---
212
+ <br/>
301
213
 
302
- ## Architecture
214
+ ## 🏗 Architecture & Stack
303
215
 
304
- ```
216
+ ```text
305
217
  BarkAPI/
306
218
  ├── packages/
307
219
  │ ├── core/ @barkapi/core — shared engine
@@ -309,43 +221,33 @@ BarkAPI/
309
221
  │ │ ├── parser/ OpenAPI parser + response schema inferrer
310
222
  │ │ ├── diff/ Recursive schema differ + severity classifier
311
223
  │ │ ├── db/ SQLite connection, schema migration, queries
312
- │ │ └── models/ CRUD for projects, endpoints, check runs, drifts, alerts
224
+ │ │ └── models/ CRUD for projects, endpoints, runs, alerts
313
225
  │ ├── cli/ barkapi — the npm package
314
226
  │ │ └── src/
315
- │ │ ├── commands/ init, check, watch, report, dev, diff, ci-gen
227
+ │ │ ├── commands/ init, check, watch, dev, diff, ci-gen
316
228
  │ │ ├── config/ .barkapi.yml loader + project detector
317
- │ │ ├── runner/ HTTP endpoint caller + check orchestrator
318
- │ │ └── output/ ESLint-style chalk formatter
229
+ │ │ └── runner/ HTTP endpoint caller + check orchestrator
319
230
  │ └── dashboard/ @barkapi/dashboard — Next.js web UI
320
231
  │ └── app/
321
- │ ├── api/ REST API routes (projects, endpoints, stats, schema, SSE)
322
- ├── components/ UI primitives, schema viewer, health ring, breadcrumbs
323
- │ ├── hooks/ usePolling, useSSE (real-time data fetching)
324
- │ └── projects/ Project pages (health map, detail, timeline, alerts)
232
+ │ ├── api/ REST API routes (SSE, stats, schema)
233
+ └── projects/ Project pages (health map, detail, timeline)
325
234
  ├── examples/ Demo project with intentional drift
326
235
  │ ├── openapi.yaml Sample OpenAPI spec
327
- ├── server.js API server with mismatched responses
328
- │ └── .barkapi.yml Pre-configured BarkAPI config
236
+ └── server.js API server with mismatched responses
329
237
  ```
330
238
 
331
- ### Tech Stack
239
+ ### ⚡️ Technologies
332
240
 
333
241
  | Layer | Technology |
334
242
  |-------|-----------|
335
- | Language | TypeScript (strict) |
336
- | CLI framework | Commander.js |
337
- | Terminal UI | chalk + ora |
338
- | API parsing | @apidevtools/swagger-parser |
339
- | Database | SQLite via better-sqlite3 (WAL mode) |
340
- | Web framework | Next.js 14 (App Router) |
341
- | Styling | Tailwind CSS (dark mode) |
342
- | Animations | Framer Motion |
343
- | Charts | Recharts |
344
- | Icons | Lucide React |
345
- | Monorepo | npm workspaces |
243
+ | **CLI & Tools** | Commander.js, chalk, ora |
244
+ | **API Parsing** | `@apidevtools/swagger-parser` |
245
+ | **Database** | SQLite via `better-sqlite3` (WAL mode) |
246
+ | **Web UI** | Next.js 14, Tailwind CSS, Framer Motion |
247
+ | **Charts & Icons** | Recharts, Lucide React |
346
248
 
347
- ---
249
+ <br/>
348
250
 
349
- ## License
251
+ ## 📝 License
350
252
 
351
- MIT
253
+ Released under the [MIT License](LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barkapi",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "API Contract Drift Detector — Your API's watchdog",
5
5
  "keywords": [
6
6
  "api",
@@ -39,6 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@apidevtools/swagger-parser": "^10.1.0",
42
+ "@barkapi/core": "1.1.0",
42
43
  "better-sqlite3": "^11.0.0",
43
44
  "chalk": "^4.1.2",
44
45
  "commander": "^12.0.0",
@@ -47,8 +48,7 @@
47
48
  "yaml": "^2.4.0"
48
49
  },
49
50
  "devDependencies": {
50
- "@barkapi/core": "0.1.0",
51
51
  "typescript": "^5.4.0",
52
52
  "vitest": "^4.0.18"
53
53
  }
54
- }
54
+ }