Code layout¶
amw/
βββ src/
β βββ main.ts entry point: defaults NODE_ENV, starts AmwServer
β βββ server/
β β βββ AmwServer.ts Express app, routes, middleware, Redis, lifecycle
β β βββ AmwApi.ts /product, /products and widget asset handlers
β β βββ Paapi.ts Amazon Creators API client and product mapping
β β βββ AmazonError.ts classification of Amazon failures (502/503/504)
β β βββ Resilience.ts request coalescing, not-found cache, circuit breaker
β β βββ Schemas.ts zod validation of the query parameters
β β βββ CacheControl.ts per-route Cache-Control helpers
β β βββ Stats.ts usage statistics in Redis, /click beacon
β β βββ AdminApi.ts admin portal API, login and static files
β β βββ Insights.ts AI insights on the statistics (Claude API)
β β βββ Settings.ts typed configuration, read and validated once
β β βββ OpenApi.ts OpenAPI 3.1 document (Swagger UI)
β βββ utils/logger.ts loggers and request logging (pino)
β βββ utils/metrics.ts Prometheus metrics (prom-client)
β βββ widgets/ browser widget (plain JavaScript) and its stylesheet
βββ admin/ admin portal (Vue 3 + Vite + Chart.js, own package.json)
β βββ src/components/ views, activity bar, charts and tables
β βββ src/navigation.ts hash routes (#/overview, #/pagesβ¦)
β βββ src/theme.ts light / dark theme
β βββ tests/ component tests (Vitest)
βββ tests/
β βββ *.test.ts unit tests (Jest)
β βββ helpers/ config / SDK test doubles, in-memory Redis
β βββ e2e/
β βββ *.e2e.test.ts API end-to-end tests
β βββ browser/*.spec.ts Playwright tests
β βββ config/e2e.yml configuration used by the e2e server
β βββ support/ mock Amazon API, server launcher
βββ config/
β βββ sample.yml template for config/production.yml
β βββ docker.yml defaults of the Docker image
β βββ development.yml defaults of npm run dev and the dev container
β βββ custom-environment-variables.yml environment variable mapping
βββ docker/
β βββ Dockerfile production image (multi-stage, non-root)
β βββ Dockerfile.dev development image
β βββ docker-compose.yml production stack (AMW + Redis)
β βββ docker-compose.dev.yml development stack (hot reload + Redis)
β βββ config/redis/redis.conf Redis settings of the production stack
β βββ scripts/ build.sh, validate.sh
βββ scripts/
β βββ build-widgets.js minifies the widget into dist/widgets/
β βββ build-admin.js builds the admin portal into dist/admin/
β βββ dev-mock.ts npm run dev:mock: AMW against a mock Amazon API
β βββ docs-screenshots.ts captures the documentation screenshots
β βββ test-docker.sh Docker smoke test used by CI
βββ docs/ this documentation (MkDocs Material)
βββ resources/ logo and screenshot shipped in the npm package
βββ .devcontainer/ VS Code Dev Containers setup
βββ .github/ workflows, issue forms, PR template, Dependabot
βββ .env.example environment variable template (copy to .env)
βββ start.sh entry point: local, dev, docker and stop modes
βββ AGENTS.md contribution rules for humans and AI agents
βββ SECURITY.md security policy
βββ mkdocs.yml documentation site configuration
Build output¶
npm run build writes dist/:
| Path | Produced by |
|---|---|
dist/main.js, dist/server/, dist/utils/ |
tsc (CommonJS, with source maps) |
dist/widgets/widget.js, widget.css |
scripts/build-widgets.js (terser), served by /widget.js and /widget.css |
dist/widgets/widget.<hash>.js\|css, manifest.json |
scripts/build-widgets.js: content-hashed copies, cached as immutable |
dist/admin/ |
scripts/build-admin.js (Vite), served at <path>/admin/ when Admin.enabled |
The npm package ships dist/, config/sample.yml, config/docker.yml,
config/custom-environment-variables.yml, resources/, README.md and LICENSE.
The Docker image ships dist/, the production node_modules, config/docker.yml,
config/custom-environment-variables.yml and resources/.
Where to change what¶
| Change | Files |
|---|---|
| New endpoint or middleware | src/server/AmwServer.ts, src/server/OpenApi.ts, tests/server.test.ts, HTTP API |
| Product fields from Amazon | src/server/Paapi.ts (defaultResources, buildProduct), tests/paapi.test.ts |
| Card look or behaviour | src/widgets/widget.js, src/widgets/widget.css, tests/widget.dom.test.ts, then npm run docs:screenshots |
| Admin portal view | admin/src/components/, admin/src/navigation.ts, admin/tests/, Administration portal |
| Statistics or insights | src/server/Stats.ts, src/server/AdminApi.ts, src/server/Insights.ts, tests/stats.test.ts, tests/admin-api.test.ts, tests/insights.test.ts |
| New configuration key | config/*.yml, config/custom-environment-variables.yml, .env.example, Configuration |