How vikarnjha/react-smartcardmanager works
Project type and purpose
• SmartCardManager is a full-stack web application whose primary purpose is to securely store, encrypt, and analyze payment card information.
• The frontend is a React + Tailwind CSS single-page application (SPA) served via Vite; the backend is a RESTful API built with Node.js, Express, and MongoDB, with JWT and OAuth2 authentication and AES encryption for card data.
File structure
• Top-level directories:
• backend/ – Express server, configurations (Mongo, passport), routes, controllers, models, middleware, utilities.
• frontend/ – React code, components, assets, context, configuration (Vite, ESLint, Tailwind via CSS files).
• backend:
• server.js – entry point for the API.
• configs/ – database connection (mongo.js).
• passport-setup.js – Google OAuth integration.
• routes/ – separate modules for auth, card CRUD, contacts, reset-password.
• controllers/ – business logic for authentication flows.
• models/ – Mongoose schemas (User, Card).
• middleware/auth.js – JWT verification.
• utils/cryptoUtils.js, utils/email.js – AES encryption/decryption and email OTP/send reset link.
• frontend/src:
• context/AuthContext.jsx – global auth state.
• components/ – UI screens and shared components (Navbar, ProtectedRoute, CardForm, Cards list, Profile, etc.).
• config/cardIcons.js – mapping for card variant detection.
• assets/cards.json – initial card variant data.
• loading/ – loading spinner component.
• main.jsx/App.jsx – bootstrap React app; App.jsx defines routing.
• Deployment/config:
• frontend/vercel.json – deployment on Vercel.
• backend/package.json scripts, possibly for Heroku or Docker (not shown).
README for additional insights
• Layers and tech stack outlined.
• Features: AES encryption, BIN/IIN API calls, Google OAuth, email reset.
• Workflow description clarifies where encryption, API calls, and decryption happen.
a. Main components:
• Client (browser SPA): React + Tailwind CSS.
• Backend Service: Node.js + Express.
• Authentication subsystem:
– JWT token issuance.
– Google OAuth2 integration.
• Encryption module (inside backend): AES routines for card storage.
• MongoDB database: persisting users, encrypted cards, tokens.
• External BIN/IIN Lookup API: HTTP calls for card variant and issuing bank info.
• Email Service (SMTP or third-party, e.g., SendGrid): for password reset.
b. Relationships and interactions:
1. User interacts with SPA over HTTPS.
2. SPA hits /auth endpoints for sign-up/login; back end uses bcrypt and/or Google OAuth.
3. On success, backend returns JWT; SPA stores it in memory or secure storage.
4. For card operations, SPA invokes protected endpoints with JWT in header.
5. Backend middleware verifies JWT.
6. On Create/Update card, backend uses AES to encrypt card number, persists record in MongoDB.
7. Backend extracts BIN, calls external API to enrich data, stores variant and bank name.
8. For forgot password: SPA requests reset, backend generates OTP or link, sends email via email util.
9. SPA submits OTP/link back, backend verifies, allows password change.
10. When SPA requests cards list, backend queries DB, decrypts card numbers, returns JSON.
c. Architectural patterns and principles:
• Layered architecture: presentation (frontend), API layer (Express routes/middleware), business logic (controllers, utils), data layer (models, database).
• Separation of concerns: routes → controllers → models → utils.
• Token-based authentication: stateless JWT.
• Microservice-style modularity (could evolve into separate services).
• Security best practices: AES encryption at rest, HTTPS, OAuth2.
• React, Tailwind CSS
• Express.js, Node.js
• MongoDB (with Mongoose)
• JWT, bcrypt, passport-google-oauth20
• AES encryption library
• External BIN/IIN REST API
• Email service (SMTP/SendGrid)
Final recommendations
• Related components visually to convey separation of concerns.
• Notes on security (e.g., “AES encryption at rest”) and caching if used in future.