Skip to content

Latest commit

Β 

History

History
124 lines (116 loc) Β· 6.69 KB

File metadata and controls

124 lines (116 loc) Β· 6.69 KB

Project Structure – Blogify (Refactored)

This document reflects the current file organisation after the full refactoring (May 2026).

Backend (/backend)

backend/
β”œβ”€β”€ controllers/
β”‚ β”œβ”€β”€ authController.js # signup, login, getCurrentUser, updateSettings
β”‚ β”œβ”€β”€ postController.js # CRUD, like, getMyPosts, getAllPosts (with pagination)
β”‚ └── commentController.js # create, approve, reject, delete, like, reply
β”œβ”€β”€ middleware/
β”‚ β”œβ”€β”€ authMiddleware.js # auth (sets req.userId), optionalAuth
β”‚ β”œβ”€β”€ sanitizeBody.js # trims strings (kept, but will be replaced later)
β”‚ └── validate.js # handles express-validator errors
β”œβ”€β”€ models/
β”‚ β”œβ”€β”€ User.js # pre‑save hash, comparePassword method
β”‚ β”œβ”€β”€ Post.js # title, content, imageUrl, tags, category, author, likes, views, commentsCount
β”‚ └── Comment.js # author (string), content, post, status, likes, replies (subdocs)
β”œβ”€β”€ routes/
β”‚ β”œβ”€β”€ auth.js # /signup, /login, /me, /settings (with validation)
β”‚ β”œβ”€β”€ posts.js # GET (public), POST/PUT/DELETE (protected), /mine, /:id/like
β”‚ └── comments.js # GET (public), POST/PUT/DELETE (protected with admin checks)
β”œβ”€β”€ .env
β”œβ”€β”€ package.json
└── server.js # security middleware, rate limiting, global error handler, graceful shutdown

Frontend (/frontend)

