How agampandey27/peer-to-peer-book-exchange works
This project is a full-stack web application for a peer-to-peer book exchange system where users can register as either book Owners or Seekers. The system enables Owners to list and update books, while Seekers can search and filter through available books. The frontend is built with React.js (using Vite for development and Tailwind CSS for styling), and the backend uses Node.js with Express.js alongside MongoDB (accessed via Mongoose).
Main Components Identification
• Frontend (Client):
• Core UI components, pages, context handling (for authentication), assets, and styles.
• Key components include pages like Login, Register, OwnerDashboard, SeekerDashboard, AddBook, and MyBooks.
• Components such as Navbar and BookCard provide reusable UI elements.
• Backend (Server):
• API endpoints for user authentication, book management (add, update, list), and status updates.
• Structured into controllers (e.g., authController.js and bookController.js), models (userModel.js, bookModel.js), and routes (authRoutes.js, bookRoutes.js).
• Database connectivity via the configuration (server/config/db.js) to MongoDB.
• Database:
• Represented as MongoDB, which stores the user and book data, managed via Mongoose schemas.
• External Services:
• Optional components like environment configuration and deployment settings (e.g., vercel.json for deployment).
Relationships & Interactions
• The Frontend communicates with the Backend via API calls (primarily Axios based) to endpoints such as /api/auth/register, /api/auth/login, /api/book, and /api/book/:id/status.
• The Backend handles the business logic by directing requests to appropriate controllers, which interact with the database through models.
• Authentication flow is managed via a shared AuthContext on the client and via dedicated auth controllers on the server.
• Data flows from user inputs (login, book posting, etc.) on the frontend, through API calls, and any changes are persisted and reflected via database updates.
Architectural Patterns and Design Principles
• Separation of Concerns: Clearly divides the frontend and backend functionalities.
• MVC-like organization on the server: Routes direct requests to controllers that manipulate models.
• Context API Usage on the client for state management (authentication context).
• Modular structure: Distinct directories for components, pages, and context in the client and separated controller, model, and route files in the server.