# juspay/superposition architecture

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

- Interactive diagram: https://gitdiagram.com/juspay/superposition
- Repository: https://github.com/juspay/superposition

## Overview

##### Project Type and Purpose
- Superposition is a cloud configuration and experimentation management platform. Its primary purpose is to offer a central location to manage context-aware configuration (“Context-Aware-Configuration”), execute multivariate experiments (“Experimentation”), and eventually handle metrics.
- The README specifies separate core components for managing configurations, running experiments, and (in the near future) handling analytics or metrics.
- The existence of multiple client folders (in Go, Haskell, Java, JavaScript, and Python) indicates that the platform provides SDKs/libraries for a broad range of languages, making it a multi-language, full-stack project.

##### File Structure
– “context_aware_config” (and its client counterpart “cac_client” and “cac_toml”) manages configuration state.
– “experimentation_client” and “experimentation_platform” manage the experimentation aspects.
– “frontend” provides the administration tools and UI capabilities.
– “service_utils” likely contains shared resources/middleware for services (like DB integration, AWS utilities, etc.).
– “superposition” appears to be the main backend (with additional auth and organisation modules).
– Other utility crates (such as “superposition_derives”, “superposition_macros”, and “superposition_types”) are likely used to reduce boilerplate, share common types, and enforce schema migrations (as indicated by the migrations folder in “superposition_types”).
- Support files such as Dockerfiles, docker-compose.yaml, and build scripts further indicate deployment strategies based on containerized services and local environment setup.
- The tests, Postman collections, and documentation directories verify that the project has strong API support and automated integrations.

##### Core Components & Their Relationships
- Backend Services:
- Context-Aware Configuration: Handles configuration changes, context-specific overrides, and validations.
- Experimentation Service: Manages A/B testing and experimentation logic including cohort splitting.
- (Future) Metrics Module: Integrates with analytics backends for experiment evaluation.
- Superposition: Likely integrates authentication, organisation, and workspace management along with overall API routing.
- Shared Utilities: Crates like “service_utils” provide lower-level support such as database connections, middleware, AWS integrations, etc.
- Frontend:
- Admin UI built as a separate crate (under “crates/frontend”) serves as the point-of-interaction for administrators to manage configurations/experiments.
- Clients:
- Multiple language-specific SDKs and client libraries that interact with the APIs, making it easy for diverse teams to integrate Superposition within their applications.
- Database & Infrastructure:
- The presence of docker-compose definitions for Postgres and localstack indicates that a relational database (most likely Postgres) is used for persistence and possibly AWS integrations simulated in a local environment.
- Interactions:
- The frontend makes API requests to the backend services.
- The backend services interact with the database and potentially with external systems (e.g., for metrics collection or third-party authentication integrations).
- Client libraries provide endpoints for external applications to interact with the platform’s API.

##### Detailed Element Descriptions
- Clear Labels: Each component should have a clear label (e.g., “Frontend Admin UI”, “Context-Aware Config Service”, “Experimentation Service”, “Auth & Organisational Module”, “Database – Postgres”, “Client SDKs (Go, Java, etc.)”).
- Blue for presentation (Frontend).
- Green for backend services.
- Orange for utility libraries.
- Gray for infrastructure components like databases.

This detailed approach will help clarify the architecture for any stakeholder and serve as an accurate reflection of the project’s design and modularity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client and UI Layers
    clients["Client SDKs (Go, Haskell, Java, JS, Python)"]:::clients
    ui["Admin UI (Frontend)"]:::frontend

    %% Backend Services Subgraph
    subgraph "Backend Services"
        backend["Main Backend (API, Auth, Organisation)"]:::backend
        cac["Context-Aware Config Service"]:::backend
        exp["Experimentation Service"]:::backend
        expClient["Experimentation Client Library"]:::backend
        shared["Shared Utilities / Common Libraries"]:::utilities
    end

    %% Infrastructure and External Services
    db["Postgres Database"]:::database
    external["Localstack (AWS Integration)"]:::external

    %% Interactions
    clients -->|"APIcalls"| backend
    ui -->|"APIcalls"| backend
    backend -->|"invokes"| cac
    backend -->|"invokes"| exp
    backend -->|"utilizes"| shared
    expClient -->|"interfaces"| exp
    exp -->|"uses"| cac
    backend -->|"persists"| db
    shared -->|"DBsupport"| db
    backend -->|"integrates"| external
    shared -->|"integrates"| external

    %% Click Events
    click cac "https://github.com/juspay/superposition/tree/main/crates/context_aware_config"
    click exp "https://github.com/juspay/superposition/tree/main/crates/experimentation_platform"
    click expClient "https://github.com/juspay/superposition/tree/main/crates/experimentation_client"
    click ui "https://github.com/juspay/superposition/tree/main/crates/frontend"
    click backend "https://github.com/juspay/superposition/tree/main/crates/superposition"
    click shared "https://github.com/juspay/superposition/tree/main/crates/service_utils"
    click clients "https://github.com/juspay/superposition/tree/main/clients"
    click db "https://github.com/juspay/superposition/tree/main/docker-compose/postgres"
    click external "https://github.com/juspay/superposition/tree/main/docker-compose/localstack"

    %% Styles
    classDef frontend fill:#85CDFD,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#9AE6B4,stroke:#234E52,stroke-width:2px;
    classDef utilities fill:#FBD38D,stroke:#975A16,stroke-width:2px;
    classDef database fill:#E2E8F0,stroke:#718096,stroke-width:2px;
    classDef clients fill:#FEFCBF,stroke:#B7791F,stroke-width:2px;
    classDef external fill:#E2E8F0,stroke:#718096,stroke-width:2px;

    %% Assign Classes
    class ui frontend;
    class backend,cac,exp,expClient backend;
    class shared utilities;
    class clients clients;
    class db database;
    class external external;
```
