# amay-git101/bloghub architecture

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

- Interactive diagram: https://gitdiagram.com/amay-git101/bloghub
- Repository: https://github.com/amay-git101/bloghub

## Overview

##### Project type and purpose
- This is a browser-based Single-Page Application (SPA) built with Vite, TypeScript, React, Tailwind CSS and shadcn-ui.
- It relies on Firebase (Auth + Firestore) as its backend (BaaS).
- Deployment is handled by Lovable.dev (effectively a static file host + CDN).

##### File structure
- src/pages: top-level routes (Auth, Landing, Index, Post, CreatePost, Profile, Bookmarks, NotFound).
- src/components: reusable UI and layout primitives, plus domain-specific components (BlogCard, CommentsSection, etc.).
- src/contexts/AuthContext.tsx: global auth state.
- src/hooks: encapsulated data-fetching hooks (useBlogPosts, useBookmarks, useComments).
- src/firebase.ts: Firebase SDK initialization and exports.
- config files (vite.config.ts, tailwind.config.ts, tsconfigs): build and type settings.

##### README for additional insights
- Tech stack is purely front-end with Firebase as a service.
- No custom backend code—data flows directly from the browser to Firebase.

##### Main components and their interactions
a. Browser / Client
- Entry point (main.tsx) mounts <App> into index.html.
- React Router (via page components) handles navigation.
b. UI Layer
- Domain components (in src/components/) assemble pages.
- UI primitives (src/components/ui/) form a design system.
c. State & Business Logic
- AuthContext provides user info and login/logout.
- Hooks call Firebase SDK to read/write posts, comments, bookmarks.
d. External Services
- Firebase Authentication (login, signup, session)
- Firebase Firestore (collections: posts, comments, bookmarks, profiles)
e. Deployment / Hosting
- Vite builds a static bundle (JS/CSS/assets).
- Lovable.dev (or equivalent CDN) serves index.html and assets.
- Browser fetches static files, then all data calls go to Firebase endpoints.

##### Relationships and data flow
- User’s browser loads static assets from CDN →
React App initializes →
AuthContext checks Firebase Auth →
Pages/hooks issue real-time listeners or REST calls to Firestore →
UI components render data →
User actions (create comment, bookmark) call Firebase SDK to update DB →
Firestore triggers real-time updates back to hooks →
UI updates automatically.

##### Architectural patterns & design principles
- Component-based UI (atomic UI primitives + composite domain components)
- Separation of concerns:
- UI components
- Contexts (cross-cutting state)
- Hooks (data access / side effects)
- Firebase SDK (data layer)
- Single responsibility: each hook or component focuses on one piece of logic/UI.

