# abhi13-02/haxplore architecture

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

- Interactive diagram: https://gitdiagram.com/abhi13-02/haxplore
- Repository: https://github.com/abhi13-02/haxplore

## Overview

##### Project type and purpose
- SynapseCode is a full-stack, web-based code-editing and collaboration platform.
- Frontend: Next.js 15 with the new App Router, Shadcn UI components, Tailwind CSS, and Monaco Editor for code editing.
- Backend & real-time: Firebase Authentication, Realtime Database (and optional Firestore), plus serverless API routes in Next.js.
- AI: Google Gemini API for auto-completion, linting, documentation generation, and an embedded chatbot.

##### File structure
A. Top-level files & configs
- next.config.mjs, jsconfig.json, postcss.config.mjs, tailwind.config.mjs → Next.js + Tailwind setup
- package.json, package-lock.json → dependency management
- cat.js, components.json → metadata or side-scripts
B. Public/static
C. Source code under /src
1. /src/app → Next.js App Router
– /api/…/route.js → serverless endpoints:
- auto-complete, generate-documentation, get-errors, getChatResponse, send-email
– pages: dashboard, login, register, profile, workspace/[workspaceId]
– layout.js, globals.css
2. /src/components → React UI components
– Chat, Editor (Monaco), Header, Home, Members, Navpanel, LiveCursor, InviteNotification, etc.
– /ui → Shadcn-style primitives (button, card, dialog, input, etc.)
3. /src/config/firebase.js → Firebase initialization (Auth & Realtime DB)
4. /src/context/AuthProvider.js → React context for user session
5. /src/helpers → client-side helpers (loginHelp, signUpHelp, logoutHelp, sendVerificationEmail)
6. /src/lib/utils.js → shared utility functions
7. /src/constants.js → magic strings, API endpoints, config values

##### README insights
- Real-time sync via Firebase Realtime Database + snapshot listeners
- Authentication: Google OAuth & email/OTP
- AI integration: Google Gemini for suggestions, linting, auto-docs, code correction
- Collaboration: live cursor tracking, workspace chat, invitations
- Recursive file tree navigation component

a. Main components
- Web Client (Next.js App)
– UI Layer: Shadcn UI, Tailwind, React Context
– Monaco Editor + Collaboration overlays (cursors, chat)
– Navpanel (recursive folder tree)
- API Layer (Next.js serverless routes)
– auto-complete, generate-documentation, get-errors, getChatResponse, send-email
- Real-time Backend
– Firebase Authentication
– Firebase Realtime Database (code, file structure, cursor positions, chat messages)
– (Optional) Firestore if used for any storage
- AI Services
– Google Gemini API
– AI Chatbot microservice (could be same serverless or separate)
- External Services
– Email provider (via send-email endpoint)
– Google OAuth

b. Relationships & interactions
1. Client reads/writes user data & session → Firebase Auth
2. Editor events (typing, file operations) → Realtime Database updates → snapshot listeners push to all clients
3. API calls from client → Next.js serverless routes → either call Google Gemini or Firebase or email service → return JSON
4. Chat messages/ cursor positions → Realtime DB → broadcast
5. AI suggestions → Google Gemini → route.js → client

c. Architectural patterns & design principles
- Serverless micro-endpoints for AI features & email
- Real-time pub/sub via Firebase snapshot listeners (event-driven)
- Component-based UI with design system (Shadcn UI)
- Separation of concerns: UI vs data layer vs AI service vs auth
- Recursive rendering pattern for file tree

