barkapi 1.0.0 → 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 +181 -129
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,6 +1,20 @@
1
- # BarkAPI
2
-
3
- **Your API's watchdog.** Detects schema drift between your OpenAPI spec and live API responses — before things break in production.
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>
14
+
15
+ ---
16
+
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.
4
18
 
5
19
  ```
6
20
  GET /api/users/:id
@@ -13,128 +27,93 @@ GET /api/orders
13
27
  ✗ 2 breaking ⚠ 1 warning ✓ 8 passing (12 endpoints checked)
14
28
  ```
15
29
 
16
- ## Install
17
-
18
- ```bash
19
- npm install -g barkapi
20
- ```
21
-
22
- ### Prerequisites
23
-
24
- - **Node.js >= 18**
25
- - **Build tools** for native addon compilation (`better-sqlite3`):
26
- - macOS: `xcode-select --install`
27
- - Ubuntu/Debian: `sudo apt install build-essential python3`
28
- - Windows: install the "Desktop development with C++" workload from Visual Studio Build Tools
29
-
30
- ## Quick Start
31
-
32
- ```bash
33
- # Navigate to your API project
34
- cd /path/to/your-api
35
-
36
- # Initialize — auto-detects your OpenAPI spec
37
- barkapi init --spec openapi.yaml --base-url http://localhost:3000
38
-
39
- # Run a one-time check
40
- barkapi check
41
-
42
- # Start dashboard + watch mode (opens browser automatically)
43
- barkapi dev
44
- ```
45
-
46
- ## Commands
30
+ ## ✨ Highlights & Features
47
31
 
48
- ### `barkapi init`
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.
49
41
 
50
- Scans your project for OpenAPI specs, detects project metadata, and generates a `.barkapi.yml` config file.
42
+ <br/>
51
43
 
52
- ```bash
53
- barkapi init [options]
44
+ ## 📖 Real-World Use Cases
54
45
 
55
- Options:
56
- --spec <path> Path to OpenAPI spec file
57
- --base-url <url> Base URL for your API (default: http://localhost:3000)
58
- --name <name> Project name (default: from package.json)
59
- ```
60
-
61
- ### `barkapi check`
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.
62
50
 
63
- Parses your spec, calls each endpoint, diffs the response against the expected schema, and prints an ESLint-style report. Exits with code 1 on breaking drift — perfect for CI.
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.
64
55
 
65
- ```bash
66
- barkapi check [options]
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.
67
60
 
68
- Options:
69
- --config <path> Path to .barkapi.yml
70
- --spec <path> Override spec path
71
- --base-url <url> Override base URL
72
- ```
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.
73
65
 
74
- ### `barkapi dev`
66
+ <br/>
75
67
 
76
- The all-in-one development command. Starts the web dashboard and watch mode together. Auto-opens your browser.
68
+ ## 📦 Installation
77
69
 
78
70
  ```bash
79
- barkapi dev [options]
80
-
81
- Options:
82
- --config <path> Path to .barkapi.yml
83
- --interval <seconds> Check interval (default: 30)
84
- --port <port> Dashboard port (default: 3100)
85
- --no-open Don't auto-open browser
71
+ npm install -g barkapi
86
72
  ```
87
73
 
88
- ### `barkapi watch`
89
-
90
- Runs checks continuously on an interval.
91
-
92
- ```bash
93
- barkapi watch [options]
74
+ ### Prerequisites
75
+ - **Node.js >= 18**
76
+ - **Build tools** for SQLite (`better-sqlite3`):
77
+ - macOS: `xcode-select --install`
78
+ - Ubuntu/Debian: `sudo apt install build-essential python3`
79
+ - Windows: Visual Studio Build Tools (C++ Workload)
94
80
 
95
- Options:
96
- --config <path> Path to .barkapi.yml
97
- --interval <seconds> Check interval (default: 30)
98
- ```
81
+ <br/>
99
82
 
100
- ### `barkapi diff`
83
+ ## 🚀 Quick Start
101
84
 
102
- Compares two OpenAPI spec versions and shows schema differences.
85
+ Launch the watchdog in just two commands:
103
86
 