##### Must-include elements
- “Browser / React App”
- “Component Layer”
- “Context & Hooks Layer”
- “Firebase SDK”
- “Firebase Auth” & “Firebase Firestore”
- “Static Hosting / CDN”

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Deployment / Hosting"
    CDN["Static Hosting / CDN\n(via Lovable.dev)"]:::deployment
  end

  CDN -->|"Serves static assets"| Browser["Browser"]:::browser

  subgraph "Browser / React App"
    main["main.tsx"]:::app
    App["App.tsx"]:::app
    Router["React Router\n(src/pages)"]:::app
    main --> App
    App --> Router
  end

  Browser --> Router

  subgraph "UI Layer"
    subgraph "Pages (src/pages)"
      Auth["Auth.tsx"]:::uiPages
      Landing["Landing.tsx"]:::uiPages
      Index["Index.tsx"]:::uiPages
      Post["Post.tsx"]:::uiPages
      CreatePost["CreatePost.tsx"]:::uiPages
      Profile["Profile.tsx"]:::uiPages
      PublicProfile["PublicProfile.tsx"]:::uiPages
      Bookmarks["Bookmarks.tsx"]:::uiPages
      NotFound["NotFound.tsx"]:::uiPages
    end

    subgraph "Domain Components (src/components)"
      BlogCard["BlogCard.tsx"]:::uiComponents
      BlogList["BlogList.tsx"]:::uiComponents
      BlogView["BlogView.tsx"]:::uiComponents
      BlogForm["BlogForm.tsx"]:::uiComponents
      BlogHeader["BlogHeader.tsx"]:::uiComponents
      CommentsSection["CommentsSection.tsx"]:::uiComponents
      CommentItem["CommentItem.tsx"]:::uiComponents
      ProfileCompletionRoute["ProfileCompletionRoute.tsx"]:::uiComponents
      ProtectedRoute["ProtectedRoute.tsx"]:::uiComponents
      RedirectIfAuth["RedirectIfAuth.tsx"]:::uiComponents
      MainLayout["MainLayout.tsx"]:::uiComponents
    end

    subgraph "Design System Primitives\n(src/components/ui)"
      UIPrimitives["ui/*.tsx"]:::uiPrimitives
    end

    Router -->|renders| Auth
    Router --> Landing
    Router --> Index
    Router --> Post
    Router --> CreatePost
    Router --> Profile
    Router --> PublicProfile
    Router --> Bookmarks
    Router --> NotFound

    Auth & Landing & Index & Post & CreatePost & Profile & PublicProfile & Bookmarks & NotFound -->|use components| BlogCard
    Auth & Landing & Index & Post & CreatePost & Profile & PublicProfile & Bookmarks & NotFound --> BlogList
    Auth & Landing & Index & Post & CreatePost & Profile & PublicProfile & Bookmarks & NotFound --> BlogView
    Auth & Landing & Index & Post & CreatePost & Profile & PublicProfile & Bookmarks & NotFound --> BlogForm
    Auth & Landing & Index & Post & CreatePost & Profile & PublicProfile & Bookmarks & NotFound --> BlogHeader
    Auth & Landing & Index & Post & CreatePost & Profile & PublicProfile & Bookmarks & NotFound --> CommentsSection
    Auth & Landing & Index & Post & CreatePost & Profile & PublicProfile & Bookmarks & NotFound --> CommentItem
    Auth & Landing & Index & Post & CreatePost & Profile & PublicProfile & Bookmarks & NotFound --> ProfileCompletionRoute
    Auth & Landing & Index & Post & CreatePost & Profile & PublicProfile & Bookmarks & NotFound --> ProtectedRoute
    Auth & Landing & Index & Post & CreatePost & Profile & PublicProfile & Bookmarks & NotFound --> RedirectIfAuth
    Auth & Landing & Index & Post & CreatePost & Profile & PublicProfile & Bookmarks & NotFound --> MainLayout

    BlogCard & BlogList & BlogView & BlogForm & BlogHeader & CommentsSection & CommentItem & ProfileCompletionRoute & ProtectedRoute & RedirectIfAuth & MainLayout --> UIPrimitives
  end

  subgraph "State & Business Logic"
    AuthContext["AuthContext.tsx"]:::state
    subgraph "Hooks (src/hooks)"
      useBlogPosts["useBlogPosts.ts"]:::state
      useBookmarks["useBookmarks.ts"]:::state
      useToast["use-toast.ts"]:::state
      useMobile["use-mobile.tsx"]:::state
    end
    UIPrimitives & BlogCard & BlogList & BlogView & BlogForm & BlogHeader & CommentsSection & CommentItem & ProfileCompletionRoute & ProtectedRoute & RedirectIfAuth & MainLayout --> AuthContext
    UIPrimitives & BlogCard & BlogList & BlogView & BlogForm & BlogHeader & CommentsSection & CommentItem & ProfileCompletionRoute & ProtectedRoute & RedirectIfAuth & MainLayout --> useBlogPosts
    UIPrimitives & BlogCard & BlogList & BlogView & BlogForm & BlogHeader & CommentsSection & CommentItem & ProfileCompletionRoute & ProtectedRoute & RedirectIfAuth & MainLayout --> useBookmarks
    UIPrimitives & BlogCard & BlogList & BlogView & BlogForm & BlogHeader & CommentsSection & CommentItem & ProfileCompletionRoute & ProtectedRoute & RedirectIfAuth & MainLayout --> useToast
    UIPrimitives & BlogCard & BlogList & BlogView & BlogForm & BlogHeader & CommentsSection & CommentItem & ProfileCompletionRoute & ProtectedRoute & RedirectIfAuth & MainLayout --> useMobile
  end

  subgraph "Data Layer"
    FirebaseSDK["firebase.ts\n(Firebase SDK Init)"]:::data
    AuthContext & useBlogPosts & useBookmarks & useToast & useMobile --> FirebaseSDK
  end

  subgraph "External Services"
    AuthService["Firebase Auth"]:::external
    Firestore["Firebase Firestore"]:::external
    FirebaseSDK -->|"signInWithEmailAndPassword"| AuthService
    FirebaseSDK -->|"get/post docs"| Firestore
    Firestore -->|"onSnapshot (real-time)"| FirebaseSDK
  end

  %% Click Events
  click main "https://github.com/amay-git101/bloghub/blob/main/src/main.tsx"
  click App "https://github.com/amay-git101/bloghub/blob/main/src/App.tsx"
  click Auth "https://github.com/amay-git101/bloghub/blob/main/src/pages/Auth.tsx"
  click Landing "https://github.com/amay-git101/bloghub/blob/main/src/pages/Landing.tsx"
  click Index "https://github.com/amay-git101/bloghub/blob/main/src/pages/Index.tsx"
  click Post "https://github.com/amay-git101/bloghub/blob/main/src/pages/Post.tsx"
  click CreatePost "https://github.com/amay-git101/bloghub/blob/main/src/pages/CreatePost.tsx"
  click Profile "https://github.com/amay-git101/bloghub/blob/main/src/pages/Profile.tsx"
  click PublicProfile "https://github.com/amay-git101/bloghub/blob/main/src/pages/PublicProfile.tsx"
  click Bookmarks "https://github.com/amay-git101/bloghub/blob/main/src/pages/Bookmarks.tsx"
  click NotFound "https://github.com/amay-git101/bloghub/blob/main/src/pages/NotFound.tsx"
  click BlogCard "https://github.com/amay-git101/bloghub/blob/main/src/components/BlogCard.tsx"
  click BlogList "https://github.com/amay-git101/bloghub/blob/main/src/components/BlogList.tsx"
  click BlogView "https://github.com/amay-git101/bloghub/blob/main/src/components/BlogView.tsx"
  click BlogForm "https://github.com/amay-git101/bloghub/blob/main/src/components/BlogForm.tsx"
  click BlogHeader "https://github.com/amay-git101/bloghub/blob/main/src/components/BlogHeader.tsx"
  click CommentsSection "https://github.com/amay-git101/bloghub/blob/main/src/components/CommentsSection.tsx"
  click CommentItem "https://github.com/amay-git101/bloghub/blob/main/src/components/CommentItem.tsx"
  click ProfileCompletionRoute "https://github.com/amay-git101/bloghub/blob/main/src/components/ProfileCompletionRoute.tsx"
  click ProtectedRoute "https://github.com/amay-git101/bloghub/blob/main/src/components/ProtectedRoute.tsx"
  click RedirectIfAuth "https://github.com/amay-git101/bloghub/blob/main/src/components/RedirectIfAuth.tsx"
  click MainLayout "https://github.com/amay-git101/bloghub/blob/main/src/components/MainLayout.tsx"
  click UIPrimitives "https://github.com/amay-git101/bloghub/tree/main/src/components/ui"
  click AuthContext "https://github.com/amay-git101/bloghub/blob/main/src/contexts/AuthContext.tsx"
  click useBlogPosts "https://github.com/amay-git101/bloghub/blob/main/src/hooks/useBlogPosts.ts"
  click useBookmarks "https://github.com/amay-git101/bloghub/blob/main/src/hooks/useBookmarks.ts"
  click useToast "https://github.com/amay-git101/bloghub/blob/main/src/hooks/use-toast.ts"
  click useMobile "https://github.com/amay-git101/bloghub/blob/main/src/hooks/use-mobile.tsx"
  click FirebaseSDK "https://github.com/amay-git101/bloghub/blob/main/src/firebase.ts"

  %% Styles
  classDef deployment fill:#D8BFD8,stroke:#946DAD,color:#000
  classDef browser fill:#E0FFFF,stroke:#20B2AA,color:#000
  classDef app fill:#ADD8E6,stroke:#1E90FF,color:#000
  classDef uiPages fill:#B0E0E6,stroke:#4682B4,color:#000
  classDef uiComponents fill:#87CEFA,stroke:#1E90FF,color:#000
  classDef uiPrimitives fill:#AFEEEE,stroke:#20B2AA,color:#000
  classDef state fill:#98FB98,stroke:#2E8B57,color:#000
  classDef data fill:#E0FFFF,stroke:#5F9EA0,color:#000
  classDef external fill:#FFE4B5,stroke:#FF8C00,color:#000
```
