Skip to content

Commit a4e53a3

Browse files
kriszypclaude
andcommitted
docs: add per-folder DESIGN.md navigation for resources/ and server/
Add resources/DESIGN.md with a section index for the 4744-line Table.ts (grouped by responsibility: setup, authz, read, write, search, pub/sub, validation, stats, history) and a Resource.ts member table with line numbers. Add server/DESIGN.md mapping the three HTTP stacks (native HTTP, Operations API on Fastify, legacy Custom Functions on Fastify), the http.ts section index, and middleware ordering. Expand AGENTS.md with a repository map for all 19 top-level folders and a "Detailed navigation" pointer table to the new docs. Correct the existing "two HTTP stacks" claim to three. Goal: reduce the overhead of starting a task in this repo. Agents spending time grepping the wrong folders or top-to-bottom reading megafiles can now jump to the right place via path + line number. Generated by Claude Opus 4.7 (1M context). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 063788a commit a4e53a3

3 files changed

Lines changed: 391 additions & 6 deletions

File tree

AGENTS.md

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,20 @@ The plugin/application loader. Applications export a `handleApplication(scope)`
5959
Files within a component are discovered via micromatch glob patterns and automatically mapped to URL paths.
6060

6161
**Server** (`server/`)
62-
Two HTTP stacks coexist:
62+
Multiple HTTP entry points coexist:
6363

64-
- **Native layer** (`server/http.ts`) — direct socket handling for HTTP/1.1, HTTPS, HTTP/2, and WebSockets in one path; highest performance
65-
- **Fastify layer** (`server/fastifyRoutes.ts`) — used for legacy custom functions; wraps Fastify with autoload
64+
- **Native layer** (`server/http.ts`) — direct socket handling for application-level HTTP/1.1, HTTPS, HTTP/2, and WebSockets in one path; highest performance. Most user traffic goes through here.
65+
- **Operations API** (`server/operationsServer.ts`) — Fastify-based JSON operations API (`{operation: 'create_table', ...}`); internal/admin surface.
66+
- **Custom Functions (legacy)** (`server/fastifyRoutes.ts`) — legacy Fastify autoload for user-defined routes. Don't add new code here.
6667

67-
All inbound protocols (REST, GraphQL, MQTT, NATS, WebSockets) eventually resolve to the same **Resource interface**.
68+
All inbound protocols (REST, GraphQL, MQTT, NATS, WebSockets) eventually resolve to the same **Resource interface**. See `server/DESIGN.md` for the file-by-file map and the `http.ts` section index.
6869

6970
**Resources** (`resources/`)
7071
The universal abstraction. Everything that can be queried or mutated — database tables, caches, message topics, custom endpoints — extends `Resource` (`resources/Resource.ts`).
7172

7273
Static methods (`Resource.get`, `Resource.put`, `Resource.post`, `Resource.delete`, `Resource.patch`, `Resource.subscribe`) are the entry points and are automatically wrapped with `transactional()` for transaction management. Override instance methods (`get`, `put`, etc.) for custom behavior.
7374

74-
`Table.ts` is the database table implementation (~177KB) — the most complex file in the codebase.
75+
`Table.ts` is the database table implementation (4744 lines, one giant `makeTable()` factory) — the most complex file in the codebase. **Use `resources/DESIGN.md` as a section index instead of reading top-to-bottom.**
7576

7677
**Data Layer** (`dataLayer/`)
7778
Legacy translation modules plus SQL translation (`sqlTranslator/`) via AlaSQL; these should be avoided. The storage engine is selectable via `HARPER_STORAGE_ENGINE=lmdb`.
@@ -80,7 +81,62 @@ Legacy translation modules plus SQL translation (`sqlTranslator/`) via AlaSQL; t
8081
YAML-based. `configUtils.js` parses config; `RootConfigWatcher.ts` enables hot reload. Environment variables override YAML values.
8182

