How sbusanelli/claude-code-hooks-demo works
1. Repository purpose
This is a local Node.js/TypeScript demo focused on two things: a small e-commerce database layer built on better-sqlite3, and Claude Code hook automation around file/tool usage. There is no visible web server or distributed backend; the main runtime boundary is an in-process SQLite database accessed from TypeScript.
2. Top-level runtime boundary
The application runs under Node.js with TypeScript sources in src/. better-sqlite3 is the core persistence engine, so database access is synchronous and happens directly in-process rather than through an ORM or remote DB service.
3. Application entry points
src/main.ts is the primary executable entry point, and src/example.ts appears to provide a runnable demo path. At the root, sdk.ts / sdk.js likely expose a packaged surface for consumption or build output, but the architecture is centered on the TypeScript app in src/.
4. Domain/data model layer
src/schema.ts defines the database schema, and src/types.ts defines the TypeScript shapes used across the app. The schema represents an e-commerce domain with customers, products, orders, reviews, promotions, inventory, shipping, and analytics-related data.
5. Query subsystem
src/queries/ is the main data-access layer. It is split by business area:
customer, product, order, analytics, inventory, promotion, review, and shipping queries. These modules encapsulate SQL statements and use the synchronous better-sqlite3 API (prepare, get, all, run) with parameterized inputs.
6. Data flow through the app
The typical flow is: entry point initializes/uses the schema, then calls a domain query module, which executes SQL against the SQLite database, and returns typed results to the caller. This keeps SQL isolated from the rest of the app and makes each business domain independently testable.
7. Claude Code hook subsystem
The hooks/ directory contains the automation/security layer: read_hook.js, write_hook.js, query_hook.js, and tsc.js. These hooks sit at the boundary of Claude Code operations and can block sensitive reads/writes, deduplicate queries, and trigger TypeScript compilation on file changes.
8. Claude configuration boundary
.claude/ plus scripts/init-claude.js are the setup/configuration layer for hook activation. The repo is designed so the Claude Code runtime uses local settings to enforce its pre-tool-use workflow rules.
9. Security model
The main security boundary is file access and secret handling. The read/write hooks are intended to block .env, key material, certificates, and secret-like patterns, while the SQL layer uses parameterized queries to reduce injection risk.
10. Testing subsystem
jest.config.cjs and tests/ define a separate verification boundary around the same database layer. Tests cover connection management, schema validation, CRUD behavior, transactions, foreign keys, and performance, with tests/setup.ts providing shared test initialization.
11. Build and developer workflow
package.json, tsconfig.json, and the npm scripts drive setup, development, build, type-checking, and test execution. The project is optimized for local iteration: compile TypeScript, run the demo, execute tests, and validate hook behavior.
12. Architectural summary for a diagram
Draw this as three main zones:
- Claude Code hook layer around file/tool operations
- TypeScript app layer with entry points, schema/types, and per-domain SQL modules
- Embedded SQLite database as the persistence core
Then show tests as a parallel verification path against the same schema/query layer, not as a separate service.
Main entry points: main.ts Main · schema.ts Schema · settings.local.json Claude settings · order_queries.ts Order queries
Components 25
Claude Code hooks
File/tool boundary enforcement and local Claude configuration.
- Claude setup · Installs or initializes local Claude hook settings.
scripts/init-claude.js - Claude settings · Local Claude configuration that activates the hook workflow.
.claude/settings.local.json - Read hook · Blocks or filters sensitive reads.
hooks/read_hook.js - Write hook · Blocks sensitive writes and secret-like content.
hooks/write_hook.js - Query hook · Deduplicates or constrains query-like tool usage.
hooks/query_hook.js - TSC hook · Runs TypeScript compilation on relevant file changes.
hooks/tsc.js
TypeScript app
Node.js/TypeScript demo with e-commerce schema and domain SQL modules.
- Main · Primary executable entry point.
src/main.ts - Example · Runnable demo path for the database layer.
src/example.ts - SDK surface · Packaged surface exposed from the repository root.
sdk.ts - Schema · Defines the SQLite tables and relationships.
src/schema.ts - Types · Shared TypeScript shapes used across the app.
src/types.ts - Customer queries · Customer-facing data access and CRUD SQL.
src/queries/customer_queries.ts - Product queries · Product catalog and lookup SQL.
src/queries/product_queries.ts - Order queries · Order placement, status, and history SQL.
src/queries/order_queries.ts - Inventory queries · Stock and availability SQL.
src/queries/inventory_queries.ts - Analytics queries · Reporting and aggregate SQL.
src/queries/analytics_queries.ts - Promo queries · Promotion and discount SQL.
src/queries/promotion_queries.ts - Review queries · Product review SQL.
src/queries/review_queries.ts - Shipping queries · Fulfillment and shipment SQL.
src/queries/shipping_queries.ts
SQLite core
Embedded in-process database accessed directly by queries and tests.
- SQLite DB · Embedded synchronous persistence core.
Tests
Parallel validation path for schema, CRUD, transactions, and connection behavior.
- Test setup · Shared test initialization and fixtures.
tests/setup.ts - Connection test · Verifies database connection behavior.
tests/database.connection.test.ts - Schema test · Validates schema definitions and migration behavior.
tests/database.schema.test.ts - Integration test · Exercises end-to-end database operations.
tests/database.integration.test.ts - CRUD test · Checks CRUD behavior and transactional paths.
tests/database.test.ts
Connections 32
- Claude setup → Claude settings: installs · Creates or updates the local Claude configuration.
- Claude settings → Read hook: enables · Activates the read boundary hook.
- Claude settings → Write hook: enables · Activates the write boundary hook.
- Claude settings → Query hook: enables · Activates the query boundary hook.
- Claude settings → TSC hook: enables · Activates the compilation hook.
- Main → Schema: initializes · Main entry point uses the schema before data operations.
- Main → Types: uses · Main entry point relies on shared domain types.
- Main → Customer queries: calls · Primary runtime reaches customer data access.
- Main → Order queries: calls · Primary runtime reaches order data access.
- Example → Schema: initializes · Demo path starts from the schema layer.
- Example → Product queries: calls · Demo path exercises product data access.
- SDK surface → Main: wraps · Package surface exposes the app runtime.
- Schema → SQLite DB: defines · Schema materializes inside the embedded database.
- Customer queries → SQLite DB: executes · Customer SQL runs directly against SQLite.
- Product queries → SQLite DB: executes · Product SQL runs directly against SQLite.
- Order queries → SQLite DB: executes · Order SQL runs directly against SQLite.
- Inventory queries → SQLite DB: executes · Inventory SQL runs directly against SQLite.
- Analytics queries → SQLite DB: executes · Analytics SQL runs directly against SQLite.
- Promo queries → SQLite DB: executes · Promotion SQL runs directly against SQLite.
- Review queries → SQLite DB: executes · Review SQL runs directly against SQLite.
- Shipping queries → SQLite DB: executes · Shipping SQL runs directly against SQLite.
- Test setup → SQLite DB: prepares · Shared setup initializes the database for tests.
- Connection test → SQLite DB: verifies · Connection tests hit the embedded database.
- Schema test → Schema: verifies · Schema tests validate the table model.
- Integration test → SQLite DB: exercises · Integration tests run against the same SQLite core.
- Integration test → Order queries: exercises · Integration tests cover representative domain SQL.
- CRUD test → Schema: checks · CRUD tests depend on the schema definition.
- CRUD test → Customer queries: checks · CRUD tests exercise representative business queries.
- Read hook → Schema: guards · Read hook sits in front of sensitive source files.
- Write hook → Main: guards · Write hook protects application sources.
- Query hook → Order queries: guards · Query hook constrains query-style operations.
- TSC hook → Main: compiles · Compilation hook validates TypeScript sources.