How youthlink-tech/fashion-commerce-backend works
1. Overall shape
- This is a Node.js backend built on Express.js for a fashion e-commerce platform.
- The codebase is organized as a feature-oriented API server, not a monolith of unrelated modules: each domain has its own route, controller, service, model, and Zod schema files.
2. Request pipeline
- Incoming HTTP requests enter through index.js, which wires the Express app, global middleware, MongoDB connection, and route mounting.
- The normal flow is: route → middleware → controller → schema validation → service → model → MongoDB, then a JSON response back to the client.
3. API layer and domain routing
- routes/ contains one route module per business area: products, orders, customers, inventory, analytics, marketing, notifications, shipment handling, etc.
- These routes are the main public boundary of the system and are likely consumed by both the storefront frontend and an internal dashboard.
4. Controller layer
- controllers/ holds the HTTP orchestration logic: parsing requests, invoking validation, calling services, and shaping responses.
- The controller set shows the main product domains of the system: commerce operations, content/CMS-like settings, customer support, analytics, and omnichannel marketing.
5. Business logic layer
- services/ contains the core business rules and multi-step operations.
- This layer is where workflows such as order handling, inventory updates, notification creation, marketing stats aggregation, access checks, and cache-aware reads are coordinated before touching the database.
6. Database access and persistence
- models/ encapsulates MongoDB collections and data access logic for each domain.
- config/db.js and config/collections.js centralize database connectivity and collection naming, so the rest of the app works through consistent model wrappers rather than raw collection lookups scattered across the codebase.
7. Validation and typed boundaries
- schemas/ contains Zod schemas for request validation and data-shape enforcement.
- This is an important architectural boundary: controllers and services can assume validated input before business logic runs, reducing coupling and runtime errors.
8. Security and access control
- Authentication and authorization are handled through middleware in middlewares/auth.js, backed by JWT utilities in utils/auth/.
- The repository explicitly supports role-based dashboard access with owner, editor, and viewer permissions, which suggests separate trust levels for admin-facing routes versus storefront-facing routes.
9. Operational middleware
- Cross-cutting concerns live in middlewares/: CORS handling, rate limiting, centralized error handling, and user-context enrichment.
- These middleware pieces define the runtime boundary around the API and protect it from abuse, bad origins, and inconsistent error responses.
10. Commerce and inventory subsystem
- The most substantial functional area is the commerce backend: products, categories, colors, tags, seasons, promos, special offers, vendors, purchase orders, transfer orders, shipping zones, shipment handling, payment methods, and inventory.
- This suggests the backend manages not only customer orders but also internal stock movement, procurement, and shipping configuration.
11. Customer engagement and content management
- There is a parallel subsystem for storefront content and engagement: hero banners, top header content, logos, story pages, FAQ, policies, newsletters, login/register images, and marketing banners.
- These modules indicate the backend also functions as a lightweight CMS for the public site and customer communications.
12. Notifications, email, and customer support
- utils/email/ and related controllers/services support transactional email flows such as order confirmation, shipping updates, refunds, password reset, invitations, and abandoned-cart messaging.
- customerSupport, notification, and email option builders form a side-effect layer that reacts to commerce events and user actions.
13. Analytics and omnichannel sync
- analytics, dashboard, audit, and omnichannel are a separate operational subsystem.
- The lib/meta* files and crons/metaInsightsCron.js/marketingStatsCron.js show scheduled synchronization with Meta advertising and insights data, while utils/googleAnalytics/ indicates Google Analytics integration.
- services/cacheHelper.js and config/redis.js suggest caching is used for performance or coordination in these reporting/sync flows.
14. Background jobs and automation
- crons/ contains scheduled jobs for abandoned carts, abandoned checkout sessions, audit logs, marketing stats, and Meta insights.
- These jobs run outside the request/response path and periodically update MongoDB-backed analytics or trigger customer re-engagement workflows.
15. Media and external integrations
- File/media handling appears to go through upload-specific controllers and helpers, with Cloudinary-related config and utilities present in the tree.
- The architecture therefore includes an external media storage boundary separate from the primary MongoDB data store.
16. Shared utilities and bootstrapping
- utils/ contains reusable domain helpers for dates, ordering calculations, promo validation, device/user info, customer/order ID generation, and activity/change tracking.
- scripts/seedOmnichannelData.js provides bootstrap data for the omnichannel subsystem, which is useful for local setup or environment seeding.
Main entry points: analyticsController.js Ops API · index.js index.js · crons/index.js Cron jobs · productsController.js Catalog API
Components 22
Core API
HTTP entrypoint, routing, middleware, validation, and persistence pipeline.
- index.js · Bootstraps Express, middleware, routes, and database connection.
index.js - Routes · Public HTTP boundary that splits the API into business domains.
- Middleware · CORS, auth, rate limiting, user context, and error handling.
- Schemas · Zod validation boundary for requests and domain shapes.
- Services · Domain workflows, coordination, and cache-aware reads.
- Models · MongoDB collection wrappers and query logic.
Commerce
Catalog, orders, inventory, and procurement workflows.
- Catalog API · Product, category, color, tag, season, promo, and special-offer HTTP orchestration.
controllers/productsController.js - Order API · Orders, inventory moves, purchase orders, transfers, shipments, and payment methods.
controllers/orderController.js - Inventory API · Stock and warehouse-facing inventory operations.
controllers/inventoryController.js
Content
Storefront content and CMS-like settings.
- Content API · Hero banners, headers, logos, stories, FAQ, and policy content.
controllers/heroBannerController.js
Engagement
Notifications, email, and customer support flows.
- Engagement API · Newsletter, notifications, email requests, and marketing campaigns.
controllers/notificationController.js - Support API · Customer support and operational requests.
controllers/customerSupportController.js - Email pipeline · Transactional email builders and delivery utilities.
utils/email/sendEmailToCustomer.js
Ops & Analytics
Dashboards, analytics, omnichannel sync, and scheduled jobs.
- Ops API · Analytics, dashboard, audit, and omnichannel coordination.
controllers/analyticsController.js - Analytics client · Google Analytics integration used by reporting flows.
utils/googleAnalytics/analyticsClient.js - Meta sync · Meta ads and insights synchronization logic.
lib/metaInsightsSync.js - Cron jobs · Background jobs for abandoned carts, audit logs, marketing stats, and Meta insights.
crons/index.js
Shared Infra
Cross-cutting config, auth, media, cache, and helper utilities.
- Mongo config · MongoDB connection setup.
config/db.js - Redis config · Cache and coordination layer for performance-sensitive flows.
config/redis.js - Auth utils · JWT helpers and role-based access checks.
utils/auth/authUtils.js - Media utils · Cloudinary upload and media handling helpers.
utils/media/cloudinary.js - Cloudinary config · External media storage configuration.
config/cloudinary.js
Connections 36
- index.js → Routes: mounts · Registers the HTTP route surface.
- index.js → Middleware: installs · Applies global request handling and protections.
- index.js → Mongo config: connects · Initializes MongoDB before serving traffic.
- index.js → Cron jobs: starts · Enables background automation.
- Routes → Catalog API: catalog · Public catalog and merchandising endpoints.
- Routes → Order API: orders · Order, shipment, and procurement endpoints.
- Routes → Inventory API: inventory · Inventory and stock endpoints.
- Routes → Content API: content · Storefront content and CMS endpoints.
- Routes → Engagement API: engagement · Notifications and marketing endpoints.
- Routes → Support API: support · Customer support endpoints.
- Routes → Ops API: ops · Analytics, dashboard, and audit endpoints.
- Catalog API → Schemas: validates · Validates product-domain requests and payloads.
- Order API → Schemas: validates · Validates order and fulfillment inputs.
- Inventory API → Schemas: validates · Validates inventory operations.
- Content API → Schemas: validates · Validates CMS-style content updates.
- Engagement API → Schemas: validates · Validates notification and marketing inputs.
- Support API → Schemas: validates · Validates support requests.
- Ops API → Schemas: validates · Validates analytics and admin inputs.
- Catalog API → Services: delegates · Hands off business rules to services.
- Order API → Services: delegates · Coordinates multi-step commerce workflows.
- Inventory API → Services: delegates · Coordinates stock movement and inventory rules.
- Content API → Services: delegates · Coordinates content read/write operations.
- Engagement API → Services: delegates · Coordinates notifications and campaigns.
- Support API → Services: delegates · Coordinates support workflows.
- Ops API → Services: delegates · Coordinates reporting and dashboard workflows.
- Services → Models: persists · Reads and writes MongoDB-backed domain data.
- Services → Auth utils: checks access · Applies role-based permissions where needed.
- Services → Redis config: caches · Uses Redis for cache-aware or coordinated reads.
- Services → Email pipeline: sends mail · Triggers transactional and campaign emails.
- Services → Media utils: uploads media · Handles external media storage interactions.
- Media utils → Cloudinary config: uses · Binds upload helpers to Cloudinary settings.
- Ops API → Analytics client: reports · Feeds Google Analytics-style reporting flows.
- Ops API → Meta sync: syncs · Coordinates Meta sync and insights pipelines.
- Cron jobs → Meta sync: runs · Schedules Meta sync jobs.
- Cron jobs → Analytics client: collects · Schedules analytics collection and aggregation jobs.
- Cron jobs → Services: reuses · Invokes domain services for background workflows.