104
87
  ```bash
105
- barkapi diff <old-spec> <new-spec> [options]
106
-
107
- Options:
108
- --json Output as JSON
109
- ```
110
-
111
- ### `barkapi ci-gen`
112
-
113
- Generates a GitHub Actions workflow file for automated contract checking.
88
+ # 1. Navigate to your API project
89
+ cd /path/to/your-api
114
90
 
115
- ```bash
116
- barkapi ci-gen [options]
91
+ # 2. Initialize (auto-detects spec + setups config)
92
+ barkapi init --spec openapi.yaml --base-url http://localhost:3000
117
93
 
118
- Options:
119
- --config <path> Path to .barkapi.yml
120
- --base-url-var <var> GitHub Actions variable name (default: vars.STAGING_URL)
121
- --output <path> Output path (default: .github/workflows/barkapi.yml)
94
+ # 3. Start dashboard + watch mode
95
+ barkapi dev
122
96
  ```
97
+ *The dashboard opens at `http://localhost:3100` and auto-refreshes every 3 seconds.*
123
98
 
124
- ### `barkapi report`
99
+ <br/>
125
100
 
126
- Runs a check and prints results.
101
+ ## ⌨️ CLI Commands
127
102
 
128
- ```bash
129
- barkapi report [options]
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>` |
130
111
 
131
- Options:
132
- --config <path> Path to .barkapi.yml
133
- ```
112
+ <br/>
134
113
 
135
- ## Configuration
114
+ ## ⚙️ Configuration (`.barkapi.yml`)
136
115
 
137
- BarkAPI uses a `.barkapi.yml` file in your project root:
116
+ BarkAPI uses a simple YAML config file in your project root.
138
117
 
139
118
  ```yaml
140
119
  project: my-api
@@ -146,56 +125,129 @@ auth:
146
125
  type: bearer # bearer | header | query
147
126
  token_env: API_TOKEN # reads from environment variable
148
127
 
149
- # Optional: path parameters
128
+ # Optional: Path parameters for simulated requests
150
129
  path_params:
151
130
  id: "1"
152
131
 
153
- # Optional: filter which endpoints to check
132
+ # Optional: Endpoint Filtering
154
133
  endpoints:
155
134
  include:
156
135
  - /api/users
157
- - /api/orders
158
136
  exclude:
159
137
  - /api/internal
160
138
  ```
161
139
 
162
- ## Dashboard
163
-
164
- The `barkapi dev` command launches a web dashboard at `http://localhost:3100` with:
140
+ <br/>
165
141
 
166
- - **Bento grid layout** — health ring, stat cards, drift distribution at a glance
167
- - **Schema viewer** — interactive tree of your OpenAPI schema with drift annotations inline
168
- - **Endpoint health map** — color-coded grid showing status of every endpoint
169
- - **Drift history** — grouped by field path with side-by-side expected vs actual diffs
170
- - **Timeline charts** — area charts showing drift trends over time
171
- - **Breadcrumb navigation** — always know where you are
172
- - **Alerting** — Slack webhook and email notifications
173
- - **Real-time updates** — auto-refreshes every 3s, no manual refresh needed
142
+ ## 🔬 Drift Detection Engine
174
143
 
175
- ## Drift Detection
144
+ BarkAPI performs strict structural diffing between standard OpenAPI JSON Schemas and observed JavaScript object trees.
176
145
 
177
146
  | Drift Type | Severity | What it means |
178
147
  |------------|----------|---------------|
