JK
Έργα
JK
>ΦΟΡΤΩΣΗ // ΦΟΡΤΩΣΗ
ΑΡΧΙΚΟΠΟΙΗΣΗ ΠΡΟΒΟΛΗΣ
Σχεδιάστηκε και δημιουργήθηκε απόJK
JK
>ΦΟΡΤΩΣΗ // PROJECT DETAILS
PARSING ARCHITECTURE, DIAGRAMS & API ENDPOINTS
Επιστροφή στα έργα
Προβολή στο GitHub
Express.js RESTful API Backend
Ολοκληρώθηκεtypescriptnodejsexpressmongodbcloudinaryjwtdotenveslint

Express.js RESTful API Backend

Έτοιμο για παραγωγή REST API με αρθρωτή αρχιτεκτονική MVC και ασφαλή πιστοποίηση.

Πρόβλημα & Λύση

Δημιουργία αξιόπιστης δομής με κεντρική διαχείριση σφαλμάτων και αυτοματοποιημένους ελέγχους.

Χαρακτηριστικά

  • Πιστοποίηση JWT με εναλλαγή refresh tokens
  • Middleware εξουσιοδότησης βάσει ρόλων
  • Βελτιστοποίηση αγωγών συγκέντρωσης στη MongoDB
  • Επικύρωση εισόδου και ασφάλεια δεδομένων
  • Σουίτα δοκιμών ολοκλήρωσης με Jest

Τεχνολογικό stack

ΤεχνολογίαΈκδοσηΣκοπόςΓιατί επιλέχθηκε
Node.js—JavaScript runtimeNon-blocking I/O, large ecosystem
Express.js4.19.2HTTP frameworkMinimal, flexible, well-documented
TypeScript5.5.4Type safetyCompile-time error catching, IDE support
MongoDB—Document databaseFlexible schema, JSON-native, horizontal scaling
Mongoose8.5.3MongoDB ODMSchema validation, middleware, query building
JWT (jsonwebtoken)9.0.2Authentication tokensStateless auth, industry standard
bcrypt5.1.1Password hashingAdaptive hashing, salt rounds
Cloudinary2.4.0Image hosting/CDNManaged service, CDN, image transformations
Multer1.4.5-lts.1File upload handlingExpress-integrated, simple API

Αρχιτεκτονική

Frontend Client

React :3000

Express App

app.ts :3000

CORS

express.json

JWT Auth Middleware

Global Error Handler

API Routes

/users, /admin, /restaurant, /menuitems, /orders

Controllers

User, Admin, Restaurant, Menu, Order

Mongoose Models

User, Admin, Restaurant, MenuItems, Order

MongoDB

localhost:27017/RMS

Cloudinary CDN

Local Filesystem

uploads
Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.

Application Layers

  • Express.js middleware pipeline (CORS, JSON parsing, JWT auth)
  • Domain-based modular structure (users, adminUser, restaurant, orders)
  • Controllers with direct Mongoose access (no service layer abstraction)
  • Global error handler middleware with status code mapping

Infrastructure

  • MongoDB via Mongoose 8.5.3 for document storage
  • Cloudinary v2 for menu item image hosting and CDN
  • Multer for multipart file upload handling
  • JWT (jsonwebtoken) for stateless authentication

Δομή έργου

src
adminUser
config
middlewares
orders
restaurant
users
app.tsExpress app setup, middleware, route mounting
server.tsApplication entry point, starts DB then server

API endpoints

RMS API (θύρα 3000)

ΜέθοδοςΔιαδρομήΣκοπός
GET/Health check / welcome
POST/api/users/registerRegister new user
POST/api/users/loginLogin user
POST/api/admin/createAdminCreate admin user
POST/api/admin/adminloginLogin admin
POST/api/restaurant/createRestaurantRegister restaurant owner
POST/api/restaurant/ownerLoginLogin restaurant owner
POST/api/Menuitems/addItemsCreate menu item with image
PUT/api/Menuitems/:itemIdUpdate menu item
GET/api/Menuitems/getAllItemsList all menu items
GET/api/Menuitems/:itemIdGet single menu item
DELETE/api/Menuitems/:itemIdDelete menu item
POST/api/orders/createorderCreate order
POST/api/orders/cancelorder/:orderIdCancel order
GET/api/orders/orderdetails/:orderIdGet order details

Σχεδιασμός βάσης δεδομένων

users

4 cols
_idPK
ObjectId
name
String
email
String
password
String

admins

4 cols
_idPK
ObjectId
name
String
email
String
userType
String

restaurants

4 cols
_idPK
ObjectId
restaurantName
String
restaurantEmail
String
restaurantPhoneNo
Number

menuitems

5 cols
_idPK
ObjectId
restaurantId
ObjectId
itemName
String
itemPrice
Number
itemImage
String

orders