frontend/
β”œβ”€β”€ public/ # static assets
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ components/
β”‚ β”‚ β”œβ”€β”€ auth/
β”‚ β”‚ β”‚ β”œβ”€β”€ ProtectedRoute.js # redirects to /signin if not authenticated
β”‚ β”‚ β”‚ └── index.js
β”‚ β”‚ β”œβ”€β”€ layout/
β”‚ β”‚ β”‚ β”œβ”€β”€ Header.js # shows user menu, logout, new post button
β”‚ β”‚ β”‚ β”œβ”€β”€ Sidebar.js # navigation links, collapsible
β”‚ β”‚ β”‚ β”œβ”€β”€ Layout.js # conditionally shows sidebar/header based on route & auth
β”‚ β”‚ β”‚ └── index.js
β”‚ β”‚ β”œβ”€β”€ modals/
β”‚ β”‚ β”‚ β”œβ”€β”€ NewPostModal.js # creates a post (uses API directly)
β”‚ β”‚ β”‚ β”œβ”€β”€ EditPostModal.js # edits a post (fetches via GET /posts/:id)
β”‚ β”‚ β”‚ β”œβ”€β”€ editPostModalStyles.js # style helpers
β”‚ β”‚ β”‚ └── index.js
β”‚ β”‚ β”œβ”€β”€ ui/ # reusable primitives
β”‚ β”‚ β”‚ β”œβ”€β”€ BlogCard.js # displays post card with actions
β”‚ β”‚ β”‚ β”œβ”€β”€ Button.js
β”‚ β”‚ β”‚ β”œβ”€β”€ Card.js
β”‚ β”‚ β”‚ β”œβ”€β”€ Input.js
β”‚ β”‚ β”‚ β”œβ”€β”€ LoadingSpinner.js
β”‚ β”‚ β”‚ β”œβ”€β”€ Typography.js
β”‚ β”‚ β”‚ └── index.js
β”‚ β”‚ β”œβ”€β”€ CommentCard.js # displays a single comment with replies, likes, moderation actions
β”‚ β”‚ β”œβ”€β”€ CommentFilter.js # filter buttons (all/pending/approved/spam)
β”‚ β”‚ β”œβ”€β”€ CommentForm.js # creates a comment (authenticated, uses API directly)
β”‚ β”‚ β”œβ”€β”€ CommentList.js # maps over comments, uses CommentCard
β”‚ β”‚ β”œβ”€β”€ CommentReplies.js # nested replies display
β”‚ β”‚ β”œβ”€β”€ CommentStats.js # stats cards (total, approved, pending, spam)
β”‚ β”‚ β”œβ”€β”€ ModerationActions.js # approve/reject/delete/reply buttons for admin
β”‚ β”‚ β”œβ”€β”€ ErrorBoundary.js # catches render errors
β”‚ β”‚ └── index.js # exports all components
β”‚ β”œβ”€β”€ contexts/
β”‚ β”‚ β”œβ”€β”€ UserContext.js # loads user from /auth/me, stores token in localStorage
β”‚ β”‚ β”œβ”€β”€ ThemeContext.js # theme, accent colour, font size – persisted in localStorage
β”‚ β”‚ └── SidebarContext.js # sidebar collapse / mobile open state
β”‚ β”œβ”€β”€ hooks/
β”‚ β”‚ β”œβ”€β”€ usePostStats.js # fetches /posts/mine, aggregates stats
β”‚ β”‚ └── useComments.js # fetches /comments with filter, provides moderation handlers
β”‚ β”œβ”€β”€ pages/
β”‚ β”‚ β”œβ”€β”€ auth/
β”‚ β”‚ β”‚ β”œβ”€β”€ Login.js # uses /auth/login, expects { token, user }
β”‚ β”‚ β”‚ └── Signup.js # registers then auto‑login
β”‚ β”‚ β”œβ”€β”€ dashboard/
β”‚ β”‚ β”‚ β”œβ”€β”€ Dashboard.js # shows user’s posts, stats, delete/edit modals
β”‚ β”‚ β”‚ β”œβ”€β”€ Comments.js # admin comment moderation page (uses useComments)
β”‚ β”‚ β”‚ β”œβ”€β”€ Settings.js # user settings (profile, privacy, notifications, appearance, publishing)
β”‚ β”‚ β”‚ β”œβ”€β”€ Stats.js # analytics and charts
β”‚ β”‚ β”‚ β”œβ”€β”€ Theme.js # theme picker (updates ThemeContext)
β”‚ β”‚ β”‚ └── settingsTabs/ # tab components for Settings page
β”‚ β”‚ β”‚ β”œβ”€β”€ ProfileTab.js
β”‚ β”‚ β”‚ β”œβ”€β”€ PrivacyTab.js
β”‚ β”‚ β”‚ β”œβ”€β”€ NotificationsTab.js
β”‚ β”‚ β”‚ β”œβ”€β”€ AppearanceTab.js
β”‚ β”‚ β”‚ β”œβ”€β”€ PublishingTab.js
β”‚ β”‚ β”‚ └── index.js
β”‚ β”‚ β”œβ”€β”€ posts/
β”‚ β”‚ β”‚ β”œβ”€β”€ CreatePost.js # standalone create post page (or use modal)
β”‚ β”‚ β”‚ β”œβ”€β”€ EditPost.js # standalone edit page (GET /posts/:id, PUT)
β”‚ β”‚ β”‚ └── PostDetail.js # view post, like, comment form, comment list
β”‚ β”‚ └── PublicHome.js # landing page, fetches all posts (GET /posts)
β”‚ β”œβ”€β”€ services/
β”‚ β”‚ └── commentsAPI.js # functions for getAllComments, approve, reject, delete, like, reply
β”‚ β”œβ”€β”€ utils/
β”‚ β”‚ β”œβ”€β”€ auth.js # setToken, getToken, removeToken, isAuthenticated, getUserFromToken
β”‚ β”‚ β”œβ”€β”€ axios.js # interceptors: attach token, handle 401
β”‚ β”‚ β”œβ”€β”€ postStats.js # getPostStats, formatPostStats, postStatsSummary
β”‚ β”‚ β”œβ”€β”€ toast.js # showSuccess, showError, showLoading (react-hot-toast)
β”‚ β”‚ └── statusColors.js # helper for comment status badges
β”‚ β”œβ”€β”€ App.js # routes: public + protected
β”‚ β”œβ”€β”€ index.js
β”‚ └── index.css # Tailwind imports + custom keyframes
β”œβ”€β”€ .env.development # REACT_APP_API_URL for local backend
β”œβ”€β”€ .env.production # REACT_APP_API_URL for deployed backend (Render)
β”œβ”€β”€ package.json
└── tailwind.config.js

Important Notes for the Team

  • All API responses from the backend use the { success, message, data } pattern (except /posts which returns { success, posts } and /posts/:id returns { success, post }).
  • Error handling in the frontend always looks at err.response?.data?.message.
  • Authentication middleware attaches req.userId (not the full user object).
  • The comment system uses author as a string (the logged‑in user’s username) – this is technical debt that can be migrated later to a proper ObjectId reference.
  • The .vscode/tasks.json provides a one‑click β€œStart Frontend Development Server” task – useful but not essential.

Deployment URLs

For local development, ensure the frontend .env.development uses http://localhost:5000/api and the backend .env uses your local MongoDB URI.