# open-simulation-platform/cosim-demo-app architecture

> Architecture diagram of the GitHub repository open-simulation-platform/cosim-demo-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/open-simulation-platform/cosim-demo-app
- Repository: https://github.com/open-simulation-platform/cosim-demo-app

## Overview

- Server Component (Go): Represent the core server logic with files such as main.go, server/server.go, and server/websockets.go. This is where incoming HTTP requests (or websocket connections) are handled and where most business logic runs.
- libcosim Library: Depicted as a separate module (with its own source files under libcosim and structs) that the server leverages for simulation or related operations.
- Client Component (ClojureScript): Represented by files in the src/client directory, which compile into assets found in resources/public. This part is responsible for providing the web UI.
- External Dependencies & Build Tools: Indicate components like the Conan-managed C++ dependencies, Go Modules (go.mod/go.sum), and build tools (leiningen, packr for distribution).
- Deployment/CI Elements: While not a runtime component, note the presence of Dockerfiles, GitHub workflows, and associated configuration files that indicate how the system is deployed and integrated in CI/CD.

##### Out Relationships and Data Flow
- If applicable, indicate that the server may serve the static assets (HTML, JS, CSS) from the resources/public directory.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly segregate the frontend (client, built in ClojureScript) from the backend (server in Go and the libcosim library) to improve maintainability.
- Modularization: Emphasize that libcosim and the server form distinct modules. This modular design offers extensibility and reusability.
- Client-Server Communication: Mark the API endpoints (for example, the /status endpoint) that the client uses to obtain status information.
- Integration Points: Note the integration workflows (e.g., CI pipelines in .github/workflows) and build scripts (Conan, lein, and packr commands) that ensure end-to-end assembly and testing.

##### Relevant Technologies
- Languages & Frameworks: Go for the server, ClojureScript for the client.
- Package Managers/Build Tools: Conan (for C++ dependencies), Go Modules, Leiningen, packr for packaging.
- External Tools: Docker (from the .dockerfiles directory) may be included to show containerized deployment.

##### Final Touches
- Remember to highlight both runtime components (server, client, library) and non-runtime aspects like CI/CD pipelines and dependency management which are critical to understanding the overall architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Backend Layer
    subgraph "Backend"
        subgraph "Go Server Component"
            A1["main.go"]:::server
            A2["server.go"]:::server
            A3["websockets.go"]:::server
        end
        subgraph "libcosim Library"
            B1["libcosim.go"]:::lib
            B2["observers.go"]:::lib
            B3["scenario.go"]:::lib
            B4["trending.go"]:::lib
            B5["utils.go"]:::lib
        end
    end

    %% Frontend Layer
    subgraph "Frontend"
        C1["ClojureScript Client"]:::client
        C2["Static Assets"]:::client
    end

    %% Build & Deployment Layer
    subgraph "Build & Deployment"
        subgraph "Build Tools & Dependencies"
            D1["Conan Dependencies"]:::build
            D2["go.mod"]:::build
            D3["go.sum"]:::build
            D4["project.clj"]:::build
        end
        subgraph "Deployment & CI/CD"
            E1["Dockerfile"]:::deploy
            E2["Docker Sources"]:::deploy
            E3["CI/CD"]:::deploy
        end
    end

    %% Connections between layers and components
    C1 -->|"HTTP/WS"| A2
    A2 -->|"calls_libcosim"| B1
    A2 -->|"serves"| C2

    D1 -->|"injects"| B1
    D2 -->|"manages"| A2
    D3 -->|"manages"| A2
    D4 -->|"builds"| C1

    E1 -->|"containerizes"| A2
    E2 -->|"includes"| C2
    E3 -->|"deploys"| E1

    %% Styles
    classDef server fill:#f9f91a,stroke:#333,stroke-width:2px;
    classDef lib fill:#ffadad,stroke:#333,stroke-width:2px;
    classDef client fill:#caffbf,stroke:#333,stroke-width:2px;
    classDef build fill:#9bf6ff,stroke:#333,stroke-width:2px;
    classDef deploy fill:#a0c4ff,stroke:#333,stroke-width:2px;

    %% Click Events for Go Server Component
    click A1 "https://github.com/open-simulation-platform/cosim-demo-app/blob/master/main.go"
    click A2 "https://github.com/open-simulation-platform/cosim-demo-app/blob/master/server/server.go"
    click A3 "https://github.com/open-simulation-platform/cosim-demo-app/blob/master/server/websockets.go"

    %% Click Events for libcosim Library
    click B1 "https://github.com/open-simulation-platform/cosim-demo-app/blob/master/libcosim/libcosim.go"
    click B2 "https://github.com/open-simulation-platform/cosim-demo-app/blob/master/libcosim/observers.go"
    click B3 "https://github.com/open-simulation-platform/cosim-demo-app/blob/master/libcosim/scenario.go"
    click B4 "https://github.com/open-simulation-platform/cosim-demo-app/blob/master/libcosim/trending.go"
    click B5 "https://github.com/open-simulation-platform/cosim-demo-app/blob/master/libcosim/utils.go"

    %% Click Events for ClojureScript Client and Static Assets
    click C1 "https://github.com/open-simulation-platform/cosim-demo-app/tree/master/src/client"
    click C2 "https://github.com/open-simulation-platform/cosim-demo-app/tree/master/resources/public"

    %% Click Events for Build Tools & Dependencies
    click D1 "https://github.com/open-simulation-platform/cosim-demo-app/blob/master/conanfile.txt"
    click D2 "https://github.com/open-simulation-platform/cosim-demo-app/blob/master/go.mod"
    click D3 "https://github.com/open-simulation-platform/cosim-demo-app/blob/master/go.sum"
    click D4 "https://github.com/open-simulation-platform/cosim-demo-app/blob/master/project.clj"

    %% Click Events for Deployment & CI/CD
    click E1 "https://github.com/open-simulation-platform/cosim-demo-app/tree/master/.dockerfiles/Dockerfile"
    click E2 "https://github.com/open-simulation-platform/cosim-demo-app/tree/master/.dockerfiles/sources"
    click E3 "https://github.com/open-simulation-platform/cosim-demo-app/blob/master/.github/workflows/ci-cosim-demo-app.yml"
```
