Skip to content

Commit 5cd5ac4

Browse files
author
Intent Layer Generator
committed
Add Intent Layer (77 AGENTS.md files)
Generated AGENTS.md files for semantic clusters: - packages/app/server/AGENTS.md - packages/app/server/src/AGENTS_defines_provider_typ_5e8780f9.md - packages/app/server/src/AGENTS_encapsulates_logic_5da8044e.md - packages/app/server/src/AGENTS_implements_an_expres_f061fb01.md - packages/app/server/src/AGENTS_manages_payment_aeac3a11.md - packages/app/server/src/AGENTS_manages_refund_respo_c5eeb818.md - packages/app/server/src/AGENTS_manages_the_process_901a8c55.md - packages/app/server/src/AGENTS_provides_core_fcd0f737.md - packages/app/server/src/AGENTS_this_area_defines_ead39b3f.md - packages/app/server/src/AGENTS_this_area_manages_3bd42be3.md - packages/app/server/src/AGENTS_this_area_manages_4800216f.md - packages/app/server/src/AGENTS_this_area_manages_823347d1.md - packages/app/server/src/AGENTS_this_area_manages_97cf148e.md - packages/app/server/src/AGENTS_this_cluster_encapsu_93e48bad.md - packages/app/server/src/AGENTS_this_cluster_encapsu_f23e8ac4.md - packages/app/server/src/AGENTS_this_cluster_manages_0ca5d551.md - packages/app/server/src/AGENTS_this_cluster_manages_114d484f.md - packages/app/server/src/AGENTS_this_cluster_manages_130feebf.md - packages/app/server/src/AGENTS_this_cluster_manages_17eb35b0.md - packages/app/server/src/AGENTS_this_cluster_manages_1e736bc2.md ... and 57 more
1 parent c568c95 commit 5cd5ac4

77 files changed

