# directus/rstore architecture

> Architecture diagram of the GitHub repository directus/rstore, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/directus/rstore
- Repository: https://github.com/directus/rstore

## Overview

##### Main Components
- Core Data Store Module:
– Represented by packages/core.
– Provides the normalized reactive cache, query engine (findFirst, findMany, peek variants), mutation engine (create, update, delete), subscription system, and store management.
- Plugin System:
– Core’s extensibility via plugins is implemented (see packages/core/src/plugin.ts and hooks in shared packages).
– Emphasize how plugins allow the core to adapt fetch mechanisms (e.g., REST, GraphQL).
- Integration Modules for Frameworks:
– Nuxt integrations (packages/nuxt, packages/nuxt-directus, packages/nuxt-drizzle) that wrap the core with framework‑specific logic and devtools.
– Vue integration (packages/vue) that exposes functions to use within Vue applications.
- Playground/Demo Applications:
– Multiple “playground” packages show example usage and act as both testbeds and demonstrations of how rstore can be integrated (e.g., packages/playground-drizzle, packages/playground-nuxt-directus, packages/playground-ws-server, and packages/playground).
- Documentation and DevTools:
– The docs folder with VitePress configuration points to an extensive documentation system.
– Devtools integration in Nuxt and client modules as shown by components under packages/nuxt/client in the devtools folder.
- Shared Utilities and Types:
– Common/shared code in packages/shared that includes type definitions and utility functions used across modules.

##### Relationships and Interactions
- All integration modules (Nuxt, Vue, etc.) depend on the core package to perform data operations.
- The plugin system acts as a middleware layer between the core and any external data sources.
- The reactive cache ensures that when data is mutated via the mutation API or updated via subscriptions, all connected UI components (often colocated in the host framework, like Nuxt) are kept in sync.
- Playground applications demonstrate how the modules (core + integrations) work together, sometimes including separate server code (REST API endpoints or WebSocket routes as found under playground and playground-ws-server).
- Shared utilities and type definitions provide consistency across the code base, interfacing with both the core functionality and integration packages.

##### Architectural Patterns and Design Principles
- Modularity: The monorepo organizes related but distinct aspects as separate packages; each package has a clear niche (core, direct integrations, utilities, playgrounds).
- Plugin/Extensibility Design: Illustrate how external data fetching strategies (REST, GraphQL, etc.) can be abstracted via plugins.
- Colocation: Document that queries can be colocated in components (see docs/guide/data) which directly use modules from the core.

##### Relevant Technologies, Frameworks, and Libraries
- TypeScript – nearly all files use it (indicated by .ts and .mts files).
- Nuxt and Vue – with dedicated packages for integration.
- VitePress – used for docs and demonstration.
- Testing frameworks – Vitest configuration is present for tests (highlight test folders under packages).
- GitHub Actions – as seen in the workflows in .github/workflows (for CI, release, nightly).

- Branch out to “Plugin System” that influences or extends the core.
- Also branch out to “Playground / Demo Applications” and “Documentation/DevTools.”

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core System Group
    Core["Core Data Store"]:::core
    Shared["Shared Utilities and Types"]:::shared

    %% Plugin System Group
    subgraph "Plugin System"
        PluginCore["Core Plugin"]:::plugin
        PluginShared["Shared Plugin Types"]:::plugin
    end

    %% Integration Modules Group
    subgraph "Integrations"
        subgraph "Nuxt Integration"
            Nuxt["Nuxt"]:::integration
            NuxtDirectus["Nuxt Directus"]:::integration
            NuxtDrizzle["Nuxt Drizzle"]:::integration
        end
        Vue["Vue Integration"]:::integration
    end

    %% Playground / Demo Applications Group
    subgraph "Playground / Demo Applications"
        Playground["Playground"]:::playground
        PlaygroundDrizzle["Playground Drizzle"]:::playground
        PlaygroundNuxtDirectus["Playground Nuxt Directus"]:::playground
        PlaygroundWSServer["Playground WS Server"]:::playground
    end

    %% Documentation and DevTools Group
    subgraph "Documentation and DevTools"
        VitePressDocs["VitePress Docs"]:::docs
        Guide["Guide"]:::docs
        NuxtDevtools["Nuxt Devtools"]:::docs
    end

    %% Connections
    PluginCore -->|"extends"| Core
    PluginShared -->|"extends"| Core

    Nuxt -->|"dependsOn"| Core
    NuxtDirectus -->|"dependsOn"| Core
    NuxtDrizzle -->|"dependsOn"| Core
    Vue -->|"dependsOn"| Core

    Playground -->|"demonstrates"| Core
    PlaygroundDrizzle -->|"demonstrates"| Core
    PlaygroundNuxtDirectus -->|"demonstrates"| Core
    PlaygroundWSServer -->|"demonstrates"| Core

    VitePressDocs -->|"documents"| Core
    Guide -->|"documents"| Core
    NuxtDevtools -->|"integratesWith"| Nuxt

    Core -->|"utilizes"| Shared

    %% Styles
    classDef core fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef plugin fill:#e6ccff,stroke:#663399,stroke-width:2px;
    classDef integration fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef playground fill:#ffffcc,stroke:#999900,stroke-width:2px,stroke-dasharray: 5 5;
    classDef docs fill:#cce5ff,stroke:#003399,stroke-width:2px;
    classDef shared fill:#f2f2f2,stroke:#999999,stroke-width:2px,stroke-dasharray: 3 3;

    %% Click Events
    click Core "https://github.com/directus/rstore/tree/main/packages/core"
    click PluginCore "https://github.com/directus/rstore/blob/main/packages/core/src/plugin.ts"
    click PluginShared "https://github.com/directus/rstore/blob/main/packages/shared/src/types/plugin.ts"
    click Nuxt "https://github.com/directus/rstore/tree/main/packages/nuxt"
    click NuxtDirectus "https://github.com/directus/rstore/tree/main/packages/nuxt-directus"
    click NuxtDrizzle "https://github.com/directus/rstore/tree/main/packages/nuxt-drizzle"
    click Vue "https://github.com/directus/rstore/tree/main/packages/vue"
    click Playground "https://github.com/directus/rstore/tree/main/packages/playground"
    click PlaygroundDrizzle "https://github.com/directus/rstore/tree/main/packages/playground-drizzle"
    click PlaygroundNuxtDirectus "https://github.com/directus/rstore/tree/main/packages/playground-nuxt-directus"
    click PlaygroundWSServer "https://github.com/directus/rstore/tree/main/packages/playground-ws-server"
    click VitePressDocs "https://github.com/directus/rstore/blob/main/docs/.vitepress"
    click Guide "https://github.com/directus/rstore/tree/main/docs/guide"
    click NuxtDevtools "https://github.com/directus/rstore/tree/main/packages/nuxt/client/components/devtools"
    click Shared "https://github.com/directus/rstore/tree/main/packages/shared"
```
