---
title: ReArch
description: The documentation homepage of ReArch.
---

# ReArch

<p align="center">
<img src="https://github.com/GregoryConrad/rearch-docs/blob/main/assets/banner.jpg?raw=true" width="100%" alt="Banner" />
</p>

<p align="center">
ReArch = re-imagined approach to application design and architecture

> We must state definitions and provide for priorities and descriptions of data.
> We must state relationships, not procedures.
>
> -- Grace Murray Hopper, _Management and the Computer of the Future_ (1962)
</p>

---


## Features
Specifically, ReArch is a novel solution to:
- ⚡️ State Management
- 🧮 Incremental Computation
- 🧱 Component-Based Software Engineering

And with those, come:
- Reactivity through declarative code
- Loose coupling and high testability
- App-level composability via a functional approach to dependency inversion
- [Feature composition through _side effects_](https://blog.gsconrad.com/2023/12/22/the-problem-with-state-management.html)


## In a Nutshell 
Define your "capsules" (en-_capsulated_ pieces of state) at the top level:
<CodeGroup title="Defining capsules">
  ```dart
  // Capsules are simply functions that consume a CapsuleHandle.
  // The CapsuleHandle lets you get the data of other capsules,
  // in addition to using a large variety of side effects.

  // This particular capsule manages a count from a classic example counter app,
  // using the state side effect.
  (int, void Function()) countManager(CapsuleHandle use) {
    final (count, setCount) = use.state(0);
    return (count, () => setCount(count + 1));
  }

  // This capsule provides the current count, plus one.
  int countPlusOneCapsule(CapsuleHandle use) => use(countManager).$1 + 1;
  ```

  ```rust
  // Capsules are simply functions that consume a CapsuleHandle.
  // The CapsuleHandle lets you get the data of other capsules,
  // in addition to using a large variety of side effects.

  // This capsule provides a count and a way to increment that count.
  fn count_manager(CapsuleHandle { register, .. }: CapsuleHandle) -> (u8, impl CData + Fn()) {
      let (count, set_count) = register(effects::state::<Cloned<_>>(0));
      let increment_count = move || set_count(count + 1);
      (count, increment_count)
  }

  // This capsule provides the count, plus one.
  fn count_plus_one_capsule(CapsuleHandle { mut get, .. }: CapsuleHandle) -> u8 {
      let (count, _increment_count) = get(count_manager);
      count + 1
  }
  ```
</CodeGroup>
