How leanlag87/catfecito-pern works
Purpose and entry points
CatFecito is a serverless ecommerce system: a React/Vite client consumes an AWS API Gateway-backed Lambda API for catalog, accounts, carts, orders, administration, and payments. Client bootstraps at client/src/main.jsx, composes global UI/auth providers in client/src/app/providers/AppProviders.jsx, and selects pages/guards through client/src/app/routes/AppRoutes.jsx. Backend deployment and HTTP/resource topology begin at serverless.yml.
Client application shell and access control
The SPA owns navigation, protected routes, modal state, and inactivity behavior. Authentication state and role checks are feature-local, while route guards constrain user/admin screens before their data flows execute.
• client/src/features/auth/stores/authStore.js
• client/src/features/auth/hooks/useRequireRole.js
• client/src/app/routes/routeGuards.jsx
Client domain feature boundary
Each major ecommerce domain follows a UI → hooks → service → client-side store pattern. Product browsing/filtering, cart mutation, checkout/order tracking, profiles, and administration are independent feature modules, limiting cross-domain UI coupling.
• client/src/features/products/services/products.service.js
• client/src/features/cart/stores/cartStore.js
• client/src/features/orders/hooks/useOrderCheckout.js
API integration flow
Feature services call a shared HTTP abstraction, configured with API endpoints and environment-derived connectivity. API responses update feature stores and render components; authenticated calls carry the client’s auth context/token. This is the boundary between browser state and the serverless backend.
• client/src/config/apiClient.js
• client/src/config/apiEndpoints.js
• client/src/services/api.js
Lambda API and layered business logic
API Gateway invokes discrete Node.js Lambda handlers. Handlers delegate to services for business rules, then repositories for DynamoDB access, preserving a clear controller/service/data boundary. The Serverless configuration splits endpoint registrations by domain and defines provider concerns such as HTTP API, IAM, CORS, DynamoDB, and S3.
• server/functions/users/orders/createOrder.js
• server/services/order.service.js
• server/repositories/order.repository.js
Identity, authorization, and administration
Registration/login integrate JWT and AWS Cognito helpers; an authorizer protects authenticated API routes. Admin handlers/services separately govern product, category, user, and order management, enforcing the privileged control-plane boundary.
• server/functions/auth/authorizer.js
• server/services/auth.service.js
• server/services/admin/order.service.js
Commerce transaction and payment lifecycle
A customer cart is persisted through cart handlers/services/repository; order creation turns checkout intent into an order, then payment preference creation delegates to MercadoPago. MercadoPago calls the webhook, which queries/updates payment state and the associated order. DynamoDB atomic transactions are the core consistency mechanism; payment handling is an external asynchronous boundary.
• server/functions/users/cart/addToCart.js
• server/functions/payments/createPreference.js
• server/functions/payments/webhook.js
Runtime, infrastructure, and delivery
The backend runs Node.js 20.x on AWS Lambda behind API Gateway, uses DynamoDB for application data, S3 for product images, Cognito for identity, MercadoPago for payment processing, and CloudWatch logging. The React app is containerized and served by Nginx; environment-specific Docker Compose and GitHub Actions pipelines support dev, staging, and production delivery.
• docker/client/Dockerfile
• docker/client/nginx.conf
• .github/workflows/cd-prod.yml
Main entry points: products.service.js Commerce features · serverless.yml Serverless topology · order.service.js Business services · AppRoutes.jsx Routes and pages
Components 25
React client
- Client bootstrap
client/src/main.jsx - Global providers · Composes UI and authentication context.
client/src/app/providers/AppProviders.jsx - Routes and pages
client/src/app/routes/AppRoutes.jsx - Route guards
client/src/app/routes/routeGuards.jsx - Auth state
client/src/features/auth/stores/authStore.js - Role checks
client/src/features/auth/hooks/useRequireRole.js - Commerce features · Products, cart, checkout, profiles, and admin remain feature-local.
client/src/features/products/services/products.service.js - Cart state
client/src/features/cart/stores/cartStore.js - Checkout flow
client/src/features/orders/hooks/useOrderCheckout.js - API client · Adds endpoint configuration and authenticated request context.
client/src/config/apiClient.js
Serverless API
- Serverless topology · Defines HTTP API, IAM, CORS, DynamoDB, and S3 resources.
serverless.yml - Lambda handlers · Domain-specific handlers receive API Gateway requests.
server/functions/users/orders/createOrder.js - Business services · Applies commerce rules and transaction orchestration.
server/services/order.service.js - Repositories
server/repositories/order.repository.js - Auth and authorizer · JWT/Cognito authentication protects API routes.
server/functions/auth/authorizer.js - Admin control plane · Governs privileged product, category, user, and order actions.
server/services/admin/order.service.js - Cart persistence
server/functions/users/cart/addToCart.js - Payment preference · Creates MercadoPago checkout preferences.
server/functions/payments/createPreference.js - Payment webhook · Reconciles asynchronous payment status with orders.
server/functions/payments/webhook.js
AWS runtime
- DynamoDB · Atomic transactions provide order and payment consistency.
- S3 product images
- Amazon Cognito
External services
- MercadoPago · External asynchronous payment boundary.
Delivery
- Nginx client image · Serves the built React application.
docker/client/Dockerfile - Production CD
.github/workflows/cd-prod.yml
Connections 24
- Client bootstrap → Global providers: mounts
- Global providers → Routes and pages: provides context to
- Routes and pages → Route guards: enforces
- Route guards → Auth state: reads session
- Route guards → Role checks: checks roles with
- Routes and pages → Commerce features: renders
- Commerce features → Cart state: updates
- Commerce features → Checkout flow: uses
- Commerce features → API client: calls
- API client → Serverless topology: HTTP API
- Serverless topology → Lambda handlers: registers routes
- Serverless topology → Auth and authorizer: attaches authorizer
- Lambda handlers → Business services: delegates to
- Business services → Repositories: persists through
- Repositories → DynamoDB: reads and writes
- Serverless topology → S3 product images: provisions access
- Auth and authorizer → Amazon Cognito: integrates with
- Lambda handlers → Admin control plane: admin operations
- Cart persistence → Business services: cart rules
- Checkout flow → Payment preference: starts payment
- Payment preference → MercadoPago: creates preference
- MercadoPago → Payment webhook: payment event
- Payment webhook → Business services: updates order state
- Production CD → Nginx client image: builds and deploys