How tiendanube/tiendanube-app-native-template-node works
Project type and purpose
• This is a full-stack monorepo template for building Nuvemshop integrated apps.
• “api” is a Node.js + Express + TypeScript backend that handles authentication, communicates with Nuvemshop’s Auth and Product APIs, and exposes your own REST endpoints.
• “frontend” is a React (Vite) app that provides the UI and calls your backend.
File structure
• Top level:
• .yarn, yarnrc.yml → Yarn Plug’n’Play workspaces
• api/ → backend code, with its own Yarn setup
• frontend/ → React app (monorepo workspace)
• api/:
• src/config → Express setup, routes, Nuvemshop API client configs
• src/features → feature modules (auth, product) organized in controller-service-interface structure
• src/middlewares → request validation, error handling
• src/repository → data persistence (e.g., UserRepository)
• src/utils → exception classes, Passport strategy, HTTP codes
• README cues: uses Passport for OAuth, integrates with Nuvemshop Auth/Product, no local DB by default (db.example.json for sample).
• frontend/: standard React/Vite project linking to api via HTTP calls.
Key insights from README
• Two main pieces: authentication flow (install app on a Nuvemshop store → OAuth flow → store tokens) and product operations (list/create/delete via Nuvemshop API).
• Ports: default frontend localhost:5173, backend via start:api (likely localhost:3000).
Main components
a. Frontend (React/Vite)
b. Backend API (Node.js/Express/TypeScript)
c. External Nuvemshop Services (Auth API, Product API)
d. (Optional) Token Store / Persistence (in-memory or JSON mock)
Relationships and data flows
• Frontend → HTTP(S) → Backend REST endpoints
• Backend → OAuth handshake → Nuvemshop Auth API
• Backend → REST calls → Nuvemshop Product API
• Backend middleware (Passport strategy) secures routes
• Repository layer → stores/retrieves user tokens (mock JSON or real DB)
Architectural patterns & design principles
• Monorepo with Yarn Workspaces: api and frontend share tooling.
• Modular “features” structure in backend → follows MVC-inspired layering:
• Controller → routes
• Service → business logic
• Repository → data access
• Interfaces → strict TypeScript contracts
• Middleware chain for cross-cutting concerns (auth check, error handling).
• Separation of concerns: UI vs API vs external third-party services.
Technologies, frameworks, libraries
• Frontend: React, Vite, Yarn
• Backend: Node.js, Express, TypeScript, Passport (OAuth), Yarn, nodemon
• External: Nuvemshop API clients (tiendanube-api.client.ts, tiendanube-auth.client.ts)
• [ ] Frontend container with pages/components → calls /api/** endpoints
• [ ] Backend container subdivided into layers (config, features, middleware, repository, utils)
• [ ] External Nuvemshop Auth and Product APIs
• [ ] Notes on Yarn workspace linking