How ashikurrafi/blog works
1. Top-level split
- The repository is a classic two-tier app: a React client in client/ and a Node/Bun backend in server/.
- The client is a single-page application that talks to the server over a JSON API; the server owns persistence, authentication, authorization, and file uploads.
2. Frontend shell and navigation
- The client is organized around route-level page components under src/pages/.
- There are distinct UI zones: public (HomePage, SinglePostPage), auth (LoginPage, RegisterPage), dashboard (CreatePostPage, EditPostPage, MyPostsPage, ProfilePage), and admin (AdminPostsPage, AdminCategoriesPage, AdminUsersPage).
- Layout components in src/components/layout/ (PublicLayout, DashboardLayout, Navbar, Sidebar, Footer) indicate the app uses shared shells to separate public browsing from authenticated work areas.
3. Client-side state and API boundary
- Redux is the central client state mechanism, with slices for auth, blog, category, comment, and UI in src/redux/.
- src/api/apiClient.js is the main transport boundary for server calls, so data-fetching and mutations are centralized rather than scattered through pages.
- This suggests the client reads server state into Redux and uses the store to coordinate auth status, post lists, categories, comments, and UI concerns like dialogs/loading.
4. Frontend component structure
- src/components/ui/ contains reusable primitive widgets such as buttons, dialogs, tables, forms, tabs, alerts, and sheets, which are then composed by pages and layouts.
- This creates a three-layer client structure: page orchestration → layout shell → reusable UI primitives.
5. Backend application structure
- The server is organized in a standard route → controller → model flow.
- src/server.js and src/app.js are the entry points, while src/routes/index.js aggregates feature routes such as auth, blog, category, comment, user, and admin.
- This separation keeps HTTP wiring isolated from business logic.
6. Domain modules on the server
- Core business domains are represented by models in src/models/: user, blog, category, and comment.
- Controllers mirror those domains in src/controllers/, with separate handlers for authentication, blog content, categories, comments, users, and admin operations.
- The data model implies a blog platform with posts, categorization, user accounts, and threaded/attached comments.
7. Persistence and data access
- src/config/db.js handles database connection setup, and the presence of model files strongly suggests a MongoDB/Mongoose-style persistence layer.
- The server does not appear to expose direct database access to the client; all reads/writes are mediated through controllers and route handlers.
8. Authentication and authorization
- src/middleware/authMiddleware.js and isAdminMiddleware.js enforce access control at the route layer.
- This creates three trust levels:
- public readers,
- authenticated users who can manage their own profile/posts,
- admins who can manage users, categories, and posts globally.
- The dedicated auth and user routes indicate login/registration and account-related APIs are separate from content APIs.
9. Media upload and external storage
- src/middleware/multer.js, src/utils/dataUri.js, and src/utils/cloudinary.js show that post images or user avatars are uploaded through the backend and pushed to Cloudinary.
- The backend therefore acts as the upload gateway, converting multipart file input into a Cloudinary-hosted asset and storing the resulting metadata in the database.
10. Error and response conventions
- src/errors/apiError.js, apiResponse.js, and asyncHandler.js provide a shared HTTP error/response pattern.
- This indicates the API is standardized around consistent JSON responses and centralized async error handling, which simplifies client integration and server maintenance.
11. Content integrity and cascading behavior
- src/utils/cascadeDelete.js suggests the backend handles dependent-record cleanup when content is removed.
- That is important for a blog system where deleting a category, user, or post may require removing or reassigning related posts/comments.
12. Primary end-to-end flows
- Public browsing: client public pages fetch blog content and display single posts.
- Signup/login: auth pages call auth routes, update Redux auth state, and unlock protected layouts.
- Author workflow: dashboard pages create/edit/manage a user’s own posts and profile.
- Admin workflow: admin pages manage site-wide posts, categories, and users.
- Commenting: comment-related state and routes support post detail interactions.
13. Technology cues that matter for the diagram
- The client is built with React + Vite and uses Bun-managed dependencies (bun.lock).
- The server is also Bun-managed and likely runs as a Node-compatible HTTP API.
- The architecture is therefore a separated SPA frontend plus REST-style backend, with Cloudinary as the only clearly visible external service.
Main entry points: store.js Redux store · main.jsx SPA shell · index.js Route index · apiClient.js API client
Components 27
Client
React SPA with pages, layouts, Redux state, and API boundary.
- SPA shell · Application bootstrap and top-level client entry.
client/src/main.jsx - Public pages · Home and post detail screens for anonymous browsing.
client/src/pages/public/HomePage.jsx - Auth pages · Login and registration screens.
client/src/pages/auth/LoginPage.jsx - Dashboard pages · Authenticated author screens for creating, editing, and managing content.
client/src/pages/dashboard/DashboardPage.jsx - Admin pages · Site-wide management screens for posts, categories, and users.
client/src/pages/admin/AdminPostsPage.jsx - Layouts · Shared public and dashboard shells with navigation and chrome.
client/src/components/layout/PublicLayout.jsx - UI kit · Reusable interface components used across pages and layouts.
client/src/components/ui/button.jsx - API client · Central client-side boundary for server requests.
client/src/api/apiClient.js - Redux store · Client state container coordinating auth, content, comments, and UI.
client/src/redux/store.js - Auth state · Authentication and current user state.
client/src/redux/authSlice.js - Blog state · Post data and blog workflow state.
client/src/redux/blogSlice.js - Category state · Category list and category management state.
client/src/redux/categorySlice.js - Comment state · Comment data and comment interactions.
client/src/redux/commentSlice.js - UI state · Local interface state such as dialogs, loading, and view toggles.
client/src/redux/uiSlice.js
Server
Bun/Node API with routes, controllers, models, and middleware.
- Server entry · HTTP startup and application wiring.
server/src/server.js - App setup · Express-style app configuration and middleware setup.
server/src/app.js - Route index · Aggregates feature routes into the public API.
server/src/routes/index.js - Auth API · Login and registration endpoints plus auth handling.
server/src/controllers/authController.js - Content API · Blog post and category CRUD plus content interactions.
server/src/controllers/blogController.js - Comment API · Comment creation and moderation endpoints.
server/src/controllers/commentController.js - Admin API · Global administration endpoints for users and content.
server/src/controllers/adminController.js - Domain models · User, blog, category, and comment schemas.
server/src/models/userModel.js - Middleware · Auth guards, admin checks, and file upload handling.
server/src/middleware/authMiddleware.js - DB setup · Database connection and persistence bootstrapping.
server/src/config/db.js - Cloudinary bridge · Multipart upload conversion and external asset storage.
server/src/utils/cloudinary.js - API helpers · Shared async handling and standardized API responses/errors.
server/src/errors/apiResponse.js - Cascade delete · Dependent-record cleanup for related content.
server/src/utils/cascadeDelete.js
Connections 32
- SPA shell → Layouts: uses · App renders shared shells and route zones.
- SPA shell → Public pages: routes · Public navigation and post detail views.
- SPA shell → Auth pages: routes · Authentication screens.
- SPA shell → Dashboard pages: routes · Protected author workflow screens.
- SPA shell → Admin pages: routes · Admin management screens.
- Layouts → UI kit: composes · Layouts are built from reusable primitives.
- Public pages → API client: fetches · Public pages load posts and single-post data.
- Auth pages → API client: mutates · Login and registration call the API boundary.
- Dashboard pages → API client: mutates · Create/edit/profile workflows submit to the backend.
- Admin pages → API client: mutates · Admin actions use centralized API calls.
- API client → Redux store: updates · Server responses flow into client state.
- Redux store → Auth state: contains · Auth state is centralized in Redux.
- Redux store → Blog state: contains · Blog state is centralized in Redux.
- Redux store → Category state: contains · Category state is centralized in Redux.
- Redux store → Comment state: contains · Comment state is centralized in Redux.
- Redux store → UI state: contains · UI state is centralized in Redux.
- Server entry → App setup: boots · Entry point starts the configured app.
- App setup → Route index: mounts · App wires feature routes into the API.
- Route index → Auth API: includes · Authentication route handling.
- Route index → Content API: includes · Blog and category content handling.
- Route index → Comment API: includes · Comment handling.
- Route index → Admin API: includes · Admin handling.
- Auth API → Middleware: guards · Auth routes are protected where needed.
- Content API → Domain models: persists · Content APIs operate on domain models.
- Comment API → Domain models: persists · Comment APIs operate on domain models.
- Admin API → Domain models: persists · Admin APIs manage persisted records.
- Domain models → DB setup: stored in · Models rely on the database connection.
- Middleware → Cloudinary bridge: uploads · File handling passes through Cloudinary integration.
- Content API → Cascade delete: cleans up · Content deletion cascades to related records.
- Auth API → API helpers: standardizes · Controllers use shared async/error response helpers.
- Content API → API helpers: standardizes · Controllers use shared async/error response helpers.
- Comment API → API helpers: standardizes · Controllers use shared async/error response helpers.