How mouhamedbouzayan/mern-blogger works
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