Advanced Integration / Real Backend Harness
This page documents a real consumer-project validation harness built around@alpha.consultings/eloquent-orm.js.
The goal was not a toy CRUD demo. The goal was to prove the package in a realistic backend system, catch runtime issues early, and document what a clean integration looks like when you combine:
- Express routing
- a dedicated router layer
- service-layer ORM usage
- JWT access tokens
- refresh token rotation
- PostgreSQL runtime validation
- Memcached-backed cache reads
- Docker-backed integration tests
What we achieved
This consumer-project pass now proves that@alpha.consultings/eloquent-orm.js can hold a realistic backend shape with:
- Express routing and clean router/service boundaries
- JWT access tokens and refresh token rotation
- authenticated user and post APIs
- PostgreSQL migrations, seeding, and runtime CRUD
- Memcached-backed cache reads for public post routes
- Docker-backed integration validation
- harness-local API docs with one JSON metadata file per documented endpoint
Architecture overview
The harness uses a clean backend layout:src/app/http/createBlogApiApp.ts: builds the Express application and registers models oncesrc/app/router/index.ts: API composition pointsrc/app/router/authRouter.ts: auth endpointssrc/app/router/postRouter.ts: REST endpoints for blog postssrc/app/services/AuthService.ts: register, login, refresh, and logout logicsrc/app/services/BlogPostService.ts: service-layer read/write behavior and cache invalidationsrc/app/cache/MemcachedPostCache.ts: shared cache adaptersrc/app/middleware/authenticateAccessToken.ts: Bearer token middlewaresrc/app/middleware/errorHandler.ts: HTTP error normalization
- controllers and routers stay thin
- the service layer owns ORM calls and cache strategy
- authentication stays in dedicated auth services and middleware
- Docker owns external infrastructure for repeatable tests
Folder structure
Typical consumer-project layout:- generated models, services, controllers, factories, and migrations came from CLI scenario generation
- hand-written auth, cache, middleware, router composition, and test harness code wrapped those generated artifacts into a real backend
Step-by-step integration flow
1. Consumer project setup
The consumer app pins the package as a normal dependency:expressjsonwebtokendotenv@faker-js/faker
2. Scenario generation
The harness started from generated scenario artifacts:- models
- services
- controllers
- factories
- PostgreSQL migrations
- scenario seed structure
3. Backend shaping
After generation, the backend was hardened into a real REST API:- the generated service/controller surface was wrapped in explicit Express routers
- a dedicated auth layer was added for login, refresh, and logout
- JWT access tokens protected write routes
- refresh tokens were stored and rotated through a
RefreshTokenmodel - public post reads were cached through Memcached
4. PostgreSQL-first validation
The first serious runtime target was PostgreSQL. That validation sequence was:5. Docker-backed infrastructure
The consumer app used Docker Compose to run:- PostgreSQL 16
- Memcached 1.6
Auth flow
The harness uses a practical auth model:POST /api/auth/login- access token is returned for protected route access
- refresh token is stored server-side through the
RefreshTokenmodel POST /api/auth/refreshrotates the refresh token and issues a new access tokenPOST /api/auth/logoutrevokes the current refresh token
- credential lookup
- persisted refresh token sessions
- token revocation checks
- protected service-layer writes
POST /api/postsPATCH /api/posts/:idDELETE /api/posts/:id
Cache strategy
The harness uses Memcached for public post reads. Design rules:- reads are cache-first
- writes invalidate cache keys
- cache failure is non-fatal for correctness
- the service layer, not the router, owns cache policy
GET /api/postsGET /api/posts/:slug
- first read returns
x-cache: MISS - second read returns
x-cache: HIT
Docker test flow
The consumer app ships a Docker-backed integration runner:- start PostgreSQL and Memcached through Docker Compose
- wait for infrastructure ports
- run the Node integration suite
- tear down containers and volumes
Key test files
The harness is intentionally documented through the exact files that matter:src/tests/blog-auth-cache.test.ts- verifies password hashing and token behavior
src/tests/blog-api-pg.integration.test.ts- validates login, JWT-protected writes, refresh rotation, logout, and cache-hit behavior
src/tests/support/testHarness.ts- owns server boot, CLI execution, request helpers, and cleanup
docs/plans/Blog-Backend-Main-Plan.md- top-level planning document
docs/plans/Blog-Backend-Auth-Plan.md- auth-focused planning slice
docs/plans/Blog-Backend-Data-Cache-Docker-Plan.md- PostgreSQL, Memcached, and Docker slice
Lessons and bugs found while integrating
This is the main reason to document the harness: it caught real package-facing integration issues. Examples from the consumer-project pass:- a stale seeded password hash no longer matched the runtime password verifier
- cache invalidation originally behaved as if it were mandatory for writes; the harness proved it must stay best-effort
- the integration harness needed explicit cache flushing between runs to avoid ambient state leaks
- Windows Docker test orchestration needed safer command launching
- PostgreSQL runtime validation exposed migration lifecycle and connection-handling rough edges faster than isolated unit tests
Why this page exists
This is not core quick-start material. It is advanced validation material. Use it when you want to answer questions like:- Can this package hold up inside a real Express backend?
- Does JWT auth work cleanly with service-layer ORM usage?
- Can public REST reads be cached without polluting controllers?
- Can Docker-backed PostgreSQL tests exercise the package predictably?
- Will a consumer-project harness catch issues that package-local tests might miss?