How ichsanna/url-shortener works
Main Components
A. Client Layer:
• Browser/Frontend (HTML/CSS/JavaScript)
• Static Assets (public/assets)
• View Templates (EJS)
B. Application Layer:
• Web Server (Express.js)
• Authentication Middleware
• Controllers
• Routers
C. Data Layer:
• MongoDB Database
• Models (User and Link)
Component Relationships
[Client Browser] ←→ [Web Server (Express.js)]
• ↑ ↑
• [Static Assets] [Controllers]
• [EJS Views] ↑
• [Models] ←→ [MongoDB]
Detailed Component Breakdown
A. Routes Layer (First Entry Point):
• webRouter (Web Interface)
• userRouter (User Management)
• linkRouter (URL Shortening Operations)
B. Middleware Layer:
• Authentication middleware
• It intercepting requests between routes and controllers
C. Controllers Layer:
• userController (User Operations)
• linkController (Link Operations)
D. Models Layer:
• userModel (User Schema)
• linkModel (Link Schema)
Data Flow Representation
• HTTP requests from client to server
• Database queries between models and MongoDB
• Authentication flow through middleware
• Response flow back to client
Additional Elements
Supporting components:
• Configuration files (configs/)
• Environment variables (.env)
• Static file serving (public/)
• View engine (EJS)
[Client Layer]
• ↓↑
[Routing Layer]
• ↓↑
[Middleware Layer]
• ↓↑
[Controller Layer]
• ↓↑
[Model Layer]
• ↓↑
[Database Layer]
Key Considerations:
MVC pattern clearly
• Models (models/)
• Views (public/views/)
• Controllers (controllers/)
Security features
• JWT authentication
• Middleware protection
URL shortening flow
• URL submission
• Shortening process
• Storage
• Retrieval
External dependencies
• MongoDB connection
• Environment configurations