How anmolmehra435/achat works
1. This repository is a two-tier MERN application: a React single-page app in frontend/ talks to an Express/Node REST API in backend/, with MongoDB as the primary database and Cloudinary as the external media store.
2. The backend is organized in a classic MVC split. server.js is the composition root that wires configuration, middleware, routes, and the database connection. Business logic lives in controllers/, persistence schemas in models/, and HTTP endpoint definitions in routes/.
3. Authentication is a first-class subsystem. authController.js and authRoutes.js handle register/login/refresh flows, while verifyAccessJwt.js is the main protection boundary for authenticated APIs. The user model stores both refreshToken and profile data, which implies token refresh is tied to the persisted user record.
4. User management is separate from auth. userController.js and userRoutes.js expose endpoints for fetching the current user, updating the profile, and searching users. The users model includes name, username, email, password, avatar, and refreshToken, so the user document is both identity and session anchor.
5. Profile image uploads are handled as a dedicated pipeline: the frontend sends multipart form data, middleware/multer.js processes the upload, and config/cloudinary.js pushes the image to Cloudinary. The resulting Cloudinary URL is then stored back in MongoDB and rendered by the frontend.
6. Conversations are modeled in MongoDB using references rather than embedded user snapshots. conversation.js stores a members array of user ObjectIds, and conversationController.js/conversationRoutes.js implement create-and-list behavior. The README indicates duplicate conversation prevention and populate-based member hydration, so the conversation layer is designed around relationship lookup rather than denormalized chat rooms.
7. Message-related files exist in the backend (messagesController.js, messagesRoutes.js, messages.js), but the README still describes realtime messaging as upcoming. For architecture purposes, treat this as a partially scaffolded or evolving subsystem: the current codebase is centered on auth, profiles, and conversation management, with realtime delivery not yet the primary runtime path.
8. The frontend is a Vite-built React app with a small page-oriented structure: Login.jsx, Dashboard.jsx, and EditProfile.jsx. App.jsx is the top-level router/shell, while page-specific styling lives in dedicated CSS files. This suggests a route-driven UI rather than a heavily componentized design.
9. Frontend data access is split into service modules under src/services/. authServices.js and verifyJwtService.js centralize API calls related to login/session validation, which keeps token and auth checks out of the page components. The dashboard and profile pages likely consume these services to fetch user state and protected resources.
10. The main runtime data flow is: login on the frontend → backend validates credentials and issues tokens → client stores tokens and uses protected APIs → verifyAccessJwt guards server routes → user/dashboard calls fetch current profile and conversations. This is the key boundary for any diagram: browser UI on one side, authenticated REST API on the other.
11. The profile update flow is a second important path: user edits profile in React → multipart request to backend → Multer/Cloudinary upload path → MongoDB update → refreshed avatar URL displayed in the UI. That flow crosses the frontend, Express middleware, cloud storage, and database layers.
12. Infrastructure-wise, the repo depends on MongoDB, Cloudinary, JWT secrets, and standard Node/React tooling. Vite, Axios, React Router DOM, Express, Mongoose, and Multer are the materially relevant technologies; there is no evidence in the current tree of Socket.IO, background jobs, or separate microservices.
Main entry points: server.js Server · users.js Users model · userController.js User controller · authRoutes.js Auth routes
Components 23
Frontend
React/Vite SPA and client-side service layer
- App shell · Top-level SPA router and layout
frontend/src/App.jsx - Login · Authentication entry screen
frontend/src/pages/Login.jsx - Dashboard · Main authenticated workspace
frontend/src/pages/Dashboard.jsx - Edit profile · Profile update screen
frontend/src/pages/EditProfile.jsx - Auth service · Client calls for login and session flows
frontend/src/services/authServices.js - JWT check · Client-side protected-session validation
frontend/src/services/verifyJwtService.js
Backend
Express API, middleware, controllers, and models
- Server · Composition root for config, middleware, routes, and DB
backend/server.js - Auth routes · Register, login, and refresh endpoints
backend/routes/authRoutes.js - Auth controller · Authentication and token flow logic
backend/controllers/authController.js - Access guard · Protects authenticated API routes
backend/middleware/verifyAccessJwt.js - User routes · Current user, profile update, and search endpoints
backend/routes/userRoutes.js - User controller · User profile and lookup logic
backend/controllers/userController.js - Conversation routes · Create and list conversation endpoints
backend/routes/conversationRoutes.js - Conversation controller · Conversation creation and hydration logic
backend/controllers/conversationController.js - Message routes · Messaging endpoints scaffold
backend/routes/messagesRoutes.js - Messages controller · Partial messaging subsystem
backend/controllers/messagesController.js - Upload middleware · Multipart parsing for profile images
backend/middleware/multer.js - Cloudinary config · Uploads media to Cloudinary
backend/config/cloudinary.js - Users model · Identity and session anchor document
backend/models/users.js - Conversation model · Member reference-based chat document
backend/models/conversation.js - Messages model · Message persistence schema
backend/models/messages.js
External services
Datastores and third-party media storage
- MongoDB · Primary data store
- Cloudinary · External image storage
Connections 32
- App shell → Login: routes to · Public auth entry
- App shell → Dashboard: routes to · Authenticated workspace
- App shell → Edit profile: routes to · Profile editor screen
- Login → Auth service: uses · Submit credentials and session actions
- Dashboard → JWT check: uses · Checks session and protected access
- Dashboard → User routes: calls · Fetch current user and conversations
- Edit profile → User routes: calls · Submit profile updates
- Auth service → Auth routes: calls · Login and refresh requests
- JWT check → Auth routes: calls · Session validation requests
- Server → Auth routes: mounts · Registers auth endpoints
- Server → User routes: mounts · Registers user endpoints
- Server → Conversation routes: mounts · Registers conversation endpoints
- Server → Message routes: mounts · Registers messaging endpoints
- Server → Access guard: applies · Protects authenticated routes
- Server → Upload middleware: applies · Handles multipart uploads
- Auth routes → Auth controller: delegates to · Auth request handling
- User routes → User controller: delegates to · Profile and lookup handling
- Conversation routes → Conversation controller: delegates to · Conversation handling
- Message routes → Messages controller: delegates to · Message handling scaffold
- Auth controller → Users model: reads/writes · Stores users and refresh tokens
- User controller → Users model: reads/writes · Profile updates and user search
- Conversation controller → Conversation model: reads/writes · Creates and lists conversations
- Messages controller → Messages model: reads/writes · Message persistence path
- Users model → MongoDB: persists to · MongoDB-backed collection
- Conversation model → MongoDB: persists to · MongoDB-backed collection
- Messages model → MongoDB: persists to · MongoDB-backed collection
- Upload middleware → Cloudinary config: uploads to · Profile image media pipeline
- Cloudinary config → Cloudinary: stores in · External media storage
- User controller → Upload middleware: uses · Profile image upload flow
- User controller → Cloudinary config: uses · Persists avatar URLs
- Access guard → Users model: validates against · Token/session tied to user record
- Conversation controller → Users model: references · Conversation members are user ids