How josephng95/thorshop works
Project type and purpose
• thorshop is a full-stack web application built with Node.js and Express.
• It provides a public shop frontend (views/shop, public assets) and a backend “Thor” admin panel (views/thor, controllers/backend).
• It uses LowDB (a file-based JSON database) to store data (models/*.js + database/db.js) and Bootstrap for styling.
File structure
• Top-level:
• app.js & bin/www – HTTP server bootstrap
• controllers/ – request handlers divided into frontend (shop) and backend (Thor)
• routes/ – Express router definitions (index.js, thor.js)
• models/ – data models (category, product, sell, user, auth)
• database/ – LowDB config and example JSON
• views/ – Jade templates for shop and Thor UI
• public/ & resource/ – static assets (CSS, JS, images)
• middlewares/ – custom middleware (utils, file upload, auth checks)
• utils/ – helper functions and constants
README
• Confirms use of Node.js, Express, LowDB, Bootstrap.
a. Main components
• Browser (Client) – Shop UI & Thor Admin UI
• Web Server (Express app.js + bin/www)
• Controllers & Routes – request processing layer
• Models & Database Adapter (LowDB)
• File System (JSON files for LowDB)
• Static Asset Server (public/ & resource/)
• Middleware Layer (authentication, file upload, utilities)
• External Libraries (Express, LowDB, Jade, Bootstrap)
b. Relationships & interactions
1. Client → HTTP Request → Express Routes
2. Routes → Controllers (frontend or backend)
3. Controllers → Models → Database (read/write JSON)
4. Controllers → Render Jade views or return JSON
5. Client ← HTTP Response (HTML + CSS/JS or JSON)
6. Static Asset Requests → public/ or resource/ directory
7. Middleware intercepts requests (auth, uploads, logging)
c. Architectural patterns
• MVC pattern:
• M: models/ + database/db.js
• V: views/ (Jade templates) + public assets
• C: controllers/ + routes/
• Layered Architecture:
• Presentation (views, public)
• Application (routes, controllers)
• Domain (models, utils)
• Infrastructure (database, file system)
• Single Node.js process hosting both frontend and admin backend, separated by route prefixes (e.g., /thor)
d. Key technologies
• Node.js & Express as HTTP server framework
• LowDB for JSON-based persistence
• Jade (Pug) for server-side templating
• Bootstrap & custom CSS/JS for UI
• Custom middleware (middlewares/thor.js) for admin authentication
• Utility modules (utils/*.js) for string, date, upload, constants
Detailed capture of architectural elements
• Bin/www script initializing the Express app.
• Environment configuration (.env.example) feeding into app.js.
• Out how models import database/db.js to perform CRUD.
• How utils and middlewares are injected into routes/controllers.
• Static URL prefix (/css, /js, /images) to public/ and resource/ folders.