7 cols
_idPK
ObjectId
customerId
ObjectId
restaurantId
ObjectId
menuId
ObjectId
orderQuantity
Number
orderStatus
String
orderBill
Number
Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.

users

ΣτήληΤύποςΣημειώσεις
_idPKObjectIdAuto-generated
nameStringRequired
emailStringRequired, unique
passwordStringbcrypt hashed
createdAtDateAuto (timestamps: true)
updatedAtDateAuto (timestamps: true)

User accounts. Email is unique.

admins

ΣτήληΤύποςΣημειώσεις
_idPKObjectIdAuto-generated
nameStringRequired
emailStringRequired, unique
passwordStringbcrypt hashed
userTypeStringenum: ['admin', 'user', 'restOwner']

Admin accounts. Separate collection from users.

restaurants

ΣτήληΤύποςΣημειώσεις
_idPKObjectIdAuto-generated
restaurantEmailStringRequired
restaurantPwdStringbcrypt hashed
restaurantNameStringRequired
restaurantAddressStringRequired
restaurantPhoneNoNumberRequired, unique

Restaurant owner accounts.

menuitems

ΣτήληΤύποςΣημειώσεις
_idPKObjectIdAuto-generated
restaurantIdObjectIdNo ref defined — .populate() won't work
itemNameStringHas typo: require instead of required
itemDescriptionStringHas typo: require instead of required
itemPriceNumberHas typo: require instead of required
itemImageStringCloudinary URL

Menu items per restaurant. restaurantId lacks ref property — schema bug.

orders

ΣτήληΤύποςΣημειώσεις
_idPKObjectIdAuto-generated
customerIdObjectIdref: User
restaurantIdObjectIdref: restaurant
menuIdObjectIdref: MenuItems
orderQuantityNumberNo validation for positive values
orderDateDateDefault: Date.now
orderStatusStringenum: ['in process', 'transit', 'cancelled', 'delivered']
orderBillNumberClient-supplied — security concern

Orders are client-supplied bill amounts — no server-side price calculation.

One-to-Many: Users→Orders, Restaurants→MenuItems, Restaurants→Orders, MenuItems→Orders. All via ObjectId references. No many-to-many relationships. menuitems.restaurantId lacks ref property.

Βασικές σχεδιαστικές αποφάσεις

Modular Monolith Architecture

Απόφαση: Single Express.js application with domain-based folder structure

Λόγος: Appropriate for project scale (~15 endpoints, single deployment)

Οφέλη: Simple deployment, easy debugging, low operational overhead, clear domain ownership

Ανταλλάγματα: Cannot scale domains independently, all modules share process, no service layer for reuse

JWT for Authentication

Απόφαση: Stateless JWT tokens with Authorization: Bearer header

Λόγος: Standard for REST APIs, no session storage needed

Οφέλη: Stateless, no server-side session store, scales horizontally

Ανταλλάγματα: No server-side revocation, tokens valid until expiry even if user is deleted

No Service Layer

Απόφαση: Business logic resides directly in controllers

Λόγος: Simplicity for small project, fewer files to navigate

Οφέλη: Fast development, fewer abstractions

Ανταλλάγματα: Untestable business logic, code duplication across auth controllers, hard to reuse logic

Cloudinary for Image Storage

Απόφαση: Menu item images uploaded to Cloudinary CDN

Λόγος: Managed service avoids S3/MinIO setup, provides CDN and image transformations

Οφέλη: No infrastructure to manage, built-in CDN, free tier available

Ανταλλάγματα: Vendor lock-in, external dependency, cost at scale, latency for non-CDN regions

Client-Supplied Order Bill

Απόφαση: orderBill is sent by the client, not calculated server-side

Λόγος: Likely intentional simplification for MVP

Οφέλη: Simpler server logic

Ανταλλάγματα: Critical security vulnerability — clients can manipulate order amounts

No Request Validation Library

Απόφαση: Manual if (!field) validation instead of Zod/Joi

Λόγος: Simplicity, fewer dependencies

Οφέλη: No additional dependency, explicit control

Ανταλλάγματα: Inconsistent validation, no type inference from schemas, generic error messages

Δοκιμές

None installed•0 μονάδες δοκιμών

Τι δοκιμάζεται

    Κενά κάλυψης

    • No test framework installed (no jest, mocha, vitest)
    • No test files or test directories
    • No unit tests for controllers or middleware
    • No integration tests for API endpoints
    • No authentication flow tests
    • No database operation tests

    Βασικές προκλήσεις

    • Σχεδιασμός αποδοτικού middleware για ασφάλεια και rate limiting
    • Ενιαία δομή απαντήσεων σφαλμάτων σε όλα τα endpoints

    Βασικά διδάγματα

    • Καθαρή αρχιτεκτονική MVC σε περιβάλλον Node.js
    • Προηγμένες τεχνικές ευρετηρίασης στη MongoDB