# osw6858/tech-hub architecture

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

- Interactive diagram: https://gitdiagram.com/osw6858/tech-hub
- Repository: https://github.com/osw6858/tech-hub

## Overview

##### Project type and purpose
- This is a full-stack single-page application (SPA) template built with React (TypeScript, Vite) on the frontend and Firebase on the backend.
- It provides a blog platform for front-end developers, handling user authentication, post creation/editing, commenting, and real-time data storage.

##### File structure
- Top-level:
- public / index.html – the SPA entry point
- src/ – all application code
– App.tsx, main.tsx – React root and router setup
– components/ – reusable UI pieces (auth screens, cards, comments, modals, header/footer, post forms, etc.)
– hooks/ – custom React hooks for each feature domain (authHooks, postHooks, commentHooks, mypagehook)
– redux/ – ThemeSlice.ts and store.ts for global theme state
– routes/ – React Router configuration
– firebase/firebaseConfig.ts – Firebase initialization
– styles/ – theme and global styled-components
- Config/build files: vite.config.ts, tsconfig.json, package.json, .eslintrc.cjs
- CI/CD: .github/workflows/*.yml deploy to Firebase Hosting

##### README for insights
- Confirms tech stack: React, TypeScript, styled-components, react-router, react-query, Redux, axios, Vite, Firebase (Auth, Firestore).
- Describes main use cases: user signup/login, posting with images, commenting, password reset, personal “My Page,” and theming.

##### Main components and their interactions
a. Client SPA (Browser/React)
– UI layer: components/ folder
– Routing: react-router (src/routes)
– State management: Redux for theme; React Query (and custom hooks) for data fetching/caching
– Firebase SDK calls abstracted in hooks (e.g. loginHook.ts, addPostHook.ts)
b. Firebase backend
– Authentication (sign-up, login, password reset)
– Firestore database (posts, comments, user profiles)
– Hosting (serving the built SPA)
c. CI/CD pipeline
– GitHub Actions workflows that build the Vite app and deploy to Firebase Hosting on merges/pull requests

##### Architectural patterns and principles
- Component-based UI with clear segregation of concerns (auth, post, comment, common UI).
- Custom hooks to encapsulate side effects and API logic.
- React Query for asynchronous data fetching, caching, and synchronization with Firestore.
- Redux slice for predictable global state (theme) across the app.
- Vite as dev/build tool for fast HMR and optimized production bundles.
- Hosted as an SPA on Firebase with environment-driven config.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% React SPA Layer
    subgraph "React SPA" 
        direction TB
        UI["public/index.html"]:::frontend
        subgraph "Entry & Router"
            direction TB
            Main["src/main.tsx"]:::frontend
            App["src/App.tsx"]:::frontend
        end
        subgraph "Components & UI"
            direction TB
            Components["UI Components (src/components/)"]:::frontend
        end
        subgraph "Routing"
            direction TB
            Routing["src/routes/routes.tsx"]:::frontend
        end
        subgraph "State & Data"
            direction TB
            Redux["Redux Store (src/redux/store.ts)"]:::state
            Hooks["React Query & Hooks (src/hooks/)"]:::state
        end
        subgraph "Config & Styles"
            direction TB
            FirebaseConf["Firebase Config (src/firebase/firebaseConfig.ts)"]:::state
            Styles["Styles & Theming (src/styles/)"]:::state
        end
    end

    %% Firebase Backend
    subgraph "Firebase" 
        direction TB
        Auth["Firebase Auth"]:::backend
        Firestore["Firestore DB"]:::backend
        Hosting["Firebase Hosting"]:::backend
    end

    %% CI/CD Pipeline
    CI["GitHub Actions"]:::ci

    %% Runtime Data Flows
    UI -->|"Loads SPA"| Main
    Main -->|"Renders App"| App
    App -->|"Routes via React Router"| Routing
    App -->|"Renders UI"| Components
    Components -->|"Calls Hooks/React Query"| Hooks
    Hooks -->|"Auth Requests via Firebase SDK"| Auth
    Hooks -->|"DB Operations via Firebase SDK"| Firestore
    Redux -->|"Theme State"| Components

    %% CI/CD Flow
    CI -.->|"deploy via firebase-tools"| Hosting

    %% Click Events
    click UI "https://github.com/osw6858/tech-hub/blob/main/public/index.html"
    click Main "https://github.com/osw6858/tech-hub/blob/main/src/main.tsx"
    click App "https://github.com/osw6858/tech-hub/blob/main/src/App.tsx"
    click Components "https://github.com/osw6858/tech-hub/tree/main/src/components/"
    click Routing "https://github.com/osw6858/tech-hub/blob/main/src/routes/routes.tsx"
    click Redux "https://github.com/osw6858/tech-hub/blob/main/src/redux/store.ts"
    click Hooks "https://github.com/osw6858/tech-hub/tree/main/src/hooks/"
    click FirebaseConf "https://github.com/osw6858/tech-hub/blob/main/src/firebase/firebaseConfig.ts"
    click Styles "https://github.com/osw6858/tech-hub/tree/main/src/styles/"

    %% Styles
    classDef frontend fill:#D0E7FF,stroke:#0366d6,color:#0366d6;
    classDef state fill:#FFD8A8,stroke:#D97706,color:#92400E;
    classDef backend fill:#FFF2CC,stroke:#D4B106,color:#a16207;
    classDef ci fill:#D4F8C4,stroke:#059669,color:#065f46;
```
