How ajithesh9/one-store works
Project Type & Purpose
• This is a full-stack MERN (MongoDB, Express, React, Node.js) web application called “Watcher.”
• Purpose: Provide parents with device monitoring & control, subscription management (Stripe), user/admin dashboards, and marketing pages.
Main Architectural Layers
a. Client Layer (Frontend)
• Vite-powered React app with React Router DOM for page navigation.
• React Context API for global state (AuthContext, CartContext).
• UI components and pages (Login, Dashboard, AdminDashboard, Cart, Payment, marketing pages).
• Stripe Elements integration for payments.
• Dev proxy (/api → localhost:5000) configured in vite.config.js.
b. Application Layer (Backend API)
• Node.js + Express.js REST API.
• MVC pattern:
– Routes (userRoutes, orderRoutes, paymentRoutes)
– Middleware (authMiddleware: protect, admin)
– Controllers (userController, orderController, paymentController)
– Models (User, Order via Mongoose)
• Security: JWT auth, Bcrypt password hashing, CORS, dotenv.
c. Data Layer
• MongoDB (hosted locally or Atlas) accessed via Mongoose ODM.
• Schemas: User (with isAdmin flag), Order (line items, payment status).
d. External Services
• Stripe API (payment intent creation & confirmation).
• Optional: CDN or static asset hosting for front-end build, email or analytics (not in code).
Component Interactions & Data Flow
• User Browser → HTTP(S) → Frontend React App
• React App → /api/... fetch calls → Express Server
• Auth flows: POST /api/users & /api/users/login → userController → User model → DB
• Order flows: POST /api/orders, GET /api/orders/myorders, GET /api/orders (admin) → orderController → Order model → DB
• Payment flow: POST /api/payment/create-payment-intent → paymentController → Stripe SDK → returns clientSecret
• Express Server ↔ MongoDB (read/write)
• Stripe SDK ↔ Stripe Cloud
• React Stripe Elements uses clientSecret to complete payment, then calls /api/orders to persist the order
Key Architectural Patterns & Principles
• Separation of Concerns:
• Frontend handles presentation, routing, state management, and Stripe Elements.
• Backend handles authentication, business logic, data validation, and database access.
• Layered Architecture: clear client → API → database layers.
• MVC on the server: keeps controllers lean, models reusable, routes declarative.
• Context-based state management on the client: isolates auth and cart logic.
• Protected routes (frontend) and protected endpoints (backend) enforce security via JWT.
Essential Elements
• Component labels with technology (e.g., “AuthContext (React Context)”).
• Annotations for key flows: Authentication flow, Purchase & Order flow, Admin analytics flow.