How pateljayy/urlshortner works
Main Components
• Frontend View Layer – Represented by the EJS templates found in the “views” directory (e.g., home.ejs, login.ejs, signup.ejs). These files are responsible for rendering the user interface.
• Backend API/Controller Layer – Consists of the controllers (e.g., controllers/url.js, controllers/user.js) which implement the business logic for URL shortening and user operations.
• Routing Layer – Found in the “routes” directory (e.g., routes/url.js, routes/user.js, routes/staticRouter.js) which maps HTTP endpoints to the appropriate controllers.
• Middleware – The “middlewares/auth.js” file ensures that routes requiring authentication are protected by verifying JWT tokens.
• Data Access Layer – The models (e.g., models/url.js, models/user.js) define the MongoDB schemas for storing URL data and user information.
• Authentication Service – Located in “service/auth.js” which handles JWT creation and validation for secure access.
• Configuration/Entry Point – The “index.js” file is the entry point of the application where the Express app is initialized, middlewares are set up, and routes are attached.
• External Systems – A MongoDB database instance (as per the README) and external authentication (JWT) means.
Lay Out Relationships and Interactions
• Client (Browser) interacts with the server through HTTP requests which hit the web server.
• The Express application in “index.js” directs the incoming requests via defined routes in the “routes” folder.
• Routes forward requests to appropriate controllers, which then might interact with the data models.
• The controllers use the “service/auth.js” for user authentication and authorization.
• The middleware “middlewares/auth.js” intercepts requests to verify user tokens before allowing access to protected routes.
• Model operations are performed against the MongoDB database using Mongoose models (in the “models” folder).
• Finally, the controller returns responses, possibly rendering dynamic views with EJS from the “views” folder.
Architectural Patterns & Design Principles
• MVC Pattern – The separation of concerns between models, views, and controllers is key.
• RESTful Routing – The “routes” directory organizes endpoints that likely follow RESTful standards.
• Middleware Usage – Implementation of cross-cutting concerns like authentication via “middlewares/auth.js”.
• Service Abstraction – The dedicated “service/auth.js” file shows abstraction of authentication logic away from controllers.
Relevant Technologies/Frameworks
• Node.js and Express – For the server and routing logic.
• EJS – As the view templating engine.
• MongoDB & Mongoose – For database and schema modeling.
• JWT – For secure user authentication.
• GitHub Actions (via the .github/workflows folder) – For CI/CD, ensuring code quality or automated testing.