How 100xdevs-cohort-3/week-8-course-selling-project works
Project Type & Purpose
• The project is a full-stack application (primarily backend-focused in the current file tree) developed in Node.js.
• Its purpose is to support a course selling platform where both users and admins have dedicated functionalities (e.g., user login, signup, course purchase; admin login, course management).
• It uses Express for the HTTP server, Mongoose for MongoDB interactions, and jsonwebtoken (JWT) for authentication, with the README noting additional suggestions like switching to cookies for auth.
Analyzing the File Structure
• Top-Level Files:
• index.js: The main entry point, likely where the Express server is configured and started.
• config.js: Contains configurations, which could include environment-specific settings.
• db.js: Manages the MongoDB connection, crucial for data persistence.
• .env.example: Holds environment variables, particularly for the DB connection string.
• package.json/package-lock.json: Define project dependencies.
• Directories:
• middleware/: Contains authentication middleware files: admin.js and user.js, responsible for managing access control for the respective roles.
• routes/: Divided into admin.js, course.js, and user.js. This clearly shows a separation of concerns where different routes are managed per user role or functionality (i.e., course management).
Key Architecture Components
a. Express Server Layer:
• Entry Point: index.js where the Express application is initialized.
• Routing: Separated in the routes directory with distinct files for admin, course, and user functionalities.
b. Middleware Layer:
• admin.js and user.js under middleware handle role-specific authentication and perhaps authorization.
c. Database Layer:
• db.js connects to MongoDB.
• The system includes schemas (as described in the README) for the models: User, Admin, Course, and Purchase.
d. Configuration & Environment:
• config.js for general configuration.
• .env.example for environment variable management.
e. External Dependencies:
• Libraries like Express (for HTTP server), jsonwebtoken (for authentication), and mongoose (for database interactions).
f. (Optional) Frontend:
• Although the file tree does not yet contain a dedicated frontend directory, the README indicates that a frontend will be added later (using EJS or React).
• Client / Frontend:
• API Gateway / Express Server:
• A central block starting from index.js that routes incoming requests.
• Middleware:
• Attach middleware blocks (user.js and admin.js) that intercept the request flow for authentication.
• Database (MongoDB):
• Configuration/Environment Variables:
• Configuration settings from config.js and .env file, which influence how different components interact (for example, DB connection strings and JWT secret keys).
Architectural Patterns and Design Principles
• Separation of Concerns/MVC-like Structure:
• The project separates routing, middleware, configuration, and database connections clearly.
• Layered Architecture:
• Different layers (routing/controllers, middleware, database) are clearly distinct.
• Dependency Management:
• External libraries are cleanly integrated via npm packages.