<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alex Zichu on Medium]]></title>
        <description><![CDATA[Stories by Alex Zichu on Medium]]></description>
        <link>https://medium.com/@azc.aizichu?source=rss-3bb49987ebc4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*uH3sVRcQQ9in1Pd5</url>
            <title>Stories by Alex Zichu on Medium</title>
            <link>https://medium.com/@azc.aizichu?source=rss-3bb49987ebc4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 22:48:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@azc.aizichu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building Tea Cup: Reconstructing Frontend Architecture From First Principles]]></title>
            <link>https://medium.com/@azc.aizichu/building-tea-cup-reconstructing-frontend-architecture-from-first-principles-e00ceedebf04?source=rss-3bb49987ebc4------2</link>
            <guid isPermaLink="false">https://medium.com/p/e00ceedebf04</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[elm]]></category>
            <dc:creator><![CDATA[Alex Zichu]]></dc:creator>
            <pubDate>Fri, 28 Aug 2026 04:41:01 GMT</pubDate>
            <atom:updated>2026-08-28T04:41:01.195Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Why Build Tea Cup?</strong></h3><p>React makes it easy to build user interfaces. You can create a component, give it some state, respond to an event, and render the result with very little setup.</p><p>The problem becomes more interesting as the application grows. State starts to live in different places, business logic gets mixed with rendering logic, and events can trigger changes across several components.</p><p>Eventually, a simple question becomes harder to answer:</p><p>When a user does something, where exactly does the application state change?</p><p>This is the question that led me to build Tea Cup. I wasn’t trying to create another React replacement or another state-management library.</p><p>Instead, I wanted to understand something more fundamental:</p><p>What is the minimum architecture required to make a frontend application’s state predictable?</p><p>To explore this, I started with an almost empty application and built the architecture from the ground up. Rather than designing all the abstractions first, I wanted each abstraction to appear when a problem required it.</p><p>The Elm Architecture influences the basic idea. An application can be described using a small set of concepts: a Model represents state, a Message represents an event, an Update determines how state changes, and a View renders the current state.</p><p>The resulting flow is simple:</p><p>User Interaction<br> ↓<br> Message<br> ↓<br> Update<br> ↓<br> Model<br> ↓<br> View<br> ↓<br>User Interaction</p><p>The important part isn’t the terminology. It is the direction of information flow.</p><p>Instead of allowing different parts of the application to modify state in arbitrary ways, state changes have an explicit path.</p><p>At the center of the architecture is a simple relationship:</p><p>Model + Message → Model</p><p>Tea Cup is deliberately small. It provides Models, Messages, Pages, Routes, and Views, but these are not intended to become a large collection of framework abstractions.</p><p>The goal is to create a few simple boundaries that make application behavior easier to reason about.</p><p>This also changes how we approach the implementation. We don’t need to design the entire architecture before writing the first line of code.</p><p>We can start with an empty application and discover the architecture step by step.</p><p>Starting With an Empty Application</p><p>The first question is surprisingly basic:</p><p>What does a frontend application actually need to run?</p><p>We need a browser entry point, some JavaScript or TypeScript code, and a way to turn that source code into something the browser can execute.</p><p>For this experiment, Vite gives us enough infrastructure without getting in the way. It provides the development server and build pipeline while leaving the application architecture to us.</p><p>So we start with a normal Vite React project:</p><blockquote>npm create vite@latest</blockquote><p>Choose React and TypeScript when prompted.</p><p>Then install the dependencies:</p><blockquote>npm install</blockquote><p>At this point, Tea Cup doesn’t exist yet. That’s intentional.</p><p>We have only created the environment in which we are going to build it.</p><p>The generated project contains several files that we don’t need for the experiment. We can remove the demo components and styles and keep only the basic application entry points.</p><p>The resulting project will eventually look like this:</p><blockquote>src/<br>├── models/<br>│ ├── Model.ts<br>│ ├── Msg.ts<br>│ └── Route.ts<br>├── pages/<br>│ └── counter/<br>│ ├── CounterModel.ts<br>│ ├── CounterMsg.ts<br>│ └── CounterView.tsx<br>├── App.tsx<br>├── View.tsx<br>├── main.tsx<br>└── vite-env.d.ts</blockquote><p>We haven’t created all of these files yet. The structure will emerge as we build the architecture.</p><h3>Finding the First Boundary</h3><p>Before thinking about Models or Messages, we need to understand how the application gets into the browser.</p><p>The first boundary is index.html.</p><p>It provides the HTML document and the element where React will render the application.</p><p>The important part is small:</p><blockquote>&lt;div id=”root”&gt;&lt;/div&gt;</blockquote><p>Everything we build later will eventually exist behind this element.</p><p>The initial flow therefore looks like this:</p><blockquote>Browser<br> ↓<br>index.html<br> ↓<br>React<br> ↓<br>Tea Cup</blockquote><p>This distinction is useful. Vite and React provide the runtime infrastructure, while Tea Cup will define how our application itself is organized.</p><p>Giving the Application a Shape</p><p>Now we can give the source code a small structure:</p><blockquote>src/<br>├── models/<br>├── pages/<br>├── App.tsx<br>├── View.tsx<br>└── main.tsx</blockquote><p>The structure is intentionally small.</p><p>main.tsx will connect the application to the browser. App.tsx will provide the top-level application boundary, while View.tsx will eventually turn application state into UI.</p><p>The models directory will contain concepts that describe the state and events of the application.</p><p>The pages directory will contain individual application features.</p><p>We aren’t trying to predict every abstraction the application might need. We’ll introduce new concepts only when we encounter a problem that requires them.</p><p>The first problem is simple:</p><p>What does the application know?</p><p>The Model</p><p>Every application has state. A counter has a number, a shopping cart has items, and a settings page has preferences.</p><p>Tea Cup calls this state the Model.</p><p>We can start with a very small interface:</p><blockquote>export interface Model {<br> // application state<br>}</blockquote><p>We also need a way to create the initial state:</p><blockquote>export function initialModel(): Model {<br> return {};<br>}</blockquote><p>This gives the application an explicit starting point.</p><blockquote>initialModel()<br> ↓<br> Model</blockquote><p>That may not look like much, but it gives us an important invariant: the application always has a well-defined state.</p><p>The next question follows naturally.</p><p>If the Model represents the current state, how does the application move from one state to another?</p><p>What Happened?</p><p>Applications change because something happens.</p><p>A user clicks a button. A page is opened. A request completes. A timer fires.</p><p>Instead of allowing these events to directly modify state, Tea Cup represents them as Messages.</p><p>Create:</p><blockquote>src/models/Msg.ts</blockquote><p>A message describes an event.</p><p>For our first application, we might eventually have messages such as:</p><p>Increment<br>Decrement<br>Reset</p><p>The message doesn’t change the Model by itself.</p><p>It simply tells the application what happened.</p><p>This gives us another part of the flow:</p><p>User Action<br> ↓<br> Message</p><p>The actual state transition will happen somewhere else.</p><p>Making State Changes Explicit</p><p>Now we have a Model and a Message.</p><p>We need something that knows what to do when a particular message arrives.</p><p>This is the role of the Update function.</p><p>Conceptually, it looks like this:</p><p>Model + Message → Model</p><p>Suppose our Counter currently contains:</p><p>count = 0</p><p>The user clicks the increment button.</p><p>The View produces:</p><p>Increment</p><p>The update logic receives:</p><p>Model:<br> count = 0</p><p>Message:<br> Increment</p><p>and produces:</p><p>Model:<br> count = 1</p><p>The important thing is that the button didn’t directly modify count.</p><p>The button produced a Message.</p><p>The update logic decided what that Message meant.</p><p>That gives us a predictable path from an interaction to a state transition.</p><p>From State Back to the User</p><p>We now have state and a way to change it.</p><p>But the user still needs to see that state.</p><p>This is where the View comes in.</p><p>The View can be thought of as:</p><p>Model → UI</p><p>If the Model contains:</p><p>count = 5</p><p>the View can render:</p><p>5</p><p>If the Model changes to:</p><p>count = 6</p><p>the View renders the new state.</p><p>This completes the basic loop:</p><blockquote>Message<br> ↓<br> Update<br> ↓<br> Model<br> ↓<br> View<br> ↓<br> Message</blockquote><p>The View doesn’t need to decide what the application state should be.</p><p>It only presents the current state and produces Messages when the user interacts with it.</p><h3>Introducing Pages</h3><p>So far, we have described one application as one Model, one Message system, and one View.</p><p>That works for a Counter.</p><p>It becomes less useful when the application contains several independent features.</p><p>Imagine that Tea Cup eventually contains:</p><p>Counter<br>Todo<br>Settings<br>Profile</p><p>We need some way to keep these features organized.</p><p>This is where the concept of a Page comes in.</p><p>A Page represents a feature of the application and gives that feature its own state, messages, and view.</p><p>For example:</p><blockquote>Counter<br>├── CounterModel<br>├── CounterMsg<br>└── CounterView</blockquote><p>The same structure can later be used for another feature:</p><blockquote>Todo<br>├── TodoModel<br>├── TodoMsg<br>└── TodoView</blockquote><p>The purpose isn’t to create more files.</p><p>The purpose is to give each feature a clear boundary.</p><h3>Introducing Routes</h3><p>Once we have multiple pages, another problem appears.</p><p>The application needs to know which page the user is looking at.</p><p>That information belongs to navigation.</p><p>Create:</p><blockquote>src/models/Route.ts</blockquote><p>A route represents the current location of the application.</p><p>For a small application, it might be as simple as:</p><p>Counter<br>Settings</p><p>Later, it could contain parameters:</p><p>Todo(id)<br>User(id)</p><p>The important idea is that navigation is not treated as something completely separate from application state.</p><p>It is another piece of information that the application needs to understand.</p><p>Conceptually:</p><blockquote>Application Model<br>├── Route<br>└── Page State</blockquote><p>Now the application has enough structure to support multiple pages.</p><h3>Building the Counter</h3><p>It’s time to stop talking about architecture and build something.</p><p>The Counter is deliberately simple. It gives us a feature where the complete state transition is easy to see.</p><p>Create:</p><blockquote>src/pages/counter/<br>├── CounterModel.ts<br>├── CounterMsg.ts<br>└── CounterView.tsx</blockquote><p>The Counter Model contains the state owned by the page:</p><blockquote>export interface CounterModel {<br> count: number;<br>}</blockquote><p>Its initial state is equally simple:</p><blockquote>export function initialCounterModel(): CounterModel {<br> return {<br> count: 0<br> };<br>}</blockquote><p>Now the state is explicit:</p><p>CounterModel<br> │<br> └── count: 0</p><p>Next we define what can happen to the Counter.</p><p>Defining Counter Messages</p><p>Create CounterMsg.ts.</p><p>The Counter only needs a few events:</p><p>export type CounterMsg =<br> | { type: “Increment” }<br> | { type: “Decrement” }<br> | { type: “Reset” };</p><p>This is one of the places where the architecture starts becoming useful.</p><p>Instead of looking at the UI to understand what the Counter can do, we can look at its Message type.</p><p>The messages describe the vocabulary of the feature.</p><blockquote>CounterMsg<br>├── Increment<br>├── Decrement<br>└── Reset</blockquote><p>The state transitions can now be expressed explicitly.</p><blockquote>Increment → count + 1<br>Decrement → count — 1<br>Reset → count = 0<br>Creating the Counter View</blockquote><p>Now we can create CounterView.tsx.</p><p>The View receives the current Counter state and provides the UI that allows the user to generate Counter messages.</p><p>Conceptually:</p><p>CounterModel<br> ↓<br>CounterView<br> ↓<br>CounterMsg</p><p>The View might contain three buttons:</p><p>[ — ] 0 [ + ]</p><p>[ Reset ]</p><p>Clicking the + button does not directly modify the Counter Model.</p><p>Instead, it produces:</p><p>{ type: “Increment” }</p><p>That message goes through the update logic, which produces a new Counter Model.</p><p>React then renders the new Model.</p><p>This is the complete loop we were trying to build.</p><p>Connecting Tea Cup to React</p><p>At this point, we have an application architecture, but React still needs to render it.</p><p>This is where App.tsx, View.tsx, and main.tsx connect the two worlds.</p><p>main.tsx is the browser entry point.</p><p>Its responsibility is mostly infrastructure: find the root element and start the React application.</p><p>Browser<br> ↓<br>main.tsx<br> ↓<br>App</p><p>App.tsx provides the top-level application boundary.</p><p>It owns the application lifecycle and connects the Tea Cup model and update logic to React.</p><p>The View.tsx component then determines what should be rendered based on the current application state and route.</p><p>This gives us a useful separation:</p><blockquote>React<br>└── Rendering mechanism</blockquote><blockquote>Tea Cup<br>├── Model<br>├── Message<br>├── Update<br>├── Route<br>├── Page<br>└── View</blockquote><p>React is still doing what React is good at.</p><p>Tea Cup is defining how application state and events move through the application.</p><p>The Complete Flow</p><p>We can now put everything together.</p><p>Suppose the user opens the Counter page.</p><p>The application starts with an initial Model:</p><p>count = 0</p><p>The View renders the Counter.</p><p>The user clicks +.</p><p>The View produces an Increment Message.</p><p>The update logic receives the current Model and the Message:</p><p>count = 0<br>+<br>Increment</p><p>and produces:</p><p>count = 1</p><p>The View renders the new state.</p><p>The same process happens again for the next interaction.</p><blockquote>┌──────────────┐<br> │ Model │<br> └──────┬───────┘<br> │<br> ▼<br> ┌──────────────┐<br> │ View │<br> └──────┬───────┘<br> │<br> User Action<br> │<br> ▼<br> ┌──────────────┐<br> │ Message │<br> └──────┬───────┘<br> │<br> ▼<br> ┌──────────────┐<br> │ Update │<br> └──────┬───────┘<br> │<br> ▼<br> ┌──────────────┐<br> │ New Model │<br> └──────────────┘</blockquote><p>There is no complicated state-management mechanism here.</p><p>That’s intentional.</p><p>The experiment is asking whether this small set of constraints is enough to make the application easier to reason about.</p><h3>What Did We Actually Gain?</h3><p>The Counter itself isn’t impressive.</p><p>The interesting part is what becomes explicit.</p><p>We can identify the state by looking at the Model. We can identify what can happen by looking at the Message type. We can identify how state changes by looking at the update logic.</p><p>The View has a narrower responsibility as well. It presents state and produces messages rather than becoming the place where application behavior is implemented.</p><p>This makes the flow of the application easier to trace.</p><p>If the Counter suddenly produces the wrong value, we don’t need to search the entire component tree for every possible state mutation.</p><p>We can start with a much smaller question:</p><p>What Model did we have, what Message was received, and what did Update produce?</p><p>This is the property I was looking for when I started the experiment.</p><h3>What We Have Not Solved</h3><p>Tea Cup doesn’t make frontend development magically simple.</p><p>We have only dealt with synchronous state transitions so far. Real applications need API requests, asynchronous operations, browser events, persistence, authentication, and many other forms of side effects.</p><p>Those introduce a more difficult question:</p><p>What happens when an application needs to do something outside of its current state?</p><p>For example, suppose the Counter needs to load its initial value from an API.</p><p>The update function cannot simply return a new Model containing the server response because the response doesn’t exist yet.</p><p>Now we need to reason about commands and effects.</p><p>This is where the simple architecture becomes more interesting.</p><h3>Why Start This Small?</h3><p>The purpose of building Tea Cup from scratch isn’t to prove that a Counter needs an architecture.</p><p>It obviously doesn’t.</p><p>The Counter gives us a small environment where the consequences of architectural decisions are easy to see.</p><p>Once the basic rules are clear, we can gradually introduce more realistic problems and see where those rules need to evolve.</p><p>That’s the part I’m most interested in.</p><p>Instead of starting with a large framework and learning its abstractions, we start with a small problem and ask what abstraction the problem actually requires.</p><p>The result may eventually become more complicated.</p><p>But hopefully every additional piece of complexity has a reason for being there.</p><h3>Where This Goes Next</h3><p>The minimal Tea Cup application now has the basic pieces:</p><blockquote>Model<br>Message<br>Update<br>View<br>Page<br>Route</blockquote><p>We also have a working Counter that demonstrates the complete state transition loop.</p><p>The next step is to introduce something that a Counter alone cannot demonstrate: side effects.</p><p>Once the application needs to communicate with the outside world, the simple relationship</p><p>Model + Message → Model</p><p>is no longer enough.</p><p>We’ll need to extend the architecture without losing the property that made the original design useful: a clear and predictable flow of information.</p><p>That is where the real experiment begins.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e00ceedebf04" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>