# mouhamedbouzayan/mern-blogger architecture

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

- Interactive diagram: https://gitdiagram.com/mouhamedbouzayan/mern-blogger
- Repository: https://github.com/mouhamedbouzayan/mern-blogger

## Overview

##### Project Type & Purpose
- This is a front-end SPA built in React (Vite), styled with TailwindCSS, using RxJS for state streams and JSON Server as a mock REST API.
- Purpose: allow users to create/read/update/delete blog articles, comment, filter/search, and authenticate.

##### File Structure
- Top level: `.gitignore`, `README.md`, plus a single `Client/` folder.
- Client/ contains:
- standard React structure under `src/`:
– `api/`: axios-based services (articleService, authService, categoryService, commentService)
– `components/`: reusable UI pieces (ArticleCard, Layout, Navbar, ToastWrapper, etc.)
– `pages/`: route targets (Home, Login, Register, ArticleList, ArticleDetail, Create/Edit pages)
– `hooks/`: custom hooks wrapping API calls & RxJS streams (useAuth, useArticles, etc.)
– `utils/`: validators;
- `public/`, config files (eslint, tailwind, postcss, Vite).

##### Key Architecture from README
UI Composants → Services API → JSON Server
UI Composants → Custom Hooks → RxJS Streams → State Management
UI Composants → Formik/Yup
Services API → Axios

##### Main Components
a. Frontend (Browser):
- React UI Layer
- Pages (routing)
- Components
- Formik/Yup forms
- State & Data Layer
- Custom Hooks
- RxJS streams for global state
b. Service Layer:
- Axios-based API Services
- HTTP requests (GET/POST/PUT/DELETE)
c. Mock Backend:
- JSON Server serving `db.json`
d. Dev/Build Tools (optional):
- Vite dev server, Tailwind build

##### Relationships & Data Flows
- User interacts with UI Components → triggers Forms or Buttons
- UI calls Custom Hook (e.g. `useArticles()`) → Hook uses RxJS to emit/subscribe to streams → invokes corresponding API Service
- API Service (Axios) → issues HTTP call → JSON Server responds with JSON → Service resolves promise → Hook pushes new value into RxJS stream → UI re-renders with updated state
- Authentication: Login/Register pages call `authService` → server returns JWT or session token (stored in memory or localStorage) → attached to further requests
- Filtering/Search: UI sends query params via categoryService or articleService → server filters from `db.json`

##### Architectural Patterns & Principles
- Separation of concerns:
- UI vs. Data fetching vs. State management
- Reactive streams (RxJS) as single source of truth
- Service abstraction over raw HTTP
- Component composition for reuse
- Form handling via Formik + Yup validation

##### Detailed Component Breakdown (optional call-out)
- In Services: list each `.js` service file
- In Hooks: show hook names and point to RxJS streams

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "Frontend (Browser)"
    direction TB
    Pages["UI Pages"]:::ui
    Components["Shared Components"]:::ui
    Validators["Form Handling (Formik/Yup)"]:::ui
  end

  subgraph "State & Data Layer"
    direction TB
    HooksArticles["useArticles Hook"]:::state
    HooksAuth["useAuth Hook"]:::state
    HooksCategories["useCategories Hook"]:::state
    HooksComments["useComments Hook"]:::state
    Streams["RxJS Streams"]:::state
  end

  subgraph "Service Layer (API Services)"
    direction TB
    ArticleService["ArticleService (Axios)"]:::service
    AuthService["AuthService (Axios)"]:::service
    CategoryService["CategoryService (Axios)"]:::service
    CommentService["CommentService (Axios)"]:::service
  end

  Backend["JSON Server (db.json)"]:::backend

  subgraph "Dev & Build Tools"
    direction TB
    Vite["Vite Config"]:::dev
    Tailwind["Tailwind Config"]:::dev
  end

  %% UI to Hooks
  Pages -->|"calls"| HooksArticles
  Pages -->|"calls"| HooksAuth
  Pages -->|"calls"| HooksCategories
  Pages -->|"calls"| HooksComments
  Components -->|"calls"| HooksArticles
  Components -->|"calls"| HooksAuth
  Components -->|"calls"| HooksCategories
  Components -->|"calls"| HooksComments

  %% Hooks to Streams & Services
  HooksArticles -->|"subscribes"| Streams
  HooksAuth -->|"subscribes"| Streams
  HooksCategories -->|"subscribes"| Streams
  HooksComments -->|"subscribes"| Streams

  HooksArticles -->|"calls API"| ArticleService
  HooksAuth -->|"calls API"| AuthService
  HooksCategories -->|"calls API"| CategoryService
  HooksComments -->|"calls API"| CommentService

  %% Services to Backend
  ArticleService -->|"HTTP"| Backend
  AuthService -->|"HTTP"| Backend
  CategoryService -->|"HTTP"| Backend
  CommentService -->|"HTTP"| Backend

  %% Dev Tools influences Frontend
  Vite -->|"build/dev"| Pages
  Tailwind -->|"styles"| Components

  %% Click Events
  click Pages "https://github.com/mouhamedbouzayan/mern-blogger/tree/main/Client/src/pages"
  click Components "https://github.com/mouhamedbouzayan/mern-blogger/tree/main/Client/src/components"
  click Validators "https://github.com/mouhamedbouzayan/mern-blogger/blob/main/Client/src/utils/validators.js"
  click HooksArticles "https://github.com/mouhamedbouzayan/mern-blogger/blob/main/Client/src/hooks/useArticles.js"
  click HooksAuth "https://github.com/mouhamedbouzayan/mern-blogger/blob/main/Client/src/hooks/useAuth.js"
  click HooksCategories "https://github.com/mouhamedbouzayan/mern-blogger/blob/main/Client/src/hooks/useCategories.js"
  click HooksComments "https://github.com/mouhamedbouzayan/mern-blogger/blob/main/Client/src/hooks/useComments.js"
  click ArticleService "https://github.com/mouhamedbouzayan/mern-blogger/blob/main/Client/src/api/articleService.js"
  click AuthService "https://github.com/mouhamedbouzayan/mern-blogger/blob/main/Client/src/api/authService.js"
  click CategoryService "https://github.com/mouhamedbouzayan/mern-blogger/blob/main/Client/src/api/categoryService.js"
  click CommentService "https://github.com/mouhamedbouzayan/mern-blogger/blob/main/Client/src/api/commentService.js"
  click Backend "https://github.com/mouhamedbouzayan/mern-blogger/blob/main/Client/db.json"
  click Vite "https://github.com/mouhamedbouzayan/mern-blogger/blob/main/Client/vite.config.js"
  click Tailwind "https://github.com/mouhamedbouzayan/mern-blogger/blob/main/Client/tailwind.config.js"

  classDef ui fill:#bbdefb,stroke:#1e88e5,color:#0d47a1;
  classDef state fill:#c8e6c9,stroke:#43a047,color:#1b5e20;
  classDef service fill:#ffe0b2,stroke:#fb8c00,color:#e65100;
  classDef backend fill:#e0e0e0,stroke:#9e9e9e,color:#424242;
  classDef dev fill:#f3e5f5,stroke:#ab47bc,color:#4a148c;
```