d. Key technologies
- Next.js App Router & API Routes
- React Context for Auth & state
- Monaco Editor for code editing
- Firebase Auth + Realtime Database
- Google Gemini AI API
- Tailwind CSS & Shadcn UI

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Web Client Layer
    subgraph "Web Client (Next.js App)" 
        direction TB
        Layout["App Layout & Globals"]:::frontend
        Dashboard["Dashboard Page"]:::frontend
        Login["Login Page"]:::frontend
        Register["Register Page"]:::frontend
        Profile["Profile Page"]:::frontend
        Workspace["Workspace Page"]:::frontend
        subgraph "UI Components"
            direction TB
            Header["Header Component"]:::frontend
            Home["Home Component"]:::frontend
            Navpanel["Navigation Panel"]:::frontend
            Editor["Monaco Editor"]:::frontend
            Chat["Chat Component"]:::frontend
            LiveCursor["Live Cursor Overlay"]:::frontend
            InviteNotification["Invite Notification"]:::frontend
            Members["Members List"]:::frontend
            Output["Output Panel"]:::frontend
            Searchbar["Search Bar"]:::frontend
            LanguageSelector["Language Selector"]:::frontend
            subgraph "Shadcn UI Primitives"
                direction TB
                UIPrimitives["UI Primitives"]:::frontend
            end
        end
        subgraph "Config & Context & Utils"
            direction TB
            FirebaseConfig["Firebase Initialization"]:::frontend
            AuthContext["Authentication Context"]:::frontend
            Helpers["Client-side Helpers"]:::frontend
            Utils["Shared Utilities"]:::frontend
            Constants["Application Constants"]:::frontend
        end
    end

    %% Serverless API Layer
    subgraph "API Layer (Next.js Serverless Routes)"
        direction TB
        AC["auto-complete"]:::serverless
        GD["generate-documentation"]:::serverless
        GE["get-errors"]:::serverless
        GC["getChatResponse"]:::serverless
        SE["send-email"]:::serverless
    end

    %% Firebase Services
    subgraph "Firebase Services"
        direction TB
        Auth["Firebase Authentication"]:::firebase
        RTDB["Realtime Database"]:::firebase
    end

    %% AI Services
    subgraph "AI Services"
        direction TB
        Gemini["Google Gemini API"]:::ai
    end

    %% External Services
    subgraph "External Services"
        direction TB
        EmailProv["Email Provider"]:::external
        OAuth["Google OAuth"]:::external
    end

    %% Client to Auth
    Layout -->|uses| AuthContext
    AuthContext -->|connects to| Auth
    AuthContext -->|connects to| OAuth

    %% Client to Real-time
    Editor -->|updates| RTDB
    Navpanel -->|reads/writes| RTDB
    Chat -->|reads/writes| RTDB
    LiveCursor -->|publishes| RTDB
    InviteNotification -->|listens| RTDB
    Members -->|syncs| RTDB
    Output -->|logs| RTDB

    RTDB -->|snapshot listeners| Editor
    RTDB -->|broadcasts| Chat
    RTDB -->|broadcasts| LiveCursor
    RTDB -->|broadcasts| InviteNotification
    RTDB -->|broadcasts| Members

    %% Client to API
    Dashboard -->|POST /auto-complete| AC
    Workspace -->|POST /generate-documentation| GD
    Workspace -->|POST /get-errors| GE
    Chat -->|POST /getChatResponse| GC
    Register -->|POST /send-email| SE

    %% API to Services
    AC -->|calls| Gemini
    GD -->|calls| Gemini
    GE -->|calls| Gemini
    GC -->|calls| Gemini
    SE -->|calls| EmailProv

    %% Firebase Config usage
    FirebaseConfig -->|initializes| Auth
    FirebaseConfig -->|initializes| RTDB

    %% Click Events
    click Layout "https://github.com/abhi13-02/haxplore/blob/main/src/app/layout.js"
    click Dashboard "https://github.com/abhi13-02/haxplore/blob/main/src/app/dashboard/page.jsx"
    click Login "https://github.com/abhi13-02/haxplore/blob/main/src/app/login/page.jsx"
    click Register "https://github.com/abhi13-02/haxplore/blob/main/src/app/register/page.jsx"
    click Profile "https://github.com/abhi13-02/haxplore/blob/main/src/app/profile/page.jsx"
    click Workspace "https://github.com/abhi13-02/haxplore/blob/main/src/app/workspace/[workspaceId]/page.jsx"
    click AC "https://github.com/abhi13-02/haxplore/blob/main/src/app/api/auto-complete/route.js"
    click GD "https://github.com/abhi13-02/haxplore/blob/main/src/app/api/generate-documentation/route.js"
    click GE "https://github.com/abhi13-02/haxplore/blob/main/src/app/api/get-errors/route.js"
    click GC "https://github.com/abhi13-02/haxplore/blob/main/src/app/api/getChatResponse/route.js"
    click SE "https://github.com/abhi13-02/haxplore/blob/main/src/app/api/send-email/route.js"
    click FirebaseConfig "https://github.com/abhi13-02/haxplore/blob/main/src/config/firebase.js"
    click AuthContext "https://github.com/abhi13-02/haxplore/blob/main/src/context/AuthProvider.js"
    click Editor "https://github.com/abhi13-02/haxplore/blob/main/src/components/Editor.jsx"
    click Chat "https://github.com/abhi13-02/haxplore/blob/main/src/components/Chat.jsx"
    click LiveCursor "https://github.com/abhi13-02/haxplore/blob/main/src/components/LiveCursor.jsx"
    click InviteNotification "https://github.com/abhi13-02/haxplore/blob/main/src/components/InviteNotification.jsx"
    click Navpanel "https://github.com/abhi13-02/haxplore/blob/main/src/components/Navpanel.jsx"
    click Header "https://github.com/abhi13-02/haxplore/blob/main/src/components/Header.jsx"
    click Home "https://github.com/abhi13-02/haxplore/blob/main/src/components/Home.jsx"
    click Members "https://github.com/abhi13-02/haxplore/blob/main/src/components/Members.jsx"
    click Output "https://github.com/abhi13-02/haxplore/blob/main/src/components/Output.jsx"
    click Searchbar "https://github.com/abhi13-02/haxplore/blob/main/src/components/Searchbar.jsx"
    click LanguageSelector "https://github.com/abhi13-02/haxplore/blob/main/src/components/LanguageSelector.jsx"
    click UIPrimitives "https://github.com/abhi13-02/haxplore/tree/main/src/components/ui"
    click Helpers "https://github.com/abhi13-02/haxplore/tree/main/src/helpers"
    click Utils "https://github.com/abhi13-02/haxplore/blob/main/src/lib/utils.js"
    click Constants "https://github.com/abhi13-02/haxplore/blob/main/src/constants.js"

    %% Styles
    classDef frontend fill:#DDEEFF,stroke:#3399FF
    classDef serverless fill:#EEEEEE,stroke:#888888
    classDef firebase fill:#EEFFEE,stroke:#33AA33
    classDef ai fill:#FFEECC,stroke:#FF9933
    classDef external fill:#F0F0F0,stroke:#666666
```
