> For the complete documentation index, see [llms.txt](https://docs.akinon.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.akinon.com/akinon-ui/ui-protocol/client-application/introduction.md). Agents can also search and read this documentation through its [MCP server](https://docs.akinon.com/~gitbook/mcp).

# Introduction

This library provides a React context and hooks for enabling inter-app communication, navigation, and other essential functionalities.

The `@akinon/app-client` library is a crucial part of the UI Protocol, designed to facilitate the creation of micro-frontend applications that seamlessly integrate with the main shell application.&#x20;

### <mark style="color:red;">What is a Client Application?</mark>

A client application is a micro-frontend that runs inside an iframe and communicates with the shell application. Examples include marketplace extensions, analytics widgets, and custom modules. The client:

* **Receives Shared Data** - Accesses user info, settings, and configuration from the shell
* **Invokes Actions** - Triggers shell functions like showing toasts or modals
* **Requests Navigation** - Asks the shell to navigate to different routes
* **Sends Configuration** - Tells the shell about its menu structure and capabilities

### <mark style="color:red;">Key Features</mark>

* Seamless integration with the shell application
* Easy-to-use React hooks for accessing client functionalities
* Support for navigation between micro-frontend applications
* Ability to invoke custom actions defined in the shell
* Helper functions for displaying modals, toasts, and more
* TypeScript support for improved developer experience

### <mark style="color:red;">Installation</mark>

```bash
pnpm add @akinon/app-client
```

### <mark style="color:red;">Basic Usage</mark>

Wrap your application with `AppClientProvider`:

```tsx
import { AppClientProvider, useAppClient } from '@akinon/app-client';

const MyComponent = () => {
  const { data, navigate, showToast } = useAppClient();

  const handleClick = () => {
    showToast('Action completed!', 'success');
    navigate({ path: '/dashboard' });
  };

  return (
    <div>
      <p>Welcome, {data?.user?.name}</p>
      <button onClick={handleClick}>Go to Dashboard</button>
    </div>
  );
};

const App = () => (
  <AppClientProvider config={{ isDev: process.env.NODE_ENV === 'development' }}>
    <MyComponent />
  </AppClientProvider>
);
```

### <mark style="color:red;">How It Works</mark>

1. **Client initializes** with `AppClientProvider` and configuration
2. **Client sends** `SET_CONFIG` event to the shell with its configuration
3. **Shell responds** with `SET_DATA` and `SET_APP_ID`
4. **Communication established** via [framebus](https://github.com/braintree/framebus) library
5. **Ongoing communication** for actions, navigation, and data updates

```
┌─────────────────────────────────────────┐
│              Shell (iframe)             │
│  ┌───────────────────────────────────┐  │
│  │        AppClientProvider          │  │
│  │  ┌─────────────────────────────┐  │  │
│  │  │      Your Application       │  │  │
│  │  │                             │  │  │
│  │  │  useAppClient() → {         │  │  │
│  │  │    data,                    │  │  │
│  │  │    navigate,                │  │  │
│  │  │    showToast,               │  │  │
│  │  │    invokeAction,            │  │  │
│  │  │    ...                      │  │  │
│  │  │  }                          │  │  │
│  │  │                             │  │  │
│  │  └─────────────────────────────┘  │  │
│  └───────────────────────────────────┘  │
└─────────────────────────────────────────┘
```

### <mark style="color:red;">Client Can Also Be a Shell</mark>

A client application can also act as a shell for other micro-frontends. This enables nested hierarchies where a fullpage application hosts plugin applications within it.

```tsx
// This app is a client to the main shell
// but also a shell for its own plugins
import { AppClientProvider } from '@akinon/app-client';
import { AppShellProvider, PluginRenderer } from '@akinon/app-shell';

const App = () => (
  <AppClientProvider config={clientConfig}>
    <AppShellProvider apps={pluginApps} {...shellProps}>
      <MainContent />
      <PluginRenderer placeholderId="sidebar-widget" />
    </AppShellProvider>
  </AppClientProvider>
);
```

### <mark style="color:red;">Next Steps</mark>

* Configuration - Configure fullpage and plugin applications
* Hooks - Using useAppClient hook
* i18n - Internationalization in client apps
* API Reference - Complete API documentation


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.akinon.com/akinon-ui/ui-protocol/client-application/introduction.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
