R2WX [2024] — Exploring Full-Stack Infrastructure: Shared Knowledge, Reusable Procedures, Explicit Boundaries and Controlled Specialization
The complete R2WX infrastructure, including runnable Docker Compose environments, verified CRUD lifecycles, and architectural documentation, is publicly available. GitHub: https://github.com/manos-zalokostas/R2WX We bu
The complete R2WX infrastructure, including runnable Docker Compose environments, verified CRUD lifecycles, and architectural documentation, is publicly available. GitHub: https://github.com/manos-zalokostas/R2WX
We build forms. We implement CRUD operations. We validate data at multiple stages. We handle REST endpoints, authentication and persistence. Each application is different, yet we repeatedly find ourselves implementing concepts we've already implemented elsewhere — and then maintaining and synchronizing those implementations as they evolve.
Eventually, a question arises: how many times should we implement the same concepts?
Sharing code seems like the obvious answer. But consolidation introduces its own problems. Shared schemas can blur application ownership. Reusable controllers can expose operations that were never intended to be available. Automation can simplify common cases while making exceptional ones harder to implement.
R2WX explores where reuse could stop and where independent application responsibility could begin.
R2WX [2024] grew out of exploring these questions across a full-stack environment built with SvelteKit, NestJS, Prisma and MySQL.
[ @r2wx/modules ]
Shared Scheme Factories
canonical application semantics
|
+----------------+----------------+
| |
v v
[ front/.../ctx.js ] [ back/.../config.ts ]
Frontend Orchestrator Backend Orchestrator
| |
| +-- API/path/access configuration
v v
[ packEntityForm ] [ BaseController ]
scheme + literals + data configured CRUD / endpoint machinery
+ runtime DB options |
| +-----+----------------+
v v v
[ R2wxFieldsetInput ] [ Multipart Ingestion ] [ Validation.ts ]
native HTML input semantics scheme-derived Multer strict / loose
<Tag {...entity}> fileSize limits validation
| | |
v +----------+-----------+
[ FORM State Machine ] |
ADD / READ / EDIT / DEL v
field state / actions / modal [ BaseService ]
/ HTTP verb dispatch |
| v
v [ Prisma ]
[ Form Payload Resolution ] |
JSON or FormData v
| [ MySQL ]
+-- bounded override Independent Persistence Authority
| via $action.submit()
v
[ SvelteKit BFF ]
human auth/session boundary
multipart stream passthrough
|
| trusted service boundary
+-------------------------> [ NestJS Core API ]
That familiar environment was useful precisely because it repeats itself.
A field changes and several representations may need updating. Another entity needs almost the same form lifecycle. Another controller needs almost the same CRUD procedure. A reusable base class removes implementation work but suddenly exposes more capability than an application needs. A BFF protects a boundary and then starts doing work that has little to do with why that boundary exists.
R2WX developed by repeatedly confronting work like this.
The project did not begin from a predefined architectural model. Its engineering ideas accumulated through implementation, repeated experimentation, constraints and revisions. Over time, recurring application knowledge moved into shared schemes; recurring procedures moved into infrastructure; extension points appeared where automation became restrictive; capability became separated from exposure; authority was divided across trust boundaries; and consolidation eventually stopped where independent responsibility still appeared useful.
The result is not an application generator.
Entities still exist. They still require configuration, routes, references and wiring. Application-specific behavior still has to be implemented.
What R2WX tries to reduce is something narrower: the amount of already-solved application work that has to become implementation work again.
The project uses a Svelte/SvelteKit frontend and BFF, a NestJS backend, Prisma and MySQL, with the system composed through Docker. CRUD provides the practical ground on which the deeper questions can be exercised.
Looking back through the implementation produced eight recurring pressure points.
1. Knowledge Started Becoming Unreliable
A single field changes. Its maximum length becomes 160 instead of 80. Or a field becomes required. Or accepted values changes. Or even a new property appears.
The change itself is trivial. The work begins when the same application fact has independently acquired several homes:
SAME APPLICATION FACT
maximum length = 80
+-------------+-------------+
v v v
Form Frontend Backend
definition constraint validation
|
v
operation-specific
representation
Change 80 to 160, and the developer's problem is no longer typing 160. It is remembering everywhere that 80 means the same thing.
R2WX attacks that repetition one level earlier than duplicated implementation. Recurring application facts are placed in shared schemes:
const scheme = () => ({
field: {
type: ...,
required: ...,
min: ...,
max: ...
}
});
The frontend can interpret that knowledge for interaction and form behavior. The backend can interpret it for acceptance and validation.
Shared Scheme
|
application knowledge
|
+---------+---------+
v v
Frontend Backend
| |
interaction acceptance
The scheme itself is materialized through factories rather than exposing one canonical mutable graph. Different runtime consumers can therefore obtain independent working representations without sharing mutation.
The practical change is small but important:
APPLICATION FACT CHANGES
|
v
Shared Scheme
|
+----+----+
v v
frontend backend
machinery machinery
The first thing R2WX tried to stop repeating was not code.
It was application repetitive knowledge.
2. Sharing Knowledge Started Blurring Ownership
Once sharing works, another temptation appears: Why stop?
If frontend and backend both need a scheme, perhaps presentation, API behavior, routing and persistence should also collapse into the same definition. R2WX does not take that route.
The frontend and backend share application knowledge, but they retain their own contextual decisions.
Shared Scheme
|
genuinely common facts
|
+-----------+-----------+
v v
ctx.js config.ts
| |
frontend truth backend truth
Frontend context contains knowledge needed by frontend machinery: entity type, literals and representation context. Backend configuration carries different concerns: model type, API exposure and routing information. Even frontend structure and presentation literals remain separate concerns.
The significance is not that the information couldn't technically be placed into one giant configuration object. It could. The question became whether the information still represented the same application truth.
When it did, R2WX shared it. When responsibility diverged, the representations were allowed to diverge too.
WE KEEP REPEATING THE SAME FACT
|
v
SHARE IT
|
v
responsibility diverges
|
+-----+-----+
v v
frontend backend
owns owns
its truth its truth
The frontend does not need to carry backend routing decisions simply because both sides agree that a field has a maximum length. The backend does not need to own presentation literals simply because it consumes the same entity scheme.
Share agreement. Preserve ownership.
That distinction became important later, because R2WX would repeatedly encounter information that could be consolidated technically but should not necessarily be consolidated by responsibility.
3. Consolidated Knowledge Started Repeating Implementations
Removing duplicate declarations does not remove duplicate procedure. The system may now know that a field is required, another is boolean and another accepts a bounded string. But forms still have to be assembled. Values still have to be collected. Requests still have to be validated. CRUD operations still have to reach services and persistence.
If every entity implements those operations independently, shared knowledge has solved only half of the repetition. R2WX therefore pushed further:
Shared Knowledge
|
v
Runtime Interpretation
|
v
Shared Procedure
|
+--------+--------+
v v
Entity A Entity B
On the frontend, CREATE, READ, UPDATE and DELETE became operational states of common form machinery rather than four independent form implementations. For example, the mode changes behavior:
export const FORM = {
ADD: 1,
READ: 2,
EDIT: 3,
DEL: 4
};
let disabled = $derived(
[FORM.READ, FORM.DEL].includes($form.mode)
);
On the backend, recurring controller and service procedures moved into reusable infrastructure. Validation also illustrates the direction particularly well. A partial update does not require a second validation engine. R2WX projects the relevant part of the scheme and returns to the strict procedure:
strict(data: {}, scheme: {}, optionalExcludes = []) {
...
}
loose (data: {}, scheme: {}, optionalExcludes = []) {
const schemeLoose = {};
const keys = Object.keys(data).filter(key => key !== 'id');
keys.forEach(key => {
if (key in scheme)
schemeLoose[key] = scheme[key];
...
});
return this.strict(data, schemeLoose, optionalExcludes);
}
Change the scope. Reuse the procedure.
Entity-specific controllers and services still exist. They attach an entity to the common machinery rather than disappearing entirely.
R2WX reduces implementation. It does not eliminate instantiation.
It does not generate an entire application from a scheme. Instead, ordinary entity work increasingly becomes configuration and attachment to infrastructure that already knows how to perform the recurring procedure. CRUD is useful here because it makes repetition difficult to hide.
Once the ordinary path had been absorbed, however, the next problem became unavoidable: What happens when an application does not fit the ordinary path?
4. Automation Started Fighting Flexibility
Automation feels successful while the application keeps requesting things the automation already understands. Then one requirement does not fit. A form needs a different structure. A submission needs data prepared differently. An entity needs additional behavior around the normal procedure.
Highly automated infrastructure can then create an unpleasant choice:
APPLICATION NEED
|
v
GENERIC PROCEDURE
|
does not fit
|
v
fight the abstraction
I had encountered this result before: infrastructure that removed repetitive work could eventually become a personal prison - efficient while the application stayed inside its assumptions, increasingly resistant when it did not.
Never try to automate everything.
The resulting 75/25 direction is approximate rather than measured:
+-------------------------------------------+
| |
| ~75% recurring application work |
| shared machinery |
| |
+-------------------------------------------+
| |
| ~25% application-specific work |
| extension / intervention |
| |
+-------------------------------------------+
The interesting number is not really 75. It is the refusal to eliminate the 25. R2WX therefore provides intervention at different levels.
A generic form can derive representation from available application knowledge:
<form class="r2wx-form">
{#each Object.values($active.form) as attr}
<R2wxFieldsetInput id={attr.id}/>
{/each}
</form>
A custom form can instead allow explicit composition:
<form class="r2wx-form">
<slot/>
</form>
The representation changes without requiring abandonment of the shared form lifecycle. The same pattern appears during submission. Custom payload preparation can intervene before the request rejoins shared transport machinery:
normal preparation
\ shared submission -> HTTP
/ custom preparation
Backend services can similarly override specific procedures while continuing to inherit ordinary service behavior.
The amount of infrastructure R2WX can provide is not the amount the application is required to accept.
The common path is infrastructure. The exceptional path is not failure. And specialization does not necessarily mean abandoning the common machinery permanently. An application can leave the default path, perform its specific work, and rejoin shared procedure where the contract permits it.
5. Inheritance Started Exposing Capabilities
Reusable base classes solve one problem and create another. A BaseController can accumulate reusable operations:
BaseController
GET - POST - PUT - DELETE
|
inherits
v
Entity Controller
The entity no longer needs to implement those operations repeatedly. But inheritance is generous. An entity may need only some of what it receives.
That reveals two questions that are easy to collapse: Can this controller perform an operation? And: Should this entity API expose that operation?
R2WX lets inheritance answer the first. It does not allow inheritance alone to answer the second. An entity explicitly declares the operations it intends to expose:
api: {
GET: {
[PATH._]: [ACCESS.GLOB]
}, POST: {
…
},
PUT: {
…
}, DELETE: {
…
}
}
If POST, PUT and DELETE are inherited but absent from the declaration, their implementation still exists. Their API exposure does not.
BaseController
GET - POST - PUT - DELETE
|
inherits
v
Entity Controller
|
declares GET
|
+--------+---------+
v v
GET POST - PUT - DELETE
EXPOSED SEALED
The runtime checks that exposure before continuing into authorization and operation handling.
Inheritance supplies capability. Configuration grants exposure.
Reusable implementation can remain broad while the concrete API surface remains narrow. This mattered because R2WX was trying to reduce implementation work without quietly increasing the public responsibilities of every entity that reused that implementation.
The developer gets reusable machinery. The developer still has to make the application-specific decision about what becomes reachable. Implementation, capability, exposure and authorization remain separate decisions.
6. Requests Started Carrying Different Identities
Authentication can initially look like one continuous relationship:
USER
|
+---- "authenticated" ----> everything
Then the topology becomes:
Browser -> SvelteKit/BFF -> Core API
Now another question appears. Whose identity is actually crossing each boundary? The human is authenticated to the application. But the caller crossing from the BFF into the protected backend is the BFF. R2WX does not treat those as the same trust relationship.
The browser-facing side establishes the human relationship. The examined flow uses a stateless signed ticket carried in an HttpOnly cookie. The ticket provides integrity rather than confidentiality and is not a JWT.
At the BFF, the application can reason about the human user and perform human-level authorization. But that identity does not simply continue downward as the core API service identity.
HUMAN
|
v
Browser
|
signed ticket
|
v
BFF
|
human authorization
|
============ SERVICE BOUNDARY ============
|
trusted service identity
|
v
Core API
|
service-level authorization
This creates two relationships: Human identity -> BFF authorization, and BFF service identity -> Core API authorization.
The point is not that the BFF becomes magically safe. If the trusted intermediary is compromised, that trust relationship is compromised too. The useful consequence is that authority becomes local to the boundary where it has meaning.
At the browser/BFF boundary: Who is this human, and what may that human do? At the BFF/core boundary: Who is this calling service, and may that service enter?
One request can cross several boundaries without requiring one identity to remain authoritative across all of them.
7. BFF Boundary Started Accumulating Responsibilities**
The BFF creates another practical problem. Every request now has somewhere else to pass through. For JSON, that may attract little attention. Then files arrive.
A multipart request can tempt the intermediary into:
receive multipart
|
v
parse fields and files
|
v
materialize payload
|
v
construct new FormData
|
v
send reconstructed payload
But the BFF exists primarily because of its own responsibilities around the browser-facing boundary. The fact that bytes cross it does not automatically mean it should become responsible for interpreting those bytes.
For multipart forwarding, R2WX instead forwards the incoming request body as a stream:
fetch ( url, {
method,
body: request.body,
duplex: "half"
} );
So the path can remain:
Browser
|
| multipart body
v
BFF
|
| stream passthrough
v
NestJS
|
v
multipart handling
The precise claim matters: the unparsed body is forwarded as a stream, avoiding multipart parsing and FormData reconstruction in the frontend container. This does not establish that no buffering can occur anywhere in the complete runtime or network stack.
The same effort to remove repeated decisions appears elsewhere in the transport path. A form does not need application-specific code simply to decide whether its current payload should become JSON or FormData. File presence can drive that representation automatically while custom submission remains available when the default preparation does not fit.
File limits also reconnect transport to the shared application knowledge from the first pressure point.
Rather than independently maintaining:
Scheme: file max = X
Multer: file max = Y
R2WX derives the applicable Multer fileSize limit from the active entity scheme file rules.
Active entity scheme
|
v
file-size rule
|
v
derive maximum
|
v
Multer fileSize
The same application knowledge therefore participates in both validation and multipart ingestion.
Entity requiredness != interaction requiredness.
An entity may require a file to exist without requiring every update operation to upload that file again. Runtime-loaded select options follow the same broader pattern. A scheme can describe what kind of field exists and where its options come from, while the actual values are loaded from current database state into an independently materialized working representation.
Several earlier decisions therefore meet in one real request:
Shared application scheme
|
v
Frontend interpretation
|
v
Form machinery
|
+-- existing values
+-- runtime-loaded options
+-- file interaction
|
v
Automatic payload preparation
|
v
FormData
|
v
SvelteKit BFF
|
stream passthrough
|
v
NestJS API
|
schema-derived file limit
|
v
file + scalar validation
|
v
shared procedure
The boundary remains. What changes is how much unnecessary responsibility the boundary acquires.
Crossing a component does not require becoming that component's responsibility.
8. Persistence Started Challenging Application Truths
By this point, R2WX has repeatedly consolidated application knowledge and procedure. Field knowledge feeds forms and validation. Shared procedure handles recurring operations. Configuration controls exposure. Application knowledge reaches transport configuration.
An obvious question follows: Why stop? If the shared schemes already know so much about an entity, why maintain another independently owned model in Prisma?
Why not continue:
Shared Scheme
|
+-- frontend
+-- backend
+-- validation
+-- transport
|
v
generate persistence model
|
v
Database
R2WX deliberately does not. schema.prisma remains an independently maintained persistence definition. The application schemes can determine whether data is acceptable to application procedure. Persistence retains the final authority over what state can actually exist there.
APPLICATION JURISDICTION
Shared Schemes
|
frontend / backend
|
validation
|
v
data
|
============ PERSISTENCE BOUNDARY ============
|
v
Prisma Model
|
v
MySQL
This leaves a synchronization point. That is deliberate. R2WX spent much of its development removing synchronization work, yet here it accepts some because the duplicated representation protects an independently meaningful responsibility.
This resolves what can otherwise look like a contradiction across the project.
On one side, R2WX repeatedly does this:
- remove duplication;
- centralize recurring knowledge;
- reuse procedure;
- automate repetitive work.
On the other, it repeatedly does this:
- preserve frontend/backend interpretation;
- retain custom procedure;
- require explicit API exposure;
- separate human and service authority;
- retain an independent persistence model.
Those are not opposite strategies. The recurring question is:
Does this repetition represent unnecessary repeated ownership, or does the separation preserve a responsibility that should remain independently owned?
RECURRING KNOWLEDGE / WORK
|
v
Does independent ownership
still serve a purpose?
|
+------+------+
NO YES
| |
v v
ABSORB ISOLATE
| |
v v
shared knowledge preserve
or procedure boundary
R2WX does not eliminate repetition as an absolute rule. It tries to distinguish repetition that represents unnecessary developer work from separation that still represents meaningful responsibility.
R2WX Emerged as Infrastructure
Looking at these eight pressure points together, the progression is clearer than it was while the individual mechanisms were being built:
knowledge
|
v
ownership
|
v
procedure
|
v
specialization
|
v
exposure
|
v
identity
|
v
transport
|
v
persistence
At each stage, R2WX encounters some combination of repeated work and independent responsibility.
Where repetition no longer appears to protect a useful responsibility, the system tends to absorb it: shared schemes, reusable form behavior, validation procedure, CRUD infrastructure, transport decisions.
Where separation still represents a meaningful boundary, the system tends to preserve it: frontend/backend ownership, application-specific procedure, explicit API exposure, separate trust relationships, independent persistence authority.
That is also where the approximate 75/25 direction becomes more meaningful. The 75 is not a claim that every application is exactly 75% generic. It represents the ambition to move dominant recurring work into infrastructure. The 25 is the deliberate refusal to make that infrastructure absolute.
For a conventional entity, this can mean that much of the CRUD lifecycle becomes primarily setup rather than repeated implementation. For a more specialized entity, the shared proportion can shrink. The application can depart from generic procedure, perform its own work and - where the receiving contract allows it - rejoin the shared lifecycle afterward.
So the result is not:
AUTOMATE EVERYTHING
It is closer to:
remove unnecessary implementation
without removing necessary responsibility
And that is ultimately what this R&D artifact records.
R2WX uses ordinary full-stack application problems as its experimental ground: forms, CRUD, validation, APIs, authentication, files and persistence.
What accumulated around those ordinary problems was an attempt to make fewer solved problems become implementation work again - without making shared infrastructure responsible for decisions that still belong somewhere else.
Not everything repeated belongs together.
Not everything separated should remain separate.
The decision depends on responsibility.
The complete R2WX infrastructure, including runnable Docker Compose environments, verified CRUD lifecycles, and architectural documentation, is publicly available. GitHub: https://github.com/manos-zalokostas/R2WX
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.