# concrete-utopia/utopia architecture

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

- Interactive diagram: https://gitdiagram.com/concrete-utopia/utopia
- Repository: https://github.com/concrete-utopia/utopia

## Overview

##### Major system components
- Frontend (Editor)
– This is the primary user interface where design tools and code-editing capabilities are offered. It lives largely in the “editor” folder and contains rich assets, React components, bundled dependencies, testing suites (Jest, Karma), and configuration files for Vite/webpack.
- Backend (Server)
– The “server” directory contains a Haskell-based backend (using Cabal, Haskell modules, and migrations). It handles API endpoints, authentication, database interactions, logging, and real-time features.
- Client Model and API Layers
– The “clientmodel” directory includes Haskell code that likely defines business logic, state management, and the client data model. “utopia-api” is another module written in TypeScript that contains supporting helper functions, API endpoint logic, and utilities that integrate with the editor’s functionality.
- Remix & Website Components
– The “utopia-remix” directory represents a Remix-based web integration, complete with its own server, routes, components, handlers, and a separate front-end for users not using the desktop editor.
- VS Code Integration
– The “utopia-vscode-common” and “utopia-vscode-extension” directories indicate that there is integration or a dedicated extension for VS Code. Their roles are to bridge the Utopia editor functionality with the VS Code environment.
- Infrastructure and CI/CD
– The “.github” folder and associated workflows (e.g., build, tag-release, PR templates) indicate automated testing, deployment, and integration pipelines. This aspect should also be represented as an external process/system that triggers builds/deployments.

##### Relationships and interactions
- The Editor front-end (React/Vite/webpack based) communicates with the backend (Haskell server) via REST or Servant endpoints, as well as through real-time collaboration protocols (e.g., via Liveblocks).
- The client model and API components enforce consistency between the frontend state and server state.
- The VS Code extension and Utopia Remix integration serve as alternate clients or portals that trigger similar backend services when editing projects.
- The CI/CD workflows (GitHub Actions) trigger tests, deploy builds, and regularly update both the site and the editor application.
- External dependencies such as GitHub (for authentication and content fetching) and PostgreSQL (for persistence, as inferred from the migrations) are critical to the system’s operation.

##### Architectural patterns and design principles
- Separation of concerns: Notice the clear boundaries between the editor (UI), the server’s business logic (Haskell), and API infrastructure.
- Modular design: Several independent modules (utopia-api, utopia-remix, utopia-vscode-extension) suggest a microkernel or plugin-based architecture that allows Utopia to support multiple client interfaces.
- Real-time collaboration: Integration with Liveblocks and GitHub implies messaging or data synchronization layers.
- Build and deployment automation: Use of Nix, direnv, and GitHub workflows indicates an emphasis on reproducibility and streamlined developer experience.

##### Incorporate relevant technologies and frameworks
- Frontend: React, TypeScript, Vite, Webpack, Jest, Karma.
- Backend: Haskell (with Cabal, hpack for builds), PostgreSQL (via migrations), and possibly Servant for REST endpoints.
- Infrastructure: Nix-shell, direnv, GitHub Actions for CI/CD.
- Integrations: Liveblocks (for collaboration), GitHub API (for token-based operations), and Remix for web routing and server-side rendering.

- Clear labels for each major component: “Editor”, “Server API”, “Client Model”, “Utopia API”, “VS Code Extension”, “Utopia Remix”, “Database”, “CI/CD Pipeline”, and “External Services (GitHub, Liveblocks)”.
– Editor ⇄ Server API (bidirectional for code editing and real‑time updates)
– Editor → Client Model/utopia-api (local data and state management)
– Server API → Database (for persistence)
– CI/CD workflows (from GitHub actions triggering deployments and tests)
– Frontend (Editor, Remix, VS Code Extension)
– Backend (Server, Client Model, API modules)
– Infrastructure / DevOps (Nix environment, GitHub Actions, build scripts)
– External integrations (GitHub, Liveblocks, PostgreSQL)

– Illustrate the multi-channel input points (editor, VS Code, Remix website)
– Show how the frontend reacts to real time user input and communicates with the Haskell server (and indirectly with persistent storage)
– Highlight the automated build, test, and deployment strategies governed by GitHub Actions and other CI tools
– Mark clearly how external services (GitHub’s API, Liveblocks) are incorporated into the workflow

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Components
    subgraph "Frontend Components"
        Editor["Editor (React)"]:::frontend
        Remix["Utopia Remix"]:::frontend
        VSC_Common["VS Code Common"]:::frontend
        VSC_Ext["VS Code Extension"]:::frontend
    end

    %% Backend Components
    subgraph "Backend Components"
        Server["Server API (Haskell)"]:::backend
        ClientModel["Client Model"]:::backend
        UtopiaAPI["Utopia API"]:::backend
        DB["Database (PostgreSQL)"]:::backend
    end

    %% Infrastructure / DevOps
    subgraph "Infrastructure / DevOps"
        CICD["CI/CD Pipeline"]:::infrastructure
    end

    %% External Integrations
    subgraph "External Integrations"
        External["External Services (GitHub & Liveblocks)"]:::external
    end

    %% Relationships
    Editor -->|"REST_API"| Server
    Server -->|"real-time"| Editor

    Editor -->|"state_management"| ClientModel
    Editor -->|"calls_API"| UtopiaAPI
    ClientModel -->|"business_logic"| UtopiaAPI

    Server -->|"persistence"| DB
    Server -->|"integrations"| External

    VSC_Common -->|"interfaces"| Server
    VSC_Ext -->|"interfaces"| Server

    Remix -->|"routes"| Server

    CICD -->|"deploy_builds"| Editor
    CICD -->|"deploy_builds"| Remix
    CICD -->|"deploy_builds"| Server

    %% Click Events
    click Editor "https://github.com/concrete-utopia/utopia/tree/master/editor/"
    click Server "https://github.com/concrete-utopia/utopia/tree/master/server/"
    click ClientModel "https://github.com/concrete-utopia/utopia/tree/master/clientmodel/"
    click UtopiaAPI "https://github.com/concrete-utopia/utopia/tree/master/utopia-api/"
    click Remix "https://github.com/concrete-utopia/utopia/tree/master/utopia-remix/"
    click VSC_Common "https://github.com/concrete-utopia/utopia/tree/master/utopia-vscode-common/"
    click VSC_Ext "https://github.com/concrete-utopia/utopia/tree/master/utopia-vscode-extension/"
    click CICD "https://github.com/concrete-utopia/utopia/tree/master/.github/"

    %% Styles
    classDef frontend fill:#DDEEFF,stroke:#000,stroke-width:2px;
    classDef backend fill:#CCFFCC,stroke:#000,stroke-width:2px;
    classDef infrastructure fill:#FFEEAD,stroke:#000,stroke-width:2px;
    classDef external fill:#FFCCCC,stroke:#000,stroke-width:2px;
```
