How lindsey5/zhiyuan-backend works
Zhiyuan Backend is an Express API for identity and permissions, catalog and orders, and distributor inventory and sales operations. A client request enters through the app’s mounted routes and is handled by domain controllers; selected workflows also use service-layer logic, persistent models, caching, media storage, or real-time notifications. The README documents audit logging, reviews, returns, sponsored items, and other capabilities beyond the sampled source. Their route mounts are visible, but unsampled handler wiring is not inferred.
Main entry points: app.ts Express app · productController.ts Catalog management · reviewController.ts Review handling · distributorRoutes.ts Distributor routes
Components 27
API and access
- Express app
app.ts - Auth routes
routes/authRoutes.ts - Authentication
controllers/authController.ts - Auth and permissions
middlewares/authMiddleware.ts - User routes
routes/userRoutes.ts - User management
controllers/userController.ts - Role routes
routes/roleRoutes.ts
Catalog and commerce
- Product routes
routes/productRoutes.ts - Catalog management
controllers/productController.ts - Order routes
routes/orderRoutes.ts - Order handling
controllers/orderController.ts - Review routes
routes/reviewRoutes.ts - Review handling
controllers/reviewController.ts
Distributor operations
- Distributor routes
routes/distributorRoutes.ts - Distributor management
controllers/distributorController.ts - Sales routes
routes/distributorSaleRoutes.ts - Sales reporting
controllers/distributorSaleController.ts - Return routes
routes/returnRequestRoutes.ts - Return handling
controllers/returnRequestController.ts - Stock transfer logic
services/StockTransferService.ts
Runtime services
- Cloudinary media
utils/cloudinary.ts - Socket.IO
sockets/socket.ts - Notification service
services/NotificationService.ts - Distributor notifications
sockets/namespaces/distributorNotification.namespace.ts
Persistence and cache
- MongoDB
config/db.ts - Redis cache
config/redis.ts
Other components
- API client
Connections 28
- API client → Express app: sends request
- Express app → Auth routes: mounts routes
- Express app → User routes: mounts routes
- Express app → Role routes: mounts routes
- Express app → Product routes: mounts routes
- Express app → Order routes: mounts routes
- Express app → Review routes: mounts routes
- Express app → Distributor routes: mounts routes
- Express app → Sales routes: mounts routes
- Express app → Return routes: mounts routes
- Auth routes → Authentication: dispatches to
- User routes → User management: dispatches to
- Product routes → Catalog management: dispatches to
- Review routes → Review handling: dispatches to
- Distributor routes → Auth and permissions: checks access
- Distributor routes → Distributor management: dispatches to
- Sales routes → Auth and permissions: checks access
- Sales routes → Sales reporting: dispatches to
- Return routes → Return handling: dispatches to
- Review handling → Redis cache: reads and writes cache
- Catalog management → Cloudinary media: uploads media
- Return handling → Distributor notifications: emits notification
- Stock transfer logic → Distributor notifications: emits notification
- Notification service → Socket.IO: emits events
- Stock transfer logic → Redis cache: invalidates cache
- Return handling → MongoDB: persists workflow
- Catalog management → MongoDB: reads and writes catalog
- Review handling → MongoDB: reads and writes reviews