179
- | Removed required field | `breaking` | A required field is gone |
180
- | Removed optional field | `warning` | An optional field disappeared |
181
- | Type changed | `breaking` | Field type shifted (e.g. `string` → `number`) |
182
- | Nullable non-null | `breaking` | Consumers handling null will break |
183
- | Non-null nullable | `warning` | Field can now be null |
184
- | Required changed | `breaking` | Required/optional status changed |
185
- | Enum changed | `warning` | Allowed enum values differ |
186
- | Format changed | `warning` | Field format differs |
187
- | Undocumented field added | `info` | Response has a field not in the spec |
188
-
189
- ## CI Integration
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 |
156
+
157
+ <br/>
158
+
159
+ ## 🖥 Dashboard Experience
160
+
161
+ The `barkapi dev` command launches a web dashboard at `http://localhost:3100` with real-time updates:
162
+
163
+ | Page | Route | Description |
164
+ |------|-------|-------------|
165
+ | **Projects** | `/` | Overview cards with health donut, labeled status dots, drift count |
166
+ | **Project Detail** | `/projects/:id` | Bento grid with health ring, passing/breaking/warning stats, drift type distribution, endpoint health map |
167
+ | **Endpoint Detail** | `/projects/:id/endpoints/:eid` | Three tabs — **Overview** (stats), **Schema** (annotated tree), **History** (drift list grouped by field) |
168
+ | **Timeline** | `/projects/:id/timeline` | Area/line/bar charts + check run cards with mini health rings |
169
+ | **Alerts** | `/projects/:id/alerts` | Configure Slack and email notifications with severity filters |
170
+
171
+ <br/>
172
+
173
+ ## 🧪 Example Project
174
+
175
+ The [`examples/`](https://github.com/mruduljohn/BarkAPI/tree/main/examples) directory contains a complete demo with intentional drift to see how BarkAPI reacts:
176
+
177
+ ```bash
178
+ # 1. Start the example API server (has intentional drift from spec)
179
+ cd examples
180
+ node server.js
181
+
182
+ # 2. In another terminal, run BarkAPI against it
183
+ cd examples
184
+ barkapi init --spec openapi.yaml --base-url http://localhost:4000
185
+ barkapi dev
186
+ ```
187
+
188
+ The example server returns responses that intentionally differ from its OpenAPI spec:
189
+ - `GET /api/users/:id` — `email` is a number (spec says string), missing `created_at`, extra `avatar` field
190
+ - `GET /api/products/:id` — `price` is a string (spec says number)
191
+
192
+ <br/>
193
+
194
+ ## 🤖 CI Integration
195
+
196
+ ### GitHub Actions
190
197
 
191
198
  ```yaml
192
- # GitHub Actions
193
199
  - name: Check API contracts
194
- run: npx barkapi check --spec openapi.yaml --base-url ${{ vars.STAGING_URL }}
200
+ run: |
201
+ npx barkapi check --spec openapi.yaml --base-url ${{ vars.STAGING_URL }}
202
+ ```
203
+
204
+ Or generate a workflow file automatically:
205
+
206
+ ```bash
207
+ barkapi ci-gen --base-url-var vars.STAGING_URL
195
208
  ```
196
209
 
197
- Or generate a workflow automatically: `barkapi ci-gen`
210
+ > 💡 The `check` command gracefully exits with code 1 on breaking drift, failing your pipeline automatically.
211
+
212
+ <br/>
213
+
214
+ ## 🏗 Architecture & Stack
215
+
216
+ ```text
217
+ BarkAPI/
218
+ ├── packages/
219
+ │ ├── core/ @barkapi/core — shared engine
220
+ │ │ └── src/
221
+ │ │ ├── parser/ OpenAPI parser + response schema inferrer
222
+ │ │ ├── diff/ Recursive schema differ + severity classifier
223
+ │ │ ├── db/ SQLite connection, schema migration, queries
224
+ │ │ └── models/ CRUD for projects, endpoints, runs, alerts
225
+ │ ├── cli/ barkapi — the npm package
226
+ │ │ └── src/
227
+ │ │ ├── commands/ init, check, watch, dev, diff, ci-gen
228
+ │ │ ├── config/ .barkapi.yml loader + project detector
229
+ │ │ └── runner/ HTTP endpoint caller + check orchestrator
230
+ │ └── dashboard/ @barkapi/dashboard — Next.js web UI
231
+ │ └── app/
232
+ │ ├── api/ REST API routes (SSE, stats, schema)
233
+ │ └── projects/ Project pages (health map, detail, timeline)
234
+ ├── examples/ Demo project with intentional drift
235
+ │ ├── openapi.yaml Sample OpenAPI spec
236
+ │ └── server.js API server with mismatched responses
237
+ ```
238
+
239
+ ### ⚡️ Technologies
240
+
241
+ | Layer | Technology |
242
+ |-------|-----------|
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 |
248
+
249
+ <br/>
198
250
 
199
- ## License
251
+ ## 📝 License
200
252
 
201
- 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.0",
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
+ }