# ishan1603/codlr architecture

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

- Interactive diagram: https://gitdiagram.com/ishan1603/codlr
- Repository: https://github.com/ishan1603/codlr

## Overview

##### Project type and purpose
- This is a full‐stack Next.js web application (using the new App Router) that lets authenticated users browse, star, and “play” with a library of code‐starter templates.
- It uses NextAuth for authentication, Prisma as an ORM over a relational database, and file‐system–based code templates under `code-starters`.

##### File structure
- Top‐level Next.js “app” folder holds server‐and client‐rendered routes:
- `/auth` (sign‐in pages)
- `/dashboard` (user’s saved/starred templates)
- `/playground/[id]` (interactive editor)
- API routes under `app/api/auth/[...nextauth]` and `app/api/template/[id]`
- `components/`, `modules/`, and `hooks/` contain UI and client logic organized by feature (auth, dashboard, playground, home).
- `lib/` holds server utilities:
- `db.ts` – Prisma client initialization
- `template.ts` – loader for file‐system templates
- `utils.ts` – shared helpers
- `prisma/` directory defines your schema (`schema.prisma`) and config (`prisma.config.ts`).
- `code-starters/` is a large folder of various framework starter kits (Angular, Astro, React, etc.) that back the playground and template lists.
- `src/generated/` is the Prisma client types and models.

##### README for additional insights
- Bootstrapped with `create-next-app`
- Standard Next.js commands, zero‐config Vercel deploy

a. Main components
– Client Browser (React + Next.js)
– Next.js Server–Side Renderer & API
– Authentication service (NextAuth)
– Database (via Prisma)
– File System Templates (code-starters folder)
b. Relationships & data flows
1. Browser requests a page (e.g., `/dashboard`) → Next.js SSR reads session → fetches user data via Prisma → renders React components → HTML/JSON back to client.
2. Browser calls client‐side API fetch to `/api/template/[id]` → Next.js API handler uses `lib/template.ts` to read from `code-starters` → returns JSON of files.
3. Browser sends POST to `/api/auth/*` → NextAuth middleware verifies credentials → writes session to DB → issues session cookies.
4. Browser interacts with the “Playground” editor → updates stored in-memory or persisted via API calls to custom route (if implemented).
c. Architectural patterns and principles
– Layered design: UI (modules + components), API (route handlers), persistence (Prisma + file system)
– Serverless functions (app/api) for business logic
– Separation of concerns: modules/auth, modules/dashboard, modules/playground share no direct coupling
– Next.js App Router for co-located page + data fetch + layout definitions
d. Key technologies
– Next.js (App Router + Server Components + API Routes)
– React (client components)
– NextAuth (authentication)
– Prisma ORM (database access)
– TypeScript (end-to-end)
– Node.js file‐system for code templates

