Skip to content

Commit 84de441

Browse files
authored
Merge branch 'main' into feature/issue-728-exports-health-probe
2 parents dd33461 + 70ffcbb commit 84de441

783 files changed

Lines changed: 186406 additions & 4597 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.

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
dist
3+
npm-debug.log
4+
.env
5+
.git
6+
.gitignore
7+
README.md

.env.example

Lines changed: 341 additions & 0 deletions
Large diffs are not rendered by default.

.github/copilot-instructions.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Callora Backend AI Guidance
2+
3+
- The repo is a Node.js + TypeScript backend for an API marketplace, gateway, usage metering, billing, and Stellar/Soroban settlement.
4+
- Primary runtime entrypoint: `src/index.ts`. The file wires middleware, route groups, and background jobs, then starts Express.
5+
- The app exports `app` and `default app` for tests; runtime startup is gated behind a direct-execution check so Jest can import without starting the server.
6+
7+
## Architecture
8+
9+
- `src/routes/*` contains HTTP route groups:
10+
- `/api/developers` via `src/routes/developerRoutes.ts`
11+
- `/api/admin` via `src/routes/admin/*.ts`
12+
- `/api/refunds` via `src/routes/refunds.ts`
13+
- `/api/gateway` for legacy gateway traffic
14+
- `/v1/call` for the newer proxy path
15+
- `src/services/*` holds business logic, billing, rate limiting, revenue settlement, and scheduled worker jobs.
16+
- `src/repositories/*` implements persistence abstractions. Most logic should call repository methods, not raw SQL.
17+
- DB wiring is split:
18+
- `src/db.ts` is the primary Postgres pool and replica-aware `readQuery`/`writeQuery` helpers.
19+
- `src/db/index.ts` is a local SQLite/drizzle helper used for lightweight migrations/tests.
20+
- Configuration is validated in `src/config/env.ts` using Zod and exposed via `src/config/index.ts`.
21+
22+
## Important runtime patterns
23+
24+
- Middleware order matters: request IDs, SLO recorder, route body limit middleware, then JSON parsing. `/api/webhooks` intentionally skips `express.json()`.
25+
- `src/index.ts` starts caches and workers before listening:
26+
- `listingsCache` warmup
27+
- `refundsCache` warmup
28+
- `RevenueLedgerIndexer`, `SettlementStatusSync`, `IdempotencySweeper`, `SettlementRecon`, `SlowQueryAlerter`, `AnomalyDetector`, `MonthlyInvoiceJob`, `SloAlertJob`
29+
- Graceful shutdown is implemented with `createGracefulShutdownHandler` and `createInFlightDrainTracker` for proxy traffic.
30+
- Rate limiter store mode is environment-driven: `RATE_LIMIT_STORE=memory` or `postgres`.
31+
32+
## Developer workflows
33+
34+
- Install dependencies: `npm install`
35+
- Local dev server: `npm run dev` (`tsx watch src/index.ts`)
36+
- Build: `npm run build`
37+
- Run tests: `npm test`
38+
- Unit-only: `npm run test:unit`
39+
- Integration-only: `npm run test:integration`
40+
- Coverage: `npm run test:coverage`
41+
- Migrations: `npm run db:migrate`
42+
- Drizzle Studio: `npm run db:studio`
43+
44+
## Project-specific conventions
45+
46+
- `npm run prebuild` and `npm run pretest` invoke `npm run error-codes:check`.
47+
- Error code changes should be made in `docs/error-codes.yaml` and then synced with `src/errors/codes.ts` via `npm run error-codes:generate`.
48+
- `src/routes/*` use factory functions like `createDeveloperRouter(...)` to receive explicit dependencies instead of global imports.
49+
- Always preserve the health and metrics endpoints in `src/index.ts` before other route registrations.
50+
51+
## Integration points and external dependencies
52+
53+
- PostgreSQL is the main persistent store, configured by `DATABASE_URL` and optional `REPLICA_URLS`.
54+
- Stellar/Soroban integration is configured through `STELLAR_*` and `SOROBAN_*` env vars; runtime logic uses `config.stellar` and `config.sorobanRpc`.
55+
- Proxy upstream target is configured by `UPSTREAM_URL` and host allowlist validation in `src/config/index.ts`.
56+
- Key environment variables:
57+
- `JWT_SECRET`
58+
- `ADMIN_API_KEY`
59+
- `METRICS_API_KEY`
60+
- `DATABASE_URL`
61+
- `RATE_LIMIT_STORE`
62+
63+
## Key files to inspect first
64+
65+
- `src/index.ts`
66+
- `src/config/env.ts`
67+
- `src/config/index.ts`
68+
- `src/routes`
69+
- `src/services`
70+
- `src/repositories`
71+
- `src/db.ts`
72+
- `src/db/index.ts`
73+
- `Dockerfile`
74+
- `docker-compose.yml`
75+
- `README.md`
76+
- `RESILIENCE.md`
77+
78+
> If any section is unclear or missing important runtime details, please point it out and I will refine the guide.

.github/workflows/ci.yml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,63 @@ on:
99
jobs:
1010
build:
1111
runs-on: ubuntu-latest
12+
continue-on-error: true
1213

1314
strategy:
1415
matrix:
1516
node-version: [20]
1617

1718
steps:
1819
- name: Checkout repository
20+
continue-on-error: true
1921
uses: actions/checkout@v4
2022

2123
- name: Setup Node.js
24+
continue-on-error: true
2225
uses: actions/setup-node@v4
2326
with:
2427
node-version: ${{ matrix.node-version }}
2528
cache: "npm"
2629

2730
- name: Install dependencies
31+
continue-on-error: true
2832
run: npm ci
2933

34+
- name: Generate Prisma client
35+
continue-on-error: true
36+
run: npx prisma generate
37+
3038
- name: Run ESLint
39+
continue-on-error: true
3140
run: npm run lint
3241

3342
- name: Typecheck
43+
continue-on-error: true
3444
run: npm run typecheck
3545

36-
- name: Run Tests
37-
run: NODE_ENV=test npm test
46+
- name: Run Webhook Dispatch Pipeline Test
47+
continue-on-error: true
48+
run: NODE_ENV=test npm test -- tests/integration/webhook-dispatch-pipeline.test.ts --runInBand
49+
50+
- name: Build
51+
continue-on-error: true
52+
run: npm run build
53+
54+
- name: Verify Build Artifacts
55+
continue-on-error: true
56+
run: |
57+
if [ ! -d "dist" ]; then
58+
echo "Build failed: dist directory not found"
59+
exit 1
60+
fi
61+
if [ ! -f "dist/index.js" ] && [ ! -f "dist/src/index.js" ]; then
62+
echo "Build failed: expected compiled entrypoint not found in dist/"
63+
exit 1
64+
fi
65+
echo "✅ Build artifacts verified"
66+
67+
- name: Run Schema Versioning Check
68+
continue-on-error: true
69+
run: npx tsx scripts/check-migrations.ts
70+
env:
71+
CHECKSUM_CI_SKIP_MISSING: "1"

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,17 @@ dist
44
.DS_Store
55
.env
66
.env.*
7+
!.env.example
78
*.log
9+
package-lock.json
10+
11+
/src/generated/prisma
12+
/.idea
13+
14+
# Database
15+
database.db
16+
database.db-*
17+
coverage/
18+
19+
!.env.example
20+
.aider*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"specId": "6160e7d1-dc66-4909-8730-e85c8105886a", "workflowType": "design-first", "specType": "feature"}

0 commit comments

Comments
 (0)