8283
**Utility** (`utility/`)
83-
Logging, error types, helpers, async utilities.
84+
Logging, error types, helpers, async utilities. Most-used: `utility/hdbTerms.ts` (global constants), `utility/logging/harper_logger.js`, `utility/errors/hdbError.js`.
85+
86+
---
87+
88+
## Repository map
89+
90+
Use this to land in the right folder before grepping. Every top-level folder is listed; deeper docs are noted where they exist.
91+
92+
### Source — covered above
93+
94+
- **`components/`** — plugin/app loader. Entry: `Scope.ts`, `OptionsWatcher.ts`. Tests: `unitTests/components/`.
95+
- **`server/`** — HTTP/WS/MQTT/etc. Entry: `operationsServer.ts` (boot), `http.ts` (native HTTP). **See [server/DESIGN.md](server/DESIGN.md).** Tests: `unitTests/server/`.
96+
- **`resources/`** — universal Resource abstraction; tables. Entry: `Resource.ts`, `Table.ts`. **See [resources/DESIGN.md](resources/DESIGN.md).** Tests: `unitTests/resources/`.
97+
- **`dataLayer/`** — legacy translation modules (`insert.js`, `search.js`, `update.js`). **Avoid for new code.** Tests: `unitTests/dataLayer/`.
98+
- **`config/`** — YAML config + hot reload. Entry: `configUtils.js`, `RootConfigWatcher.ts`. Tests: `unitTests/config/`.
99+
- **`utility/`** — logging, errors, helpers. Tests: `unitTests/utility/`.
100+
101+
### Other source folders
102+
103+
- **`bin/`** — CLI entry points. `harper.js` is the executable; `run.js` initializes and runs the server; `cliOperations.js` translates CLI args → API operations. Tests: `unitTests/bin/`. **Don't look here for** business logic.
104+
- **`security/`** — auth, authz, certificate handling, context. Entry: `jsLoader.ts` exposes `getContext()`, `getResponse()`, `getUser()`; `user.ts` for User/Role; `certificateVerification/` for TLS validation; `data_objects/` for permission/role models. Tests: `unitTests/security/`.
105+
- **`sqlTranslator/`** — SQL → internal operations via AlaSQL AST. Entry: `sqlTranslator/index.js` exports `evaluateSQL`, `processAST`, `convertSQLToAST`, `checkASTPermissions`. **Legacy — avoid for new code.** Tests: `unitTests/sqlTranslator/`.
106+
- **`validation/`** — input shape validation (Joi + `validate.js`). Entry: `validationWrapper.js`. **Not authorization** — that's in `security/`. Tests: `unitTests/validation/`.
107+
- **`upgrade/`** — version-upgrade orchestration. Entry: `directivesManager.js` exports `processDirectives()`. Per-version logic in `directives/`. Tests: `integrationTests/upgrade/`.
108+
- **`launchServiceScripts/`** — thin launchers that delegate to `server/operationsServer.ts`. `checkNodeVersion.js` is the pre-flight Node version check.
109+
- **`json/`** — system schema definitions. `systemSchema.json` defines built-in tables (`hdb_user`, `hdb_role`, `hdb_permission`). Loaded at startup; no code.
110+
111+
### Non-source
112+
113+
- **`bin/`** — covered above (it's source).
114+
- **`benchmarks/`** — HNSW vector-search benchmark only (`hnsw-search.js`). Stand-alone; not part of CI.
115+
- **`build-tools/`** — shell scripts for the build pipeline (`build.sh`, `build-studio.sh`, `download-prebuilds.js`). No tests.
116+
- **`dev/`** — single dev utility (`sync-commits.js`) for cross-repo commit syncing. Not runtime.
117+
- **`integrationTests/`** — end-to-end tests against a built distribution. Run with `npm run test:integration` / `npm run test:integration:all`. Subdirs mirror source. See `integrationTests/README.md`.
118+
- **`unitTests/`** — Mocha unit tests; subdir per source layer. Run with `npm run test:unit:<layer>`.
119+
- **`static/`** — assets only: `defaultConfig.yaml`, `ascii_logo.txt`.
120+
121+
### Top-level docs to consult
122+
123+
- **[DESIGN.md](DESIGN.md)** — running list of non-obvious internals (RecordObject prototype, getFromSource timing, blob orphan cleanup). Read this before debugging anything record-store-related.
124+
- **[dependencies.md](dependencies.md)** — rationale for every npm dependency. Required reading before adding a new package.
125+
- **[storage-format.md](storage-format.md)** — on-disk layout (RocksDB/LMDB).
126+
- **[CONTRIBUTING.md](CONTRIBUTING.md)** — contribution workflow.
127+
128+
---
129+
130+
## Detailed navigation
131+
132+
For megafiles and complex subsystems, jump to the section index instead of reading top-to-bottom:
133+
134+
| If you are touching… | Read first |
135+
| ------------------------------------------------------ | ------------------------------------------ |
136+
| Anything in `resources/` (especially `Table.ts`) | [resources/DESIGN.md](resources/DESIGN.md) |
137+
| HTTP/WS/MQTT, middleware ordering, content types | [server/DESIGN.md](server/DESIGN.md) |
138+
| Record-store internals (commit timing, blobs, encoder) | [DESIGN.md](DESIGN.md) |
139+
| Adding a dependency | [dependencies.md](dependencies.md) |
84140

85141
---
86142

0 commit comments

Comments
 (0)