# processing/p5.js-web-editor architecture

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

- Interactive diagram: https://gitdiagram.com/processing/p5.js-web-editor
- Repository: https://github.com/processing/p5.js-web-editor

## Overview

##### Project Type & Purpose
- This is a full-stack web application that powers the p5.js Editor. Its purpose is to let users create, share, and remix p5.js sketches online.
- The frontend is focused on an accessible, beginner-friendly user experience (note the extensive client folder with React components, hooks, pages, Redux reducers/selectors, and storybook files) while the backend (server folder) provides RESTful APIs for managing users, projects, files, collections, and other domain objects.
- Additional folders (e.g., infrastructure, docker-compose files, Kubernetes configuration, Terraform scripts) indicate that the project supports containerized deployment and cloud infrastructure management.

##### File Structure & Architectural Clues
- The top-level organization clearly separates code concerns:
- The “client” directory contains client-side code built with JSX components, state management (likely using Redux), styles, tests, and tools (e.g., Storybook for component demos).
- The “server” directory provides backend logic including controllers, routes, models, and various utility functions. This suggests an MVC-like pattern for handling API requests.
- “infrastructure” includes Terraform scripts and related configuration for provisioning cloud resources such as a VPC, and there are Dockerfile(s) and docker-compose files for container orchestration.
- Several CI/CD configuration files (.github workflows, Travis, nodemon, etc.) demonstrate integrated testing, deployment automation, and linting.
- The presence of “client/routes.jsx” and detailed module subdirectories (such as those for the IDE, About, Legal, etc.) reinforces a modular client design.

##### Components & Relationships
- Frontend (Client) Components:
- Core user interface components: the editor, project/IDE components (e.g., “client/modules/IDE”), header navigation, and dialogs.
- State management via Redux with reducers, selectors, and middleware to handle application state and API calls.
- Integration with Storybook for UI component demo and testing.
- Backend (Server) Components:
- Controllers: Manage business logic for users, projects, files, collections, etc.
- Routes: Define API endpoints that map to controllers and middleware (e.g., authentication, sessions).
- Models: Represent business data like users and projects.
- Utility modules: Assist in email handling, file operations, error creation, and server-side rendering (e.g., for preview or mail layouts).
- Infrastructure & Deployment:
- Containerization: Dockerfile(s) for creating container images.
- Container orchestration: docker-compose files and Kubernetes YAML configuration.
- Terraform: Automate provisioning of cloud infrastructure.
- CI/CD: GitHub workflows, Travis, and scripts to deploy to staging/production.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Components
    subgraph "Frontend"
        F_UI["Frontend Application (React/JSX Components)"]:::frontend
        F_Redux["Redux Store"]:::frontend
        F_Reducers["Reducers"]:::frontend
        F_IDEReducers["IDE Reducers"]:::frontend
        F_API["API Client Module"]:::frontend
        F_Storybook["Storybook UI Demos"]:::frontend
    end

    %% Backend Components
    subgraph "Backend"
        B_API["REST API Server"]:::backend
        B_Controllers["Domain Controllers"]:::backend
        B_Utils["Utility Modules"]:::backend
    end

    %% Infrastructure & Deployment Components
    subgraph "Infrastructure & Deployment"
        I_Containers["Containerization & Deployment"]:::infra
        I_IaC["Infrastructure as Code (Terraform)"]:::infra
        I_CICD["CI/CD Pipelines & Testing"]:::infra
    end

    %% Connections within Frontend
    F_UI -->|"uses"| F_API
    F_UI -->|"manages"| F_Redux
    F_Redux -->|"updates"| F_Reducers
    F_Reducers -->|"integrates"| F_IDEReducers
    F_Storybook -->|"demos"| F_UI

    %% Frontend to Backend Communication
    F_API -->|"HTTPRESTcalls"| B_API

    %% Server Workflow
    B_API -->|"routes"| B_Controllers
    B_Controllers -->|"utilizes"| B_Utils

    %% Deployment Pipeline
    I_CICD -->|"builds"| I_Containers
    I_Containers -->|"provisions"| I_IaC

    %% Click Events for Frontend
    click F_UI "https://github.com/processing/p5.js-web-editor/tree/develop/client/"
    click F_Redux "https://github.com/processing/p5.js-web-editor/blob/develop/client/store.js"
    click F_Reducers "https://github.com/processing/p5.js-web-editor/blob/develop/client/reducers.js"
    click F_IDEReducers "https://github.com/processing/p5.js-web-editor/tree/develop/client/modules/IDE/reducers"
    click F_API "https://github.com/processing/p5.js-web-editor/blob/develop/client/utils/apiClient.js"
    click F_Storybook "https://github.com/processing/p5.js-web-editor/tree/develop/.storybook/"

    %% Click Events for Backend
    click B_API "https://github.com/processing/p5.js-web-editor/tree/develop/server/"
    click B_Controllers "https://github.com/processing/p5.js-web-editor/tree/develop/server/controllers/"
    click B_Utils "https://github.com/processing/p5.js-web-editor/tree/develop/server/utils/"

    %% Click Events for Infrastructure
    click I_Containers "https://github.com/processing/p5.js-web-editor/tree/develop/Dockerfile"
    click I_IaC "https://github.com/processing/p5.js-web-editor/tree/develop/infrastructure/terraform/"
    click I_CICD "https://github.com/processing/p5.js-web-editor/tree/develop/.github/workflows/"

    %% Styles
    classDef frontend fill:#aee2ff,stroke:#0277bd,stroke-width:2px;
    classDef backend fill:#dcedc8,stroke:#33691e,stroke-width:2px;
    classDef infra fill:#ffe0b2,stroke:#e65100,stroke-width:2px;
```
