How fangel123/tokokita works
Project Type and Purpose
• This is a full-stack e-commerce web application (“TokoKita”) organized as a monorepo with two main subprojects:
• Frontend: React (Vite) SPA deployed on Vercel
• Backend: Node.js + Express API with Prisma ORM and PostgreSQL, deployed on Railway
• Purpose: Connect Sellers and Buyers, display products, manage orders, reviews, likes, and checkout flow (including external shipping API).
File Structure
• Top-level:
• README.md, .gitignore
• client/ → All React code, assets, config, contexts, hooks, pages, components
• server/ → Express app, Prisma schema & migrations, controllers, routes, middleware
• Frontend patterns:
• src/components separated into common, layout, ui
• src/contexts for global state (Auth, Cart, Product)
• src/hooks for reusable logic (API calls, auth, like)
• React Router v6 under src/routes
• Backend patterns:
• src/routes → route definitions per resource (auth, product, order, etc.)
• src/controllers → request handlers following an MVC-light style
• src/middleware → auth checks (JWT, optional)
• prisma/ → schema.prisma, migration history
• Config & scripts:
• client/package.json, vite.config.js, tailwind.config.js
• server/package.json, index.js, .env management via dotenv
Insights from README
• Tech stack summary (React, Tailwind, Framer Motion, Axios, Express, Prisma, PostgreSQL, JWT).
• Features breakdown: public buyer flows (catalog, likes, reviews, cart, checkout) and protected seller dashboard (product and order CRUD, review management).
• Deployment targets and environment variable requirements.
a. Main Components
• User’s Browser (Buyer & Seller roles)
• Frontend SPA (React + Vite):
– UI Components, Layout, Pages
– Context Providers (Auth, Cart, Product)
– React Router (AppRoutes, ProtectedRoute)
– HTTP Client (Axios via useApi & api.js)
• Backend API (Express):
– Routes → Controllers → Services
– Middleware (auth, optionalAuth)
– Prisma ORM → PostgreSQL
• External Service: Shipping API (Komerce/RajaOngkir)
b. Relationships & Interactions
• Browser ↔ Frontend: UI events → Context/Hooks → Axios calls
• Frontend → Backend: RESTful HTTP requests (/api/auth, /api/products, /api/orders…)
• Backend → PostgreSQL: Prisma executes migrations & queries
• Backend → External Shipping API: HTTP calls for cost calculation
• JWT tokens flow: Frontend stores token → attaches to subsequent requests → validated by auth.middleware
c. Architectural Patterns & Principles
• Monorepo separation (client vs server)
• Layered backend (Routes → Controllers → ORM)
• Component-based frontend with Context API for state
• REST API design
• Protected routes and role-based access
• Environment-driven configuration
d. Key Technologies
• React 18, Vite, Tailwind CSS, Framer Motion, Zod, Axios
• Node.js, Express.js, Prisma, PostgreSQL, JWT, bcryptjs, CORS