How andmiron/my-tour works
Project Type and Purpose
• This is an Express-based MVC web application designed as a pet project to showcase full-stack development skills.
• Its purpose is to provide a tour management platform with features such as user authentication, booking tours, posting reviews, and handling payments (via Stripe).
• The application clearly separates logic into distinct components (e.g., auth, bookings, tours, reviews, users) and uses a modular design with controllers, routers, models, and validators.
Main Components
a. Client Browser:
• Represents users interacting with the application through a web client.
• Uses Pug templates rendered on the server, with some client-side JavaScript under the public/js folder.
b. Express Application Server:
• Entry Points: The main server file (app.js) and starting script (bin/www).
• Routing Layer: Clearly separated into various components (auth, bookings, tours, reviews, users, views), each having its own router file.
• Controllers: Manage the business logic associated with each component.
• Models: Represent the data schema (using Mongoose) for users, tours, bookings, and reviews.
• Validators: Ensure data integrity before processing.
• Middlewares: Global error handler and authentication checks (e.g., errorHandler.js and isAuthenticated.js).
c. Configuration and Services:
• Config: Contains configuration files (session.options.js, config.js) which determine application settings.
• Services: A folder that abstracts integrations with external systems such as:
• MongoDB (mongo.js) for database connectivity.
• Stripe (stripe.js) for payment processing.
• AWS S3 client (clientS3.js) for file storage.
• Email and other utilities (email.js, morgan.js, multer.js, passport.js).
d. Database:
• Although not directly visible, the use of Mongoose indicates a MongoDB database.
• Database as an external component linked to the models in the server.
e. External and Third-Party Services:
• Stripe as the external payment service.
• Email service, file storage service (Amazon S3), and any external authentication mechanisms (Passport) as distinct external components.
Relationships and Interactions
• From Client Browser → Express Server: HTTP requests are made by the client, which are routed to specific routers.
• Express Server Routes → Controllers: Routers delegate requests to controllers where business logic is executed.
• Controllers ↔ Models: Controllers interact with the models to perform database operations (create, read, update, delete).
• Controllers → Views: Upon processing data, controllers render Pug templates or send JSON responses.
• Controllers → Services: For external interactions (e.g., handling payments via Stripe, sending emails, file uploads).
• Middlewares: Positioned in the flow to intercept and process requests for error handling and authentication.
• Database: Connects to the Express server via the Mongoose layer.
Architectural Patterns and Design Principles
• MVC (Model-View-Controller): Clearly visible by the segregation of controllers, models, and views (Pug templates).
• Modular Organization: Components are organized by domain (auth, bookings, tours, reviews, users) each with its own controllers, routers, models, and validators.
• Service Abstraction: External interactions are abstracted in the services folder, which isolates concerns such as payment processing, file management, logging, and database connectivity.
• Clear Separation of Concerns: Config, middleware, and routes are defined in separate directories/files to ensure maintainability.
• A subsection for routing and controllers organized by component (auth, tours, bookings, reviews, users, views).
• A middleware layer that is applied to all or selected routes.
• A service layer that abstracts interactions to external systems.