-
Notifications
You must be signed in to change notification settings - Fork 125
docs: add AGENTS.md for AI coding agent guidance #306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # AGENTS.md | ||
|
|
||
| Lightweight web framework for AWS Lambda with **zero external dependencies**. Express.js-like API for serverless apps, supporting API Gateway v1/v2 and ALB event formats. | ||
|
|
||
| ## Commands | ||
|
|
||
| ```bash | ||
| npm test # Type tests (tsd) + Jest unit tests | ||
| npm run test:unit # Jest unit tests only | ||
| npm run test:unit -- __tests__/routes.unit.js # Run a single test file | ||
| npm run test:types # TypeScript definition tests (tsd) | ||
| npm run test-cov # Jest with coverage | ||
| npm run test-ci # Full CI: lint + format + tests + coverage | ||
| npm run lint:check # ESLint check | ||
| npm run lint:fix # ESLint auto-fix | ||
| npm run prettier:check # Prettier check | ||
| npm run prettier:write # Prettier auto-fix | ||
| ``` | ||
|
|
||
| ## Architecture | ||
|
|
||
| **Entry point**: `index.js` — main `API` class. Handles route registration, middleware management, and the `run()` method that processes Lambda events. | ||
|
|
||
| **Core modules** in `lib/`: | ||
|
|
||
| - `request.js` — Parses Lambda event into Express-like request object (headers, query, params, body, auth) | ||
| - `response.js` — Response builder: `json()`, `html()`, `send()`, `redirect()`, `sendFile()`, `cookie()`, `cors()` | ||
| - `utils.js` — Path parsing, URL encoding, HTML escaping, MIME lookup, body parsing | ||
| - `logger.js` — Built-in logging with sampling, custom levels, and serializers | ||
| - `errors.js` — Custom error classes: `RouteError`, `MethodError`, `ConfigurationError`, `ApiError`, `FileError`, `ResponseError` | ||
| - `compression.js` — Brotli/Gzip/Deflate response compression | ||
| - `s3-service.js` — S3 file operations and pre-signed URLs (`@aws-sdk/client-s3` peer dep) | ||
|
naorpeled marked this conversation as resolved.
Outdated
|
||
|
|
||
| **Request/response flow**: Lambda event → `REQUEST` parses event → execution stack built from matched routes + middleware → handlers run sequentially via `next()` → `RESPONSE` formats output for API Gateway/ALB. | ||
|
|
||
| **Routing internals**: Routes stored in a hierarchical tree (`_routes` object). Path parameters become `__VAR__` markers. Wildcard routes (`/*`) supported. Execution stacks are method-specific with middleware inheritance. | ||
|
|
||
| **Type definitions**: `index.d.ts` with type tests in `index.test-d.ts` (validated via `tsd`). | ||
|
|
||
| ## Code Style | ||
|
|
||
| - JavaScript ES6+ with `'use strict'` | ||
| - Single quotes, enforced by Prettier | ||
| - ESLint with `eslint:recommended` + `prettier` | ||
| - JSDoc file headers with author and license | ||
| - Use custom error classes from `lib/errors.js`, not raw `Error` | ||
|
|
||
| Example handler pattern: | ||
|
|
||
| ```javascript | ||
| // Route handler | ||
| api.get('/users/:id', async (req, res) => { | ||
| return { id: req.params.id }; | ||
| }); | ||
|
|
||
| // Error middleware (4 params) | ||
| api.use((err, req, res, next) => { | ||
| res.status(500).json({ error: err.message }); | ||
| }); | ||
| ``` | ||
|
|
||
| ## Testing | ||
|
|
||
| - Tests live in `__tests__/*.unit.js` | ||
| - Sample Lambda events in `__tests__/sample-*.json` | ||
| - Always test with API Gateway v1, v2, and ALB event formats | ||
| - Update type definitions in `index.d.ts` for public API changes, then run `npm run test:types` | ||
|
|
||
| ## Boundaries | ||
|
|
||
| **Never do:** | ||
|
|
||
| - Add external npm dependencies (zero-dependency policy is non-negotiable) | ||
| - Introduce breaking changes to the public API | ||
|
|
||
| **Always do:** | ||
|
|
||
| - Add unit tests in `__tests__/*.unit.js` for new features | ||
| - Update `index.d.ts` when changing the public API | ||
| - Maintain backwards compatibility | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.