# sai-pratham05/code-shimasu architecture

> Architecture diagram of the GitHub repository sai-pratham05/code-shimasu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sai-pratham05/code-shimasu
- Repository: https://github.com/sai-pratham05/code-shimasu

## Overview

##### Project Type and Purpose
- This is a full-stack web application called “code-shimasu,” built with Next.js (App Router) and TypeScript on the front end, and Convex on the back end.
- Purpose: collaborative code authoring, execution, sharing, and user-profile management with real-time features, multi-language support, and payment integration for premium plans.

##### File Structure Analysis
- Top level:
- convex/ – backend logic: Convex schema, serverless functions (codeExecutions.ts, snippets.ts, users.ts), authentication (auth.config.ts), external-service integrations (lemonSqueezy.ts, http.ts).
- src/app/ – Next.js App Router pages and layouts, organized by route: root, pricing, profile, snippets/[id].
- src/components/ – shared UI components and providers (ConvexClientProvider).
- Tailwind & PostCSS configs, ESLint, TS configs, package.json, next.config.ts.
- Architectural hints:
- Front end is a React/Next.js single-page interface with server-side and client-side rendering.
- Backend uses Convex as a serverless platform for data storage, function execution, and real-time subscriptions.
- External services for code sandboxing (via HTTP calls in codeExecutions.ts) and payment (LemonSqueezy).

##### Key Insights from README
- Real-time collaboration, snippet sharing via unique links.
- Multi-language execution in “secure, isolated environments.”
- User profiles and authentication.
- Payment for premium via LemonSqueezy.

##### Components
a. Frontend (Browser)
- Next.js App – pages, components, client-side state (Zustand or similar store).
- Convex Client SDK for data queries/mutations and real-time subscriptions.
- UI modules: EditorPanel, OutputPanel, LanguageSelector, RunButton, ShareSnippetDialog.
b. Backend
- Next.js Server (hosted on Vercel/Node) – handles SSR/SSG, API routes (if any), static asset serving.
- Convex Serverless Functions – codeExecutions, snippets CRUD, users, auth workflows.
c. Database
- Convex Database – stores users, snippets, comments, execution results, subscription data.
d. External Services
- Code Execution Sandbox – isolated environment for running user code (invoked via HTTP from Convex).
- LemonSqueezy – payment processing integration for premium feature gating.
- (Optional) Auth Provider – if not custom, via Convex auth or OAuth endpoints.
e. Static Assets
- CDN/Static Storage – hosts images, CSS (Tailwind), fonts.

##### Relationships and Data Flows
- User → Browser (React)
- Choose language, write code.
- Click Run → ConvexClient → codeExecutions function → Code Execution Service → return output.
- Click Share → ConvexClient → snippets.create → return snippet ID → shareable URL.
- Authentication flows → Convex Auth functions → set session cookie.
- Browser → Next.js Server
- Initial page load SSR/SSG, static route serving.
- API calls for data not handled by Convex SDK (if any).
- Convex Serverless → Convex DB
- Queries, mutations, real-time subscriptions on snippet/comment/user collections.
- Convex Serverless → External Services
- HTTP calls to LemonSqueezy for payment checks, Code Execution Service for sandbox runs.

