How thapatechnical/urlshortener works
Main Components
a. Client (Browser) – renders EJS views, interacts via HTTP/HTTPS
b. Web Server / Application Layer – Node.js + Express.js
c. Business Logic Layer – Controllers → Services → Validators → Models
d. Persistence Layer –
• MongoDB via Mongoose (e.g., user profiles)
• MySQL via Prisma & Drizzle ORM (e.g., link records, migrations)
e. External Services –
• OAuth Providers (Google, GitHub)
• Email Service (Nodemailer + MJML templates)
• File Storage (via Multer for profile images)
f. Static Assets – CSS, images, served from /public
Relationships & Data Flow
• Client sends HTTP requests (GET/POST) → Express Router (routes/*.js)
• Request passes through global and route‑specific middleware (e.g., verify-auth‑middleware.js)
• Router invokes appropriate Controller (controllers/*.js)
• Controller calls Validators (validators/*.js) to enforce input rules
• Controller delegates to Services (services/*.js) for business logic
• Service interacts with Models (models/*.js) using ORM APIs (Mongoose, Prisma, Drizzle)
• Model operations translate to queries on MongoDB or MySQL
• Some Services invoke lib utilities (e.g., get-html-from-mjml-template.js, nodemailer.js) to send email
• Responses flow back up to Controller → rendered via EJS views (views/**/*.ejs) → HTTP response to client
Architectural Patterns & Design Principles
• Layered (MVC‑like) architecture: Separation of concerns between routing, controller logic, services, and data access
• Modular design: Each feature (auth, shortener) lives in its own route/controller/service/validator directory
• Multi‑ORM strategy: Use of Mongoose for MongoDB, Prisma & Drizzle ORM for MySQL, plus Drizzle migrations for schema versioning
• Security: JWT & OAuth, request validators, auth middleware
• Templating: Server‑side rendering with EJS + partials
• Asynchronous, event‑driven I/O (Node.js)
Detailed Component Breakdown
a. Client
• Index page (views/index.ejs)
• Auth pages under views/auth
• Shortener UI (views/edit-shortlink.ejs, views/report.ejs)
b. Express Server (app.js) & Config (config/*.js)
c. Routes (routes/*.js) – entry points
d. Middleware (middlewares/verify-auth-middleware.js) – guard protected routes
e. Controllers → Services → Models → DB
f. Drizzle Migrations (drizzle/migration/) – manage MySQL schema versions
g. Email subsystem (emails/*.mjml + lib/send-email.js)
h. Validators (validators/*.js) – enforce schema on incoming requests