# rohitsinghten/code-craft architecture

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

- Interactive diagram: https://gitdiagram.com/rohitsinghten/code-craft
- Repository: https://github.com/rohitsinghten/code-craft

## Overview

##### Project type and purpose
- This is a full-stack web application built on Next.js (React) with a serverless backend using Convex.
- Purpose: users can write, run, share, and comment on code snippets, manage profiles, and purchase pro features via LemonSqueezy.

##### File structure
- Top-level “src/app” and “src/components” → Next.js app router, React UI components, feature-based folders (root, pricing, profile, snippets).
- “convex/” folder → serverless business logic and data schema:
- schema.ts defines data models (snippets, users, comments, etc.).
- auth.config.ts configures authentication roles.
- codeExecutions.ts calls out to a code-runner API.
- lemonSqueezy.ts integrates with the payment gateway.
- http.ts exposes custom HTTP endpoints.
- Configuration files: next.config.ts, tsconfig.json, tailwind.config.ts, ESLint, PostCSS.
- State management: src/store (Zustand).
- Hooks, providers (ConvexClientProvider), middleware, public assets, global CSS.

##### (empty) README for additional insights
- No explicit architecture doc, but folder names and filenames reveal:
- External services: code execution engine, LemonSqueezy.
- Core features: snippets CRUD, comments, user profiles, payments.

##### Elements
- UI (e.g., blue rectangles)
- Application servers/functions (e.g., green)

##### Detail level
- Essential interactions: user login, snippet CRUD, code execution cycle, payment checkout.
- Non-obvious flows (e.g., webhooks from LemonSqueezy into http.ts).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        Browser["User Browser (React UI)"]:::ui
        NextApp["Next.js App Router"]:::app
        Components["Shared React Components"]:::ui
        State["Zustand Store"]:::state
        Providers["ConvexClientProvider"]:::app
        Hooks["Custom Hooks"]:::app
        Styles["Global Styles"]:::assets
        NextConfig["Next.js Configuration"]:::config
        Tailwind["Tailwind Config"]:::config
        Middleware["Middleware (Edge)"]:::app
    end

    subgraph "Backend Layer"
        ConvexFuncs["Convex Serverless Functions"]:::backend
        Schema["Schema Definitions"]:::backend
        AuthCfg["Authentication Config"]:::backend
        Snippets["Snippet Business Logic"]:::backend
        Users["User Business Logic"]:::backend
        HTTP["HTTP Endpoints"]:::backend
        Exec["Code Execution Integration"]:::backend
        Lemon["LemonSqueezy Integration"]:::backend
        Generated["Generated API Types"]:::backend
        ConvexTS["Convex tsconfig"]:::config
    end

    subgraph "External Services"
        CodeService["Code Execution Service"]:::service
        LemonAPI["LemonSqueezy Payment API"]:::service
    end

    DB["Convex Data Store"]:::database

    Browser -->|HTTP/Fetch| NextApp
    NextApp -->|"RPC Calls"| ConvexFuncs
    NextApp --> Components
    NextApp --> State
    NextApp --> Providers
    NextApp --> Hooks
    NextApp --> Styles
    NextApp --> NextConfig
    NextApp --> Tailwind
    NextApp --> Middleware

    ConvexFuncs --> Schema
    ConvexFuncs --> AuthCfg
    ConvexFuncs --> Snippets
    ConvexFuncs --> Users
    ConvexFuncs --> HTTP
    ConvexFuncs --> Exec
    ConvexFuncs --> Lemon
    ConvexFuncs --> Generated
    ConvexFuncs --> ConvexTS
    Schema --> DB
    Snippets --> DB
    Users --> DB

    Exec -.->|REST API| CodeService
    Lemon -.->|REST API| LemonAPI
    LemonAPI -.->|Webhook| HTTP

    classDef ui fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef app fill:#E6F5D0,stroke:#28a745,color:#28a745
    classDef state fill:#FFF0B3,stroke:#FFC107,color:#FF6F00
    classDef config fill:#F0E6FF,stroke:#6f42c1,color:#6f42c1
    classDef assets fill:#FFE6E6,stroke:#d73a49,color:#d73a49
    classDef backend fill:#E8F0FE,stroke:#1D6F42,color:#1D6F42
    classDef database fill:#E0FFEE,stroke:#00a66c,color:#005f40
    classDef service fill:#FFF4E6,stroke:#dbab09,color:#dbab09

    click NextApp "https://github.com/rohitsinghten/code-craft/tree/main/src/app"
    click Components "https://github.com/rohitsinghten/code-craft/tree/main/src/components"
    click NextConfig "https://github.com/rohitsinghten/code-craft/blob/main/next.config.ts"
    click Styles "https://github.com/rohitsinghten/code-craft/blob/main/src/app/globals.css"
    click Tailwind "https://github.com/rohitsinghten/code-craft/blob/main/tailwind.config.ts"
    click State "https://github.com/rohitsinghten/code-craft/blob/main/src/store/useCodeEditorStore.ts"
    click ConvexFuncs "https://github.com/rohitsinghten/code-craft/tree/main/convex"
    click Schema "https://github.com/rohitsinghten/code-craft/blob/main/convex/schema.ts"
    click AuthCfg "https://github.com/rohitsinghten/code-craft/blob/main/convex/auth.config.ts"
    click Snippets "https://github.com/rohitsinghten/code-craft/blob/main/convex/snippets.ts"
    click Users "https://github.com/rohitsinghten/code-craft/blob/main/convex/users.ts"
    click HTTP "https://github.com/rohitsinghten/code-craft/blob/main/convex/http.ts"
    click Exec "https://github.com/rohitsinghten/code-craft/blob/main/convex/codeExecutions.ts"
    click Lemon "https://github.com/rohitsinghten/code-craft/blob/main/convex/lemonSqueezy.ts"
    click Generated "https://github.com/rohitsinghten/code-craft/tree/main/convex/_generated"
    click ConvexTS "https://github.com/rohitsinghten/code-craft/blob/main/convex/tsconfig.json"
    click Providers "https://github.com/rohitsinghten/code-craft/blob/main/src/components/providers/ConvexClientProvider.tsx"
    click Hooks "https://github.com/rohitsinghten/code-craft/blob/main/src/hooks/useMounted.tsx"
    click Middleware "https://github.com/rohitsinghten/code-craft/blob/main/src/middleware.ts"
```
