How giozulber/frontend-api-coder works
Project type and purpose
• This is a full-stack e-commerce application’s frontend, built with React and TypeScript.
• Purpose: Allow users to register, log in (with JWT), browse and manage products, add items to a shopping cart, and for admins to create/update/delete products.
File structure
• src/App.tsx and src/main.tsx: application entry point and root component.
• src/components: UI broken down into Feature Folders:
• Form (Login, Register, PostProducts)
• Home (public Home, UserHome)
• Navbar
• Products (list, item, service)
• User (user details, userService)
• cart (Cart, CartItem, cartService, types)
• src/context: React Context providers for user and cart state (cartContext.tsx, userContext.tsx).
• src/utils/UserGuard.tsx: route protection component.
• src/styles: theming (theme.ts via Chakra UI).
• Services: separate files that wrap Axios calls for products, users, cart.
• Config: tsconfig, vite.config.ts for build tooling.
README
• Confirms technologies: Chakra UI for design, Axios for HTTP, JSON Web Token for authentication.
• Backend is a separate Vercel-hosted API at https://ecommerce-app-coder.vercel.app/.
• Frontend hosted on Vercel.
Main components and their interactions
a. Frontend Client (browser)
• UI Tier: React Components (Forms, Navbar, Home, Products, Cart)
• State Tier: React Context providers (UserContext, CartContext)
• Utils: Route protection (UserGuard)
• Services: productService, userService, cartService (wrap Axios calls)
b. API Gateway / Backend Microservice (external)
• Authentication Endpoints (login, register, JWT verification)
• Product Endpoints (CRUD)
• Cart Endpoints (add, remove, list)
c. Database (external to backend)
• Users table (with roles)
• Products table
• Orders/Cart table
d. External Services
• Vercel for hosting
• JSON Web Token provider/logic
Relationships and data flows
• User submits login/register form → userService (Axios) → Backend Auth API → returns JWT → stored in UserContext.
• Browsing Products: on UserHome mount, productService GET → Backend Products API → returns product list → stored in local state.
• Adding to Cart: Cart component calls cartService POST → Backend Cart API → updates cart in database → CartContext updates local state.
• Admin actions (PostProducts): Admin form → productService POST/PUT/DELETE → Backend Products API → updates products in database.
• Protected routes: UserGuard reads JWT from UserContext → allows or denies navigation.
• Theme and layout provided by Chakra UI, wrapped in App.tsx.
Architectural patterns and design principles
• Component-based architecture (feature folders).
• Context API for global state (single source of truth for user and cart).
• Services layer abstracts HTTP calls.
• Separation of concerns: UI vs state vs network.
• JWT-based authentication and role-based access (admin vs user).
• Vite as module bundler for fast HMR.