# drockparashar/snippetcove architecture

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

- Interactive diagram: https://gitdiagram.com/drockparashar/snippetcove
- Repository: https://github.com/drockparashar/snippetcove

## Overview

##### Project type and purpose
- This is a full-stack web application named “SnipCove,” a community-driven platform for saving, sharing, and discovering code snippets.
- Frontend: Next.js 15 + React + TypeScript + Tailwind CSS + Shadcn/ui.
- Backend: Node.js + Express.js + MongoDB (Mongoose) with JWT-based and GitHub OAuth authentication.
- External services: Cloudinary for image storage, Vercel for frontend hosting, Render for backend hosting, MongoDB Atlas for database.

##### File structure
- Top-level separation:
- client/ – Next.js 15 frontend (App Router, TypeScript, React Context).
- server/ – Express.js backend (controllers, routes, models, middlewares, config).
- client/src/app/ – Next.js app router organizes pages by feature: auth, dashboard, snippets, submit, users.
- client/src/components/ – shared UI components (CodeBlock, Navbar, SnippetCard, theme handling, Shadcn/ui primitives).
- server/controllers & server/routes – map HTTP endpoints to business logic.
- server/models – MongoDB schema definitions for User and Snippet.
- Config & middleware – DB connection, session, JWT, rate-limiting, input sanitization.

##### README for additional insights
- Tech stack and feature list confirm real-time updates, analytics dashboard, secure auth, responsive design, etc.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        NextApp["Next.js 15 App Router"]:::frontend
        NextConfig["next.config.ts"]:::frontend
        GlobalsCSS["globals.css"]:::frontend
        Layout["layout.tsx"]:::frontend

        subgraph "Feature Modules"
            direction TB
            AuthRoute["(auth) App Router"]:::frontend
            DashboardRoute["dashboard"]:::frontend
            SnippetsRoute["snippets"]:::frontend
            SubmitRoute["submit"]:::frontend
            UsersRoute["users"]:::frontend
        end

        subgraph "React Context & State"
            direction TB
            AuthContext["auth-context.tsx"]:::frontend
            ThemeProvider["theme-provider.tsx"]:::frontend
            TokenHandler["TokenHandler.tsx"]:::frontend
        end

        subgraph "Shared UI Components"
            direction TB
            CodeBlock["CodeBlock.tsx"]:::frontend
            Navbar["Navbar.tsx"]:::frontend
            SnippetCard["SnippetCard.tsx"]:::frontend
            ThemeToggle["ThemeToggle.tsx"]:::frontend
            ToastProvider["toast-provider.tsx"]:::frontend
            UIPrimitives["ui (Shadcn/ui)"]:::frontend
        end

        subgraph "Utilities & Types"
            direction TB
            BackendLib["backend.ts"]:::frontend
            UtilsLib["utils.ts"]:::frontend
            UserTypes["user.ts"]:::frontend
        end

        subgraph "Linting & Build Config"
            direction TB
            ESLintConfig["eslint.config.mjs"]:::frontend
            TSConfig["tsconfig.json"]:::frontend
            PostCSSConfig["postcss.config.mjs"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        ExpressServer["Express.js API"]:::backend
        AppEntry["app.js"]:::backend
        DBConfig["db.js"]:::backend
        SessionConfig["session.js"]:::backend

        subgraph "Controllers"
            direction TB
            AuthController["auth.js"]:::backend
            PassportController["passport.js"]:::backend
            AvatarController["avatar.js"]:::backend
            UsersController["users.js"]:::backend
            SnippetsController["snippets.js"]:::backend
            UtilsController["utils.js"]:::backend
        end

        subgraph "Routes"
            direction TB
            AuthRoutes["authRoutes.js"]:::backend
            GitHubAuth["githubAuth.js"]:::backend
            CheckAuth["checkAuth.js"]:::backend
            UsersRoutes["users.js"]:::backend
            SnippetsRoutes["snippets.js"]:::backend
        end

        subgraph "Models"
            direction TB
            UserModel["User.js"]:::backend
            SnippetModel["Snippet.js"]:::backend
        end

        AuthMiddleware["auth.js"]:::backend
        SeedScript["populate.js"]:::backend
        EnvExample[".env.example"]:::backend
        EntriesJSON["entries.json"]:::backend
    end

    %% Database
    MongoDB["MongoDB Atlas"]:::database

    %% External Services
    subgraph "External Services"
        direction TB
        Cloudinary["Cloudinary"]:::external
        GitHubOAuth["GitHub OAuth"]:::external
        Vercel["Vercel (Frontend)"]:::external
        Render["Render (Backend)"]:::external
    end

    %% Relationships
    NextApp -->|"HTTPS REST API"| ExpressServer
    ExpressServer -->|"Mongoose Driver"| MongoDB
    ExpressServer -->|"Cloudinary SDK"| Cloudinary
    AuthRoute -->|"OAuth2 Flow"| GitHubOAuth
    GitHubOAuth -->|"OAuth Callback"| ExpressServer
    ExpressServer -->|"JWT Token"| NextApp
    NextApp -->|"Deploy"| Vercel
    ExpressServer -->|"Deploy"| Render

    %% Click Events Frontend
    click NextApp "https://github.com/drockparashar/snippetcove/tree/main/client/src/app"
    click NextConfig "https://github.com/drockparashar/snippetcove/blob/main/client/next.config.ts"
    click GlobalsCSS "https://github.com/drockparashar/snippetcove/blob/main/client/src/app/globals.css"
    click Layout "https://github.com/drockparashar/snippetcove/blob/main/client/src/app/layout.tsx"
    click AuthRoute "https://github.com/drockparashar/snippetcove/tree/main/client/src/app/(auth)"
    click DashboardRoute "https://github.com/drockparashar/snippetcove/tree/main/client/src/app/dashboard"
    click SnippetsRoute "https://github.com/drockparashar/snippetcove/tree/main/client/src/app/snippets"
    click SubmitRoute "https://github.com/drockparashar/snippetcove/tree/main/client/src/app/submit"
    click UsersRoute "https://github.com/drockparashar/snippetcove/tree/main/client/src/app/users"
    click AuthContext "https://github.com/drockparashar/snippetcove/blob/main/client/src/components/auth-context.tsx"
    click ThemeProvider "https://github.com/drockparashar/snippetcove/blob/main/client/src/components/theme-provider.tsx"
    click TokenHandler "https://github.com/drockparashar/snippetcove/blob/main/client/src/components/TokenHandler.tsx"
    click CodeBlock "https://github.com/drockparashar/snippetcove/blob/main/client/src/components/CodeBlock.tsx"
    click Navbar "https://github.com/drockparashar/snippetcove/blob/main/client/src/components/Navbar.tsx"
    click SnippetCard "https://github.com/drockparashar/snippetcove/blob/main/client/src/components/SnippetCard.tsx"
    click ThemeToggle "https://github.com/drockparashar/snippetcove/blob/main/client/src/components/ThemeToggle.tsx"
    click ToastProvider "https://github.com/drockparashar/snippetcove/blob/main/client/src/components/toast-provider.tsx"
    click UIPrimitives "https://github.com/drockparashar/snippetcove/tree/main/client/src/components/ui"
    click BackendLib "https://github.com/drockparashar/snippetcove/blob/main/client/src/lib/backend.ts"
    click UtilsLib "https://github.com/drockparashar/snippetcove/blob/main/client/src/lib/utils.ts"
    click UserTypes "https://github.com/drockparashar/snippetcove/blob/main/client/src/types/user.ts"
    click ESLintConfig "https://github.com/drockparashar/snippetcove/blob/main/client/eslint.config.mjs"
    click TSConfig "https://github.com/drockparashar/snippetcove/blob/main/client/tsconfig.json"
    click PostCSSConfig "https://github.com/drockparashar/snippetcove/blob/main/client/postcss.config.mjs"

    %% Click Events Backend
    click ExpressServer "https://github.com/drockparashar/snippetcove/blob/main/server/server.js"
    click AppEntry "https://github.com/drockparashar/snippetcove/blob/main/server/app.js"
    click DBConfig "https://github.com/drockparashar/snippetcove/blob/main/server/config/db.js"
    click SessionConfig "https://github.com/drockparashar/snippetcove/blob/main/server/config/session.js"
    click AuthController "https://github.com/drockparashar/snippetcove/blob/main/server/controllers/auth.js"
    click PassportController "https://github.com/drockparashar/snippetcove/blob/main/server/controllers/passport.js"
    click AvatarController "https://github.com/drockparashar/snippetcove/blob/main/server/controllers/avatar.js"
    click UsersController "https://github.com/drockparashar/snippetcove/blob/main/server/controllers/users.js"
    click SnippetsController "https://github.com/drockparashar/snippetcove/blob/main/server/controllers/snippets.js"
    click UtilsController "https://github.com/drockparashar/snippetcove/blob/main/server/controllers/utils.js"
    click AuthRoutes "https://github.com/drockparashar/snippetcove/blob/main/server/routes/authRoutes.js"
    click GitHubAuth "https://github.com/drockparashar/snippetcove/blob/main/server/routes/githubAuth.js"
    click CheckAuth "https://github.com/drockparashar/snippetcove/blob/main/server/routes/checkAuth.js"
    click UsersRoutes "https://github.com/drockparashar/snippetcove/blob/main/server/routes/users.js"
    click SnippetsRoutes "https://github.com/drockparashar/snippetcove/blob/main/server/routes/snippets.js"
    click UserModel "https://github.com/drockparashar/snippetcove/blob/main/server/models/User.js"
    click SnippetModel "https://github.com/drockparashar/snippetcove/blob/main/server/models/Snippet.js"
    click AuthMiddleware "https://github.com/drockparashar/snippetcove/blob/main/server/middlewares/auth.js"
    click SeedScript "https://github.com/drockparashar/snippetcove/blob/main/server/populate.js"
    click EnvExample "https://github.com/drockparashar/snippetcove/blob/main/server/.env.example"
    click EntriesJSON "https://github.com/drockparashar/snippetcove/blob/main/server/entries.json"

    %% Styles
    classDef frontend fill:#cfe2ff,stroke:#0366d6,stroke-width:1px
    classDef backend fill:#d1e7dd,stroke:#237346,stroke-width:1px
    classDef database fill:#ffe5b4,stroke:#b35900,stroke-width:1px
    classDef external fill:#e4d1f9,stroke:#6a0dad,stroke-width:1px
```