##### Architectural Patterns and Principles
- Separation of concerns: UI layer (React/Next.js) vs data/business logic (Convex).
- Serverless microservices (Convex functions) for scalability and real-time subscriptions.
- Single source of truth: Convex database with real-time change feeds.
- Externalized services for specialized tasks (code sandboxing, payments).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Browser)" 
        direction TB
        ConvexSDK["ConvexClientProvider"]:::frontend
        EditorPanel["EditorPanel"]:::frontend
        OutputPanel["OutputPanel"]:::frontend
        LanguageSelector["LanguageSelector"]:::frontend
        RunButton["RunButton"]:::frontend
        ShareDialog["ShareSnippetDialog"]:::frontend
        Header["Header"]:::frontend
        ProfileBtn["HeaderProfileBtn"]:::frontend
        ThemeSelector["ThemeSelector"]:::frontend
        NavHeader["NavigationHeader"]:::frontend
        LoginBtn["LoginButton"]:::frontend
        StarBtn["StarButton"]:::frontend
        Footer["Footer"]:::frontend
        CodeStore["useCodeEditorStore"]:::frontend
    end

    click ConvexSDK "https://github.com/sai-pratham05/code-shimasu/blob/main/src/components/providers/ConvexClientProvider.tsx"
    click EditorPanel "https://github.com/sai-pratham05/code-shimasu/blob/main/src/app/(root)/_components/EditorPanel.tsx"
    click OutputPanel "https://github.com/sai-pratham05/code-shimasu/blob/main/src/app/(root)/_components/OutputPanel.tsx"
    click LanguageSelector "https://github.com/sai-pratham05/code-shimasu/blob/main/src/app/(root)/_components/LanguageSelector.tsx"
    click RunButton "https://github.com/sai-pratham05/code-shimasu/blob/main/src/app/(root)/_components/RunButton.tsx"
    click ShareDialog "https://github.com/sai-pratham05/code-shimasu/blob/main/src/app/(root)/_components/ShareSnippetDialog.tsx"
    click Header "https://github.com/sai-pratham05/code-shimasu/blob/main/src/app/(root)/_components/Header.tsx"
    click ProfileBtn "https://github.com/sai-pratham05/code-shimasu/blob/main/src/app/(root)/_components/HeaderProfileBtn.tsx"
    click ThemeSelector "https://github.com/sai-pratham05/code-shimasu/blob/main/src/app/(root)/_components/ThemeSelector.tsx"
    click NavHeader "https://github.com/sai-pratham05/code-shimasu/blob/main/src/components/NavigationHeader.tsx"
    click LoginBtn "https://github.com/sai-pratham05/code-shimasu/blob/main/src/components/LoginButton.tsx"
    click StarBtn "https://github.com/sai-pratham05/code-shimasu/blob/main/src/components/StarButton.tsx"
    click Footer "https://github.com/sai-pratham05/code-shimasu/blob/main/src/components/Footer.tsx"
    click CodeStore "https://github.com/sai-pratham05/code-shimasu/blob/main/src/store/useCodeEditorStore.ts"

    %% Next.js & Serverless Layer
    subgraph "Backend / Serverless" 
        direction TB
        NextServer["Next.js Server (SSR/SSG)"]:::server
        EdgeMiddleware["Edge Middleware"]:::server
        Config["next.config.ts"]:::server
        subgraph "Convex Functions" 
            direction TB
            Schema["schema.ts"]:::server
            AuthConfig["auth.config.ts"]:::server
            CodeExecFunc["codeExecutions.ts"]:::server
            SnippetsFunc["snippets.ts"]:::server
            UsersFunc["users.ts"]:::server
            HTTPHelpers["http.ts"]:::server
            LemonFunc["lemonSqueezy.ts"]:::server
            GenAPI["_generated/api.js/.d.ts"]:::server
        end
    end

    click Schema "https://github.com/sai-pratham05/code-shimasu/blob/main/convex/schema.ts"
    click AuthConfig "https://github.com/sai-pratham05/code-shimasu/blob/main/convex/auth.config.ts"
    click CodeExecFunc "https://github.com/sai-pratham05/code-shimasu/blob/main/convex/codeExecutions.ts"
    click SnippetsFunc "https://github.com/sai-pratham05/code-shimasu/blob/main/convex/snippets.ts"
    click UsersFunc "https://github.com/sai-pratham05/code-shimasu/blob/main/convex/users.ts"
    click HTTPHelpers "https://github.com/sai-pratham05/code-shimasu/blob/main/convex/http.ts"
    click LemonFunc "https://github.com/sai-pratham05/code-shimasu/blob/main/convex/lemonSqueezy.ts"
    click GenAPI "https://github.com/sai-pratham05/code-shimasu/blob/main/convex/_generated/api.js"

    click Config "https://github.com/sai-pratham05/code-shimasu/blob/main/next.config.ts"
    click EdgeMiddleware "https://github.com/sai-pratham05/code-shimasu/blob/main/src/middleware.ts"

    %% Database Layer
    subgraph "Database" 
        direction TB
        ConvexDB["Convex Database"]:::db
    end

    %% External Services
    subgraph "External Services" 
        direction TB
        CodeSandbox["Code Execution Service"]:::ext
        Lemon["LemonSqueezy API"]:::ext
    end

    %% Data Flows
    EditorPanel -->|renders with| ConvexSDK
    OutputPanel -->|subscribes via| ConvexSDK
    LanguageSelector -->|state in| CodeStore
    RunButton -->|invokes| CodeExecFunc
    CodeExecFunc -->|HTTP call| CodeSandbox
    CodeExecFunc -->|stores result| ConvexDB
    ShareDialog -->|calls| SnippetsFunc
    SnippetsFunc -->|CRUD on| ConvexDB
    UsersFunc -->|auth mutations| ConvexDB
    AuthConfig -->|manages sessions| NextServer
    NextServer -->|SSR data| ConvexDB
    NextServer -->|invokes| GenAPI
    ConvexSDK -->|queries/mutations| GenAPI
    GenAPI -->|calls| CodeExecFunc
    GenAPI -->|calls| SnippetsFunc
    GenAPI -->|calls| UsersFunc
    HTTPHelpers -->|external requests| CodeSandbox
    LemonFunc -->|HTTP call| Lemon
    Lemon -->|webhooks| UsersFunc

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#0288D1,stroke-width:1px
    classDef server fill:#E8F5E9,stroke:#388E3C,stroke-width:1px
    classDef db fill:#FFF3E0,stroke:#F57C00,stroke-width:1px
    classDef ext fill:#FFEBEE,stroke:#D32F2F,stroke-width:1px
```
