How gracious0/ecommerce-website works
Main Components
• Frontend: Represented by the content in the "public" directory. This includes HTML pages (e.g., index.html, product-listing.html) and associated CSS/JS files.
• Backend:
• Entry point (app.js) that initializes the Express server.
• Routes (found in src/routes) that map HTTP endpoints to controllers.
• Controllers (src/controllers) that orchestrate the app’s business logic.
• Models (src/models) that represent the data structure and interact with the database.
• Config (src/config/database.js) where database connectivity settings are defined.
• Services (src/services/paymentService.js) for handling specific operations like payment processing.
• Utils (src/utils) for helper functions.
• Database: The project supports MongoDB/MySQL, configurable via environment variables (provided in .env).
• External Payment Service: Integration with Paystack handles payment processing.
Out Relationships and Interactions
• Users interact with the Frontend components (served from the public folder) via their browsers.
• The browser sends HTTP requests to the Backend Express server, which is initiated in app.js.
• The Express server uses routes to forward requests to appropriate controllers.
• Controllers manage business logic, calling:
• Models to perform database operations.
• PaymentService for communicating with Paystack.
• Data flows from the Models to the Database and back again.
• Payment requests are sent to and responses received from the external Paystack API.
Architectural Patterns and Design Principles
• MVC Pattern – The separation into controllers, models, and routes clearly marks an MVC design.
• Service Layer – The paymentService emphasizes separation of concerns for external integration.
• Environment-Based Configuration – The database URI, JWT secret, and Paystack secret key are defined in the .env file.
• API Layer – Express routes form a RESTful API for interactions between the frontend and the backend.
Relevant Technologies and Frameworks
• Node.js and Express.js for the server and routing.
• MongoDB/MySQL for the database (as specified in the configuration).
• Paystack for payment processing.
• Standard HTML, CSS, and JavaScript for the frontend (static assets served from the public directory).
• Use clear labels for each component:
• The request flow: Browser → Express Routes → Controllers.
• Data operations: Controllers ⇄ Models ⇄ Database.
• Payment processing flow: Backend → PaymentService → Paystack.
• “Routes” which then feed into “Controllers.”
• “Controllers” have two branches:
▪ One towards “Models” connecting to the “Database.”
▪ Another towards “Payment Service” leading to “Paystack.”
• Component is clearly separated and labeled—this ensures the architecture is understandable at a glance.