##### Essential architectural elements to capture
– Next.js App Router structure: which routes map to which modules
– NextAuth integration point (middleware.ts or in `[...nextauth]` route)
– Prisma client usage via `lib/db.ts` and schema-driven models
– Code‐starter template loader reading from `code-starters/` on disk
– UI ↔ API interactions for template loading, starring, playground operations

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External
    Browser["Client Browser"]:::external

    %% Frontend UI - Pages & Layouts
    subgraph "Pages & Layouts" 
        direction TB
        RootPage["app/(root)/page.tsx"]:::ui
        RootLayout["app/(root)/layout.tsx"]:::ui
        AuthLayout["app/(auth)/auth/layout.tsx"]:::ui
        SignInPage["app/(auth)/auth/sign-in/page.tsx"]:::ui
        DashboardPage["app/dashboard/page.tsx"]:::ui
        DashboardLayout["app/dashboard/layout.tsx"]:::ui
        PlaygroundPage["app/playground/[id]/page.tsx"]:::ui
        PlaygroundLayout["app/playground/[id]/layout.tsx"]:::ui
    end

    %% UI Modules & Components
    subgraph "UI Modules & Components"
        direction TB
        ComponentsDir["components/"]:::ui
        ModulesAuth["modules/auth"]:::ui
        SignInForm["modules/auth/components/sign-in-form-client.tsx"]:::ui
        LogoutBtn["modules/auth/components/logout-button.tsx"]:::ui
        UseCurrentUser["modules/auth/hooks/use-current-user.ts"]:::ui
        ModulesDashboard["modules/dashboard"]:::ui
        DashboardSidebar["modules/dashboard/components/dashboard-sidebar.tsx"]:::ui
        ProjectTable["modules/dashboard/components/project-table.tsx"]:::ui
        DashboardActions["modules/dashboard/actions/index.ts"]:::ui
        ModulesPlayground["modules/playground"]:::ui
        PlaygroundExplorer["modules/playground/components/playground-explorer.tsx"]:::ui
        PlaygroundDialogs["modules/playground/components/dialogs/"]:::ui
        UsePlayground["modules/playground/hooks/usePlayground.tsx"]:::ui
        PathToJson["modules/playground/lib/path-to-json.ts"]:::ui
        ModulesHome["modules/home"]:::ui
        HomeHeader["modules/home/header.tsx"]:::ui
        HomeFooter["modules/home/footer.tsx"]:::ui
        HooksDir["hooks/use-mobile.ts"]:::ui
    end

    Browser -->|"Navigates to pages"| RootPage
    Browser -->|"Uses UI modules"| ComponentsDir

    %% Backend Server
    subgraph "Next.js Server (SSR + API)" 
        direction TB
        Server["Next.js Server"]:::server
        subgraph "API Routes"
            AuthAPI["app/api/auth/[...nextauth]/route.ts"]:::server
            TemplateAPI["app/api/template/[id]/route.ts"]:::server
        end
        subgraph "Server Utilities"
            DBUtil["lib/db.ts"]:::server
            TemplateUtil["lib/template.ts"]:::server
            Utils["lib/utils.ts"]:::server
        end
        Middleware["middleware.ts"]:::server
    end

    RootPage --> Server
    AuthAPI --> Server
    TemplateAPI --> Server
    Server --> Middleware

    %% Authentication
    NextAuth["NextAuth"]:::external
    AuthAPI -->|"Auth logic"| NextAuth
    Middleware -->|"Protect routes"| NextAuth

    %% Database Layer
    DBUtil -->|"ORM access"| PrismaClient["src/generated/"]:::persistence
    PrismaClient -->|"Queries models"| Database["Relational Database"]:::persistence
    DatabaseSchema["prisma/schema.prisma"]:::persistence
    PrismaConfig["prisma.config.ts"]:::persistence

    DBUtil --> DatabaseSchema
    DBUtil --> PrismaConfig

    %% File System Templates
    TemplateUtil -->|"Reads templates"| CodeStarters["code-starters/"]:::persistence

    %% Flows
    Browser -->|"API call"| TemplateAPI
    Browser -->|"API call"| AuthAPI
    Server --> DBUtil
    Server --> TemplateUtil

    %% Click events
    click RootPage "https://github.com/ishan1603/codlr/blob/main/app/(root)/page.tsx"
    click RootLayout "https://github.com/ishan1603/codlr/blob/main/app/(root)/layout.tsx"
    click AuthLayout "https://github.com/ishan1603/codlr/blob/main/app/(auth)/auth/layout.tsx"
    click SignInPage "https://github.com/ishan1603/codlr/blob/main/app/(auth)/auth/sign-in/page.tsx"
    click DashboardPage "https://github.com/ishan1603/codlr/blob/main/app/dashboard/page.tsx"
    click DashboardLayout "https://github.com/ishan1603/codlr/blob/main/app/dashboard/layout.tsx"
    click PlaygroundPage "https://github.com/ishan1603/codlr/blob/main/app/playground/[id]/page.tsx"
    click PlaygroundLayout "https://github.com/ishan1603/codlr/blob/main/app/playground/[id]/layout.tsx"
    click AuthAPI "https://github.com/ishan1603/codlr/blob/main/app/api/auth/[...nextauth]/route.ts"
    click TemplateAPI "https://github.com/ishan1603/codlr/blob/main/app/api/template/[id]/route.ts"
    click ComponentsDir "https://github.com/ishan1603/codlr/tree/main/components/"
    click SignInForm "https://github.com/ishan1603/codlr/blob/main/modules/auth/components/sign-in-form-client.tsx"
    click LogoutBtn "https://github.com/ishan1603/codlr/blob/main/modules/auth/components/logout-button.tsx"
    click UseCurrentUser "https://github.com/ishan1603/codlr/blob/main/modules/auth/hooks/use-current-user.ts"
    click DashboardSidebar "https://github.com/ishan1603/codlr/blob/main/modules/dashboard/components/dashboard-sidebar.tsx"
    click ProjectTable "https://github.com/ishan1603/codlr/blob/main/modules/dashboard/components/project-table.tsx"
    click DashboardActions "https://github.com/ishan1603/codlr/blob/main/modules/dashboard/actions/index.ts"
    click PlaygroundExplorer "https://github.com/ishan1603/codlr/blob/main/modules/playground/components/playground-explorer.tsx"
    click PlaygroundDialogs "https://github.com/ishan1603/codlr/tree/main/modules/playground/components/dialogs/"
    click UsePlayground "https://github.com/ishan1603/codlr/blob/main/modules/playground/hooks/usePlayground.tsx"
    click PathToJson "https://github.com/ishan1603/codlr/blob/main/modules/playground/lib/path-to-json.ts"
    click HomeHeader "https://github.com/ishan1603/codlr/blob/main/modules/home/header.tsx"
    click HomeFooter "https://github.com/ishan1603/codlr/blob/main/modules/home/footer.tsx"
    click HooksDir "https://github.com/ishan1603/codlr/blob/main/hooks/use-mobile.ts"
    click DBUtil "https://github.com/ishan1603/codlr/blob/main/lib/db.ts"
    click TemplateUtil "https://github.com/ishan1603/codlr/blob/main/lib/template.ts"
    click Utils "https://github.com/ishan1603/codlr/blob/main/lib/utils.ts"
    click PrismaClient "https://github.com/ishan1603/codlr/tree/main/src/generated/"
    click DatabaseSchema "https://github.com/ishan1603/codlr/blob/main/prisma/schema.prisma"
    click PrismaConfig "https://github.com/ishan1603/codlr/blob/main/prisma.config.ts"
    click CodeStarters "https://github.com/ishan1603/codlr/tree/main/code-starters/"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#009,stroke-width:1px
    classDef server fill:#d4edda,stroke:#060,stroke-width:1px
    classDef persistence fill:#fff3cd,stroke:#994,stroke-width:1px
    classDef external fill:#e2e3e5,stroke:#666,stroke-width:1px
```