Lines changed: 3798 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/app/server/AGENTS.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Server Configuration Modules (packages/app/server)
2+
3+
## Purpose
4+
This cluster manages configuration files for the server environment, including testing, build, and linting setups. It ensures consistent tooling behavior across development and CI environments.
5+
6+
## Boundaries
7+
- **Belongs here:** `vitest.config.ts`, `tsup.config.ts`, `eslint.config.mjs`—all define environment-specific tooling configurations.
8+
- **Does NOT belong here:** Application business logic, runtime server code, or deployment scripts. These configs are static and do not influence runtime behavior directly.
9+
10+
## Invariants
11+
- All configuration files must export a default configuration object via `defineConfig`.
12+
- Config files should avoid side effects; they are purely declarative.
13+
- The `vitest.config.ts` and `tsup.config.ts` are frequently updated, so agents must handle potential breaking changes or schema updates.
14+
- ESLint config (`eslint.config.mjs`) must adhere to ECMAScript Module syntax and be compatible with the project's linting standards.
15+
- No circular dependencies should exist between configs; each should be self-contained.
16+
17+
## Patterns
18+
- Use `defineConfig` to wrap configuration objects for type safety and consistency.
19+
- Maintain naming conventions: `vitest.config.ts`, `tsup.config.ts`, `eslint.config.mjs`.
20+
- For TypeScript configs, prefer explicit types where possible.
21+
- Handle errors gracefully; configs should fail to load if invalid, but avoid silent failures.
22+
- Keep configurations minimal; extend base configs only when necessary.
23+
- Frequently modified files (5 versions each) suggest the need for careful review when editing to prevent breaking changes.
24+
25+
## Pitfalls
26+
- Modifying `vitest.config.ts` or `tsup.config.ts` without updating related build/test scripts can cause environment failures.
27+
- Changing ESLint config syntax or rules may silently break linting if not validated.
28+
- Overriding default behaviors in configs may lead to inconsistent tooling behavior.
29+
- Frequent churn indicates these configs are sensitive; avoid unnecessary modifications.
30+
- Be cautious with dependencies imported into configs; ensure they are compatible and correctly versioned.
31+
32+
## Dependencies
33+
- `defineConfig` from the relevant configuration libraries (e.g., Vite, Tsup, ESLint). Use it to ensure proper typing and structure.
34+
- External plugins or presets used within configs must be compatible with the current versions.
35+
- Do not introduce runtime dependencies into static configs unless explicitly supported; configs should be self-contained.
36+
- When extending configs, verify that dependencies are correctly installed and compatible with the existing setup.
37+
38+
---
39+
40+
**Summary:**
41+
This cluster encapsulates static tooling configurations critical for development consistency. Agents must handle frequent updates, avoid breaking invariants, and respect the separation from runtime code. Proper use of `defineConfig` and adherence to naming, syntax, and dependency standards are essential for stability.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# ProviderType Module & createX402Transaction Method
2+
3+
## Purpose
4+
Defines provider types used for transaction processing and implements `createX402Transaction`, an async method that generates a `TransactionCosts` object based on a given `Transaction`. This facilitates dynamic transaction cost calculation within the provider ecosystem.
5+
6+
## Boundaries
7+
- **Belongs here:**
8+
- Provider type definitions (`ProviderType.ts`) that categorize or configure different transaction providers.
9+
- Implementation of `createX402Transaction`, which encapsulates logic for creating a specific transaction cost report.
10+
- **Does NOT belong here:**
11+
- Core transaction processing logic unrelated to provider types.
12+
- External API integrations or database access—these should be abstracted or delegated elsewhere.
13+
- Utility functions or shared helpers unrelated to provider type definitions or transaction cost creation.
14+
15+
## Invariants
16+
- `createX402Transaction` must always return a `TransactionCosts` object, never null or undefined.
17+
- The method should handle all `Transaction` inputs gracefully, including invalid or incomplete data, by throwing or returning error states as per the application's error handling pattern.
18+
- The `Transaction` parameter must be validated before processing; invalid transactions should not produce a `TransactionCosts` object.
19+
- The function must preserve data integrity: no mutation of input `Transaction`, and all outputs must accurately reflect the input's details plus calculated costs.
20+
- The method must respect the contract that it is asynchronous; any synchronous operations should be wrapped or awaited appropriately.
21+
- Provider types in `ProviderType.ts` should be immutable or controlled; avoid runtime modifications that could break type assumptions.
22+
23+
## Patterns
24+
- Use explicit, descriptive naming for variables and functions; e.g., `createX402Transaction`.
25+
- Implement comprehensive error handling: catch exceptions, validate inputs, and propagate errors in a consistent manner.
26+
- Follow the project's coding style for async functions, including proper use of `await`.
27+
- When modifying, ensure that any new provider types or transaction cost calculations adhere to existing data schemas and validation rules.
28+
- Maintain separation of concerns: `ProviderType.ts` should only define types/constants; `createX402Transaction` should focus solely on transaction cost creation logic.
29+
30+
## Pitfalls
31+
- **Churn risk:** Both the module and method are frequently modified; introducing incompatible changes can break assumptions.
32+
- **Coupling:** Since the method depends on `Transaction` and returns `TransactionCosts`, ensure these types are stable; avoid tight coupling to external modules that may change.
33+
- **Null safety:** Failing to validate `Transaction` inputs could lead to runtime errors or inconsistent `TransactionCosts`.
34+
- **Type assumptions:** Misalignment between `Transaction` and `TransactionCosts` schemas can cause subtle bugs; enforce strict validation.
35+
- **Asynchronous handling:** Forgetting to `await` the async method can cause unpredictable behavior downstream.
36+
- **Provider type modifications:** Changes in `ProviderType.ts` should be reflected in all dependent logic to prevent mismatches.
37+
38+
## Dependencies
39+
- **Transaction:** Must be validated and processed according to its schema; ensure any updates to `Transaction` are reflected here.
40+
- **TransactionCosts:** The output schema; understand its fields and constraints to produce valid results.
41+
- **TypeScript types:** Use the types from `ProviderType.ts` to enforce correct provider categorization.
42+
- **Error handling conventions:** Follow existing patterns for propagating errors from `createX402Transaction`.
43+
- **External configs or constants:** If any provider-specific parameters are used, ensure they are correctly imported and used consistently.
44+
45+
---
46+
47+
**Note:** Be vigilant about frequent modifications in both the module and method—test thoroughly after changes to prevent regressions.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Package: packages/app/server/src
2+
3+
## Purpose
4+
Encapsulates server-side logic for user spend management and error handling, focusing on retrieving balances, updating user spend pools, and managing upstream response errors. It provides core transactional and error-resilient operations critical to financial workflows.
5+
6+
## Boundaries
7+
- **Includes:**
8+
- `getBalance()`: Fetches total user balance, likely from a database or cache.
9+
- `upsertUserSpendPoolUsage()`: Atomically updates or inserts user spend pool records within a Prisma transaction, ensuring data consistency during concurrent operations.
10+
- `handleUpstreamError()`: Processes upstream HTTP responses, throwing or handling errors based on response status or content.
11+
12+
- **Excludes:**
13+
- User authentication/authorization logic (should be handled upstream).
14+
- External payment gateways or external API integrations beyond response error handling.
15+
- Business logic for spend pool creation, deletion, or complex validation (beyond basic upsert).
16+
- UI rendering or client-side code.
17+
- Non-transactional data retrieval or background jobs.
18+
19+
## Invariants
20+
- `upsertUserSpendPoolUsage()` must be invoked within an active Prisma transaction (`tx`) to ensure atomicity.
21+
- `getBalance()` must return a non-negative number; if negative, it indicates a data inconsistency.
22+
- `handleUpstreamError()` must never swallow errors silently; it should throw or escalate after processing.
23+
- All methods assume proper dependency injection; no internal state is maintained.
24+
- Null or undefined `userId`, `spendPoolId`, or `amount` parameters are invalid; validation should be enforced externally or at call sites.
25+
- `amount` must be a `Decimal` object, not a primitive number, to avoid precision errors.
26+
- Response handling in `handleUpstreamError()` should consider HTTP status codes and response body content to determine error severity.
27+
28+
## Patterns
29+
- Use explicit async/await syntax for all I/O operations.
30+
- Consistent error handling: `handleUpstreamError()` processes `Response` objects, throwing on error status.
31+
- Transactional integrity: `upsertUserSpendPoolUsage()` requires a Prisma `TransactionClient` passed explicitly, emphasizing explicit transaction boundaries.
32+
- Naming conventions:
33+
- Methods prefixed with `get` or `fetch` for retrieval.
34+
- Methods prefixed with `upsert` for create/update logic.
35+
- Error handling methods prefixed with `handle`.
36+
- Decimal usage for monetary amounts to prevent floating-point inaccuracies.
37+
- Frequent modifications suggest these methods are core to spend and balance logic, requiring careful change management.
38+
39+
## Pitfalls
40+
- **Churn Hotspots:**
41+
- `getBalance()`, `upsertUserSpendPoolUsage()`, `handleUpstreamError()` have high churn; modifications risk introducing regressions or inconsistencies.
42+
- Changes to `getBalance()` must consider caching or external data sources; frequent updates may affect performance or correctness.
43+
- `upsertUserSpendPoolUsage()` must handle concurrent updates; improper transaction handling can cause race conditions or data corruption.
44+
- `handleUpstreamError()` must correctly interpret varied response formats; misinterpretation can lead to unhandled errors or silent failures.
45+
46+
- **Common mistakes:**
47+
- Omitting transaction context in `upsertUserSpendPoolUsage()`.
48+
- Not validating input parameters before calling these methods.
49+
- Ignoring the need for consistent error propagation in `handleUpstreamError()`.
50+
- Assuming `getBalance()` is always accurate without considering cache invalidation or external data refresh.
51+
52+
## Dependencies
53+
- **Prisma.TransactionClient:**
54+
- Must be a valid Prisma transaction context; ensure caller manages transaction lifecycle.
55+
- Do not reuse transaction clients outside their scope.
56+
57+
- **Decimal:**
58+
- Use the `Decimal` class for `amount` to maintain precision; avoid primitive number types.
59+
60+
- **Response (globalThis.Response):**
61+
- Handle HTTP status codes (e.g., 4xx, 5xx) explicitly; consider response body content for detailed error info.
62+
- Do not assume all responses are successful; always check status before processing.
63+
64+
- **External APIs:**
65+
- No external dependencies are directly imported; assume all external interactions are via `Response` objects passed to `handleUpstreamError()`.
66+
67+
---
68+
69+
**Note:**
70+
Agents modifying this code should prioritize maintaining transactional integrity, input validation, and error handling consistency. Frequent churn areas require thorough testing to prevent regressions.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Trace Logging Middleware (packages/app/server/src)
2+
3+
## Purpose
4+
Implements an Express middleware function `traceLoggingMiddleware` that logs request details for tracing and debugging purposes. It ensures consistent logging for incoming requests and their lifecycle within the server.
5+
6+
## Boundaries
7+
- **Belongs here:** Request lifecycle logging, middleware setup, request context enrichment.
8+
- **Does NOT belong here:** Business logic, route handling, response formatting, error handling beyond logging, schema definitions (handled in `descriptionForRoute.ts`), or external request processing.
9+
10+
## Invariants
11+
- `traceLoggingMiddleware` must always call `next()` exactly once, regardless of errors.
12+
- It must log at the start of request processing and after response is sent, capturing request method, URL, headers, and response status.
13+
- Null-safety: `req`, `res`, and `next` are guaranteed to be non-null; no null checks needed.
14+
- Response status should be captured after response finishes, not before.
15+
- Logging should not block or delay response; perform asynchronously if needed.
16+
- Middleware must not modify `req` or `res` objects unless explicitly intended for tracing.
17+
- Churn: Frequently modified (5 versions); ensure backward compatibility with previous logging formats.
18+
19+
## Patterns
20+
- Use consistent naming: `traceLoggingMiddleware`.
21+
- Log request details at the start (`req.method`, `req.url`, headers) and after response (`res.statusCode`).
22+
- Attach event listeners to `res` (`finish` event) for capturing response completion.
23+
- Handle errors gracefully; ensure `next()` is called even if logging fails.
24+
- Use external dependencies (`bodies`, `response`, `status`) for structured logging and response handling.
25+
- Maintain idempotency: middleware should be safe to call multiple times without side effects.
26+
- Follow existing code style: arrow functions, explicit types, minimal side effects.
27+
28+
## Pitfalls
29+
- Forgetting to call `next()`, causing request hang or deadlock.
30+
- Logging after response has already been sent, missing status code.
31+
- Not handling errors in logging, leading to unhandled exceptions.
32+
- Modifying request or response objects unintentionally.
33+
- Churn: frequent modifications increase risk of breaking invariants; test thoroughly.
34+
- Over-logging: avoid sensitive data exposure in logs.
35+
- Churn hotspots imply the middleware may evolve; monitor for breaking changes.
36+
37+
## Dependencies
38+
- **request:** Used to access request data; must be used carefully to avoid blocking.
39+
- **bodies:** For parsing request bodies if needed for logging (not shown explicitly here).
40+
- **response:** For structured response data, if applicable.
41+
- **status:** For standardized status code handling.
42+
- **External logging library (implied):** Ensure logs are asynchronous and non-blocking.
43+
- Use these dependencies according to their API contracts; avoid side effects or assumptions about their internal state.
44+
45+
---
46+
47+
**Note:** Given the frequent modifications, always review recent changes for compatibility, especially around response lifecycle handling and logging formats.

0 commit comments

Comments
 (0)