# abdulahadsiddiqui11/cacta architecture

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

- Interactive diagram: https://gitdiagram.com/abdulahadsiddiqui11/cacta
- Repository: https://github.com/abdulahadsiddiqui11/cacta

## Overview

##### Project Type & Purpose
- Cacta is a full-stack modern social media application built with Next.js and React on the frontend, using Tailwind CSS for styling and TypeScript for type safety.
- The backend uses Next.js API endpoints combined with a Sanity datastore (configured in the “cacta-backend” folder) to manage the content, user data, and video-related schemas.
- The platform integrates external services such as Google OAuth for authentication.

##### Analyzing the File Structure
- Top-level Directories:
- “pages”: Contains Next.js pages and API endpoint routes (e.g., authentication, posts, profiles, search, like, etc.), representing the core interactions and routing.
- “components”: Holds UI components (Navbar, Sidebar, VideoCard, etc.), forming the building blocks of the frontend.
- “cacta-backend”: Contains configuration, Sanity schemas (for posts, users, comments etc.), and plugins which define the CMS part of the application.
- “store”: Contains state management (using Zustand) for authentication and other global states.
- “lib” and “utils”: Utility functions and middleware, which support both frontend and API endpoints.
- Configuration files such as “next.config.js”, “tailwind.config.js”, and “tsconfig.json” indicate standard Next.js setup and TypeScript usage.
- Dependencies on Sanity for the backend are highlighted in the “cacta-backend” directory through schema definitions and plugin configuration.

##### Key System Components & Their Interactions
a. Frontend:
- Pages: Located under “pages” (e.g., home, detail, profile, search, upload).
- Components: Individual React components for UI elements like Navbar, VideoCard, and Sidebar.
- State Management: The “store” folder using Zustand to mediate state changes (e.g., authentication state).
- Utilities: “utils” and “lib” folders that manage API client calls, helper functions, and middleware.
b. Backend:
- API Endpoints: Endpoints under “pages/api” for handling authentication, posts, profiles, likes, and searches. These endpoints receive requests from the frontend, process data, and interact with the datastore.
- Sanity CMS: The “cacta-backend” folder holds the configuration and schema definitions to structure, validate, and store video content and user interactions.
c. External Services:
- Google OAuth: Integrated via API endpoints for authentication using Google Identity Services.
- Hosting/Deployment: References to Vercel hint at the deployment platform.
d. Relationships/Interactions:
- The user interacts with the frontend, which calls API endpoints for data (such as posts, comments, likes).
- API endpoints then interact with the Sanity datastore (managed within “cacta-backend”) or with independent internal logic (through utilities) to process and serve data.
- Authentication requests are exclusively routed through API endpoints that communicate with Google’s OAuth service.

##### Architectural Patterns & Design Principles
- Next.js-driven architecture that separates the application into distinct pages and API routes (serverless functions).
- Component-based design for the UI with clear separation between UI components and application state management.
- The use of Sanity as a headless CMS for backend content management introduces a decoupled data storage mechanism.
- A layered approach where the frontend presentation, business logic (in API endpoints/utilities), and data layer (Sanity) interact in a clear command-response pattern.

##### Elements
- Clear labels: Each module (e.g., “Next.js Frontend”, “API Endpoints”, “Sanity CMS”, “Google OAuth Service”).
- From “User” (represented perhaps as a chibi-style character) to “Frontend” pages.
- From “Frontend” to various “API Endpoints” (auth, posts, search, likes).
- From “API Endpoints” to the “Sanity CMS” backend where data is stored and managed.
- Communication with external services like Google OAuth.
- Backend components (more technical or subdued tones with anime “tech” motifs),
- Annotations to note primary technologies:
- Technologies like Next.js, React, TailwindCSS, and TypeScript on the frontend.
- Use of Sanity for CMS including key files (schemas, plugins) from “cacta-backend”.
- Use annotations to show the integration with Google Identity Services.
- Incorporate anime-themed visuals:

- Lay out the Frontend block (detailing Pages, Components, Store, Utilities), the Backend block (API endpoints and Sanity configuration), and External Services blocks.
- Review the structure for accuracy, clarity, and detail: each file/directory grouping should be represented as part of the larger application architecture with dynamic interactions depicted clearly.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Node
    U["User (Chibi)"]:::userClass

    %% Frontend Layer (Anime Hero UI)
    subgraph "Frontend Layer (Anime Hero UI)"
        direction TB
        %% Frontend Pages
        subgraph "Next.js Pages"
            homePage["Home Page"]:::frontendClass
            detailPage["Detail Page"]:::frontendClass
            profilePage["Profile Page"]:::frontendClass
            searchPage["Search Page"]:::frontendClass
            uploadPage["Upload Page"]:::frontendClass
        end

        %% UI Components
        subgraph "UI Components"
            navbar["Navbar"]:::frontendClass
            videoCard["VideoCard"]:::frontendClass
            sidebar["Sidebar"]:::frontendClass
        end

        %% State Management
        subgraph "State Management"
            authStore["Auth Store"]:::frontendClass
        end

        %% Utility Functions
        subgraph "Utilities & Middleware"
            clientUtil["client.ts"]:::frontendClass
            constantsUtil["constants.tsx"]:::frontendClass
            helperUtil["helperFunctions.ts"]:::frontendClass
            corsUtil["cors.ts"]:::frontendClass
            initMiddlewareUtil["init-middleware.ts"]:::frontendClass
        end
    end

    %% Backend Layer (API & CMS - Anime Control Panel)
    subgraph "Backend Layer (API & CMS - Anime Control Panel)"
        direction TB
        %% API Endpoints
        subgraph "API Endpoints"
            apiAuth["Auth API"]:::backendClass
            apiPost["Post API"]:::backendClass
            apiSearch["Search API"]:::backendClass
        end

        %% Sanity CMS Configuration & Schemas
        subgraph "Sanity CMS"
            sanitySchemas["Sanity Schemas"]:::backendClass
            sanityConfig["Sanity Config"]:::backendClass
        end
    end

    %% External Services (Magical Gateways)
    subgraph "External Services (Magical Gateways)"
        direction TB
        googleOAuth["Google OAuth Service"]:::externalClass
        vercel["Vercel Deployment"]:::externalClass
    end

    %% Connections
    U -->|"interacts"| homePage
    homePage -->|"navigates"| detailPage
    homePage -->|"navigates"| profilePage
    homePage -->|"navigates"| searchPage
    homePage -->|"navigates"| uploadPage

    %% UI Components linked with Pages (for layout illustrative purposes)
    detailPage -->|"displays"| navbar
    navbar -->|"controls"| videoCard
    videoCard -->|"organizes"| sidebar
    sidebar -->|"updates state"| authStore
    authStore -->|"calls"| clientUtil
    clientUtil -->|"uses"| constantsUtil
    constantsUtil -->|"assists"| helperUtil
    helperUtil -->|"integrates"| corsUtil
    corsUtil -->|"initializes"| initMiddlewareUtil

    %% Frontend to Backend: API call flow
    uploadPage -->|"submits data"| apiAuth
    navbar -->|"fetches data"| apiPost
    searchPage -->|"queries"| apiSearch

    %% Backend: API endpoints call Sanity CMS
    apiAuth -->|"reads/writes"| sanitySchemas
    apiPost -->|"reads/writes"| sanitySchemas
    apiSearch -->|"reads"| sanitySchemas
    sanitySchemas -->|"configured by"| sanityConfig

    %% API authentication via external service
    apiAuth -->|"authenticates with"| googleOAuth

    %% Deployment arrows to Vercel
    U ---|"hosted on"| vercel
    initMiddlewareUtil ---|"hosted on"| vercel
    apiAuth ---|"hosted on"| vercel
    sanityConfig ---|"hosted on"| vercel

    %% Click Events for Frontend Pages
    click homePage "https://github.com/abdulahadsiddiqui11/cacta/blob/main/pages/index.tsx"
    click detailPage "https://github.com/abdulahadsiddiqui11/cacta/blob/main/pages/detail/[id].tsx"
    click profilePage "https://github.com/abdulahadsiddiqui11/cacta/blob/main/pages/profile/[id].tsx"
    click searchPage "https://github.com/abdulahadsiddiqui11/cacta/blob/main/pages/search/[searchTerm].tsx"
    click uploadPage "https://github.com/abdulahadsiddiqui11/cacta/blob/main/pages/upload.tsx"

    %% Click Events for UI Components
    click navbar "https://github.com/abdulahadsiddiqui11/cacta/blob/main/components/Navbar.tsx"
    click videoCard "https://github.com/abdulahadsiddiqui11/cacta/blob/main/components/VideoCard.tsx"
    click sidebar "https://github.com/abdulahadsiddiqui11/cacta/blob/main/components/Sidebar.tsx"

    %% Click Event for State Management
    click authStore "https://github.com/abdulahadsiddiqui11/cacta/blob/main/store/authStore.ts"

    %% Click Events for Utility Functions
    click clientUtil "https://github.com/abdulahadsiddiqui11/cacta/blob/main/utils/client.ts"
    click constantsUtil "https://github.com/abdulahadsiddiqui11/cacta/blob/main/utils/constants.tsx"
    click helperUtil "https://github.com/abdulahadsiddiqui11/cacta/blob/main/utils/helperFunctions.ts"
    click corsUtil "https://github.com/abdulahadsiddiqui11/cacta/blob/main/lib/cors.ts"
    click initMiddlewareUtil "https://github.com/abdulahadsiddiqui11/cacta/blob/main/lib/init-middleware.ts"

    %% Click Events for API Endpoints
    click apiAuth "https://github.com/abdulahadsiddiqui11/cacta/blob/main/pages/api/auth.ts"
    click apiPost "https://github.com/abdulahadsiddiqui11/cacta/blob/main/pages/api/post/index.ts"
    click apiSearch "https://github.com/abdulahadsiddiqui11/cacta/blob/main/pages/api/search/[searchTerm].ts"

    %% Click Events for Sanity CMS
    click sanitySchemas "https://github.com/abdulahadsiddiqui11/cacta/tree/main/cacta-backend/schemas"
    click sanityConfig "https://github.com/abdulahadsiddiqui11/cacta/tree/main/cacta-backend/config"

    %% Class Definitions for Anime Theme Colors
    classDef userClass fill:#FFFACD,stroke:#FFCC00,stroke-width:2px
    classDef frontendClass fill:#FFD1DC,stroke:#FF6699,stroke-width:2px
    classDef backendClass fill:#D1E8FF,stroke:#3399FF,stroke-width:2px
    classDef externalClass fill:#D1FFD1,stroke:#33CC33,stroke-width:2px
```
