# amharshit45/scriptly architecture

> Architecture diagram of the GitHub repository amharshit45/scriptly, 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/amharshit45/scriptly
- Repository: https://github.com/amharshit45/scriptly

## Overview

##### Project Type & Purpose
- It’s a full-stack application with a clear separation between a React-based frontend (in the “client” directory) and a Node/Express-based backend (in the “server” directory).
- The project enables multi-user collaboration with features such as real-time code editing, file management, integrated chat, collaborative drawing, and an AI-powered “Copilot” assistant.
- Real-time communication is a core aspect, likely handled via Socket.io, as indicated in both the file tree (contexts and socket types) and the README.

##### File Structure
- Frontend (“client”):
- Built using React with TypeScript and styled by Tailwind CSS. The use of Vite, React Router, and multiple “components”, “contexts”, and “hooks” directories indicates a modular, component-based architecture.
- The “src” directory is organized into subfolders representing different features: editor, chats, drawing, files, sidebar, etc. This suggests separation of concerns within UI components.
- There are APIs (e.g., pistonApi.ts and pollinationsApi.ts) that likely facilitate backend communication, code execution, or external integrations.
- Backend (“server”):
- Contains a simple server.ts setup that likely establishes WebSocket or REST communication (evidenced by the inclusion of Socket types).
- The server structure is lean, focusing on handling requests, real-time socket communication, and possibly user management.

##### Main Components
a. User/Client Devices: Represent end-user input devices.
b. Frontend (Client):
- Code Editor Module: Show components like Editor, FileStructureView, and tooltips.
- Collaboration Features: Chat components, drawing board, Copilot integration, sidebar handling files, chats, and settings.
- Context and Hooks: Illustrate how shared states (AppContext, Theme, Settings, etc.) manage and propagate real-time updates.
c. Backend (Server):
- Real-Time Communication Service: Emphasize use of Socket.io (and any REST endpoints if applicable) for bridging communication.
- File and User Management: Modules in the backend that support file operations, user sessions, and socket event management.
d. External & Deployment Components:
- Docker/Containers: Use Dockerfile entries and docker-compose.yml to indicate containerized deployment for both client and server.
- Live Preview: A note for deployment on platforms like Vercel for the frontend.

##### Relationships & Interactions
- HTTP/API calls (to external services, file management, code execution via piston API or pollinations API).
- WebSocket communications to the Backend for real-time collaboration (propagating code changes, chat messages, user presence, etc.).
- From the Backend, show responses and broadcast mechanisms towards all connected clients to maintain synchronization.
- Docker containers and the docker-compose setup as part of the deployment layer regulating both client and server operations.

##### Architectural Patterns & Technologies
- MVC/Component-Based Design for the frontend given the separation into components, context providers, and hooks.
- Real-time Event-driven Communication Pattern via Socket.io between the client and server.
- Micro-service or containerized deployment model as evidenced by separate Dockerfiles and docker-compose.yml.
- The use of modern technologies such as React, TypeScript, Express, and Tailwind CSS is central to the project’s stack.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    subgraph "User Layer"
        U["User Devices"]:::user
    end

    %% Frontend Components
    subgraph "Frontend (React)"
        FE["React Frontend"]:::frontend
        FE_Code["Code Editor Module"]:::frontend
        FE_Chat["Chat Functionality"]:::frontend
        FE_Drawing["Drawing Board"]:::frontend
        FE_File["File Management"]:::frontend
        FE_Copilot["Copilot Integration"]:::frontend
        FE_Sidebar["Sidebar (Navigation & Tools)"]:::frontend
        FE_Context["Context Providers"]:::frontend
        FE_API["API Integrations"]:::frontend
    end

    %% Backend Components
    subgraph "Backend (Node/Express)"
        BE_Server["Server (Socket.io)"]:::backend
        BE_Socket["Socket Types"]:::backend
    end

    %% Deployment & Containerization
    subgraph "Deployment & Containerization"
        Deploy_Front["Frontend Docker"]:::deployment
        Deploy_Back["Backend Docker"]:::deployment
        Deploy_Orch["Docker Compose"]:::deployment
    end

    %% Interactions
    U -->|"interacts"| FE
    FE -->|"communicates_with"| BE_Server
    FE_API -->|"calls"| BE_Server
    BE_Server -->|"broadcasts"| FE

    Deploy_Front -.-> FE
    Deploy_Back -.-> BE_Server
    Deploy_Orch -.-> Deploy_Front
    Deploy_Orch -.-> Deploy_Back

    %% Click Events for Frontend
    click FE "https://github.com/amharshit45/scriptly/tree/main/client/"
    click FE_Code "https://github.com/amharshit45/scriptly/tree/main/client/src/components/editor/"
    click FE_Chat "https://github.com/amharshit45/scriptly/tree/main/client/src/components/chats/"
    click FE_Drawing "https://github.com/amharshit45/scriptly/blob/main/client/src/components/drawing/DrawingEditor.tsx"
    click FE_File "https://github.com/amharshit45/scriptly/blob/main/client/src/components/files/FileStructureView.tsx"
    click FE_Copilot "https://github.com/amharshit45/scriptly/blob/main/client/src/components/sidebar/sidebar-views/CopilotView.tsx"
    click FE_Sidebar "https://github.com/amharshit45/scriptly/tree/main/client/src/components/sidebar/"
    click FE_Context "https://github.com/amharshit45/scriptly/tree/main/client/src/context/"
    click FE_API "https://github.com/amharshit45/scriptly/tree/main/client/src/api/"

    %% Click Events for Backend
    click BE_Server "https://github.com/amharshit45/scriptly/blob/main/server/src/server.ts"
    click BE_Socket "https://github.com/amharshit45/scriptly/blob/main/server/src/types/socket.ts"

    %% Click Events for Deployment
    click Deploy_Front "https://github.com/amharshit45/scriptly/tree/main/client/Dockerfile"
    click Deploy_Back "https://github.com/amharshit45/scriptly/tree/main/server/Dockerfile"
    click Deploy_Orch "https://github.com/amharshit45/scriptly/blob/main/docker-compose.yml"

    %% Styles
    classDef user fill:#ffadad,stroke:#333,stroke-width:2px;
    classDef frontend fill:#a0c4ff,stroke:#333,stroke-width:2px;
    classDef backend fill:#caffbf,stroke:#333,stroke-width:2px;
    classDef deployment fill:#fdffb6,stroke:#333,stroke-width:2px;
```
