# vikarnjha/react-smartcardmanager architecture

> Architecture diagram of the GitHub repository vikarnjha/react-smartcardmanager, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vikarnjha/react-smartcardmanager
- Repository: https://github.com/vikarnjha/react-smartcardmanager

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Browser["Browser (React SPA)"]:::frontend
        subgraph "SPA Components"
            RE["React Entry Point\n(main.jsx)"]:::frontend
            APPR["App & Routing\n(App.jsx)"]:::frontend
            AUTHCTX["Global Auth State\n(AuthContext.jsx)"]:::frontend
            UI["UI Components\n(Components/)"]:::frontend
            ICONS["Card Icon Config\n(cardIcons.js)"]:::frontend
            DATA["Initial Card Variant Data\n(cards.json)"]:::frontend
            SPINNER["Loading Spinner\n(Loading.jsx)"]:::frontend
        end
    end

    %% API Server Layer
    subgraph "API Server (Express.js)" 
        S["Server Entry Point\n(server.js)"]:::backend
        subgraph "Configuration & Setup"
            DBCON["Database Connection\n(mongo.js)"]:::backend
            OAUTH["Google OAuth2 Setup\n(passport-setup.js)"]:::backend
        end
        subgraph "Middleware"
            JWTM["JWT Auth Middleware\n(auth.js)"]:::backend
        end
        subgraph "Routes"
            AR["Auth Routes\n(auth.route.js)"]:::backend
            CR["Card CRUD Routes\n(card.route.js)"]:::backend
            CTR["Contact Routes\n(contact.route.js)"]:::backend
            RR["Password Reset Routes\n(reset.route.js)"]:::backend
        end
        subgraph "Controllers & Utilities"
            CTRL["Business Logic Controllers\n(auth.controller.js)"]:::backend
            ENC["AES Encryption Module\n(cryptoUtils.js)"]:::backend
            EMAIL["Email Service Utility\n(email.js)"]:::backend
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        DB["MongoDB"]:::database
        USERS["User Collection"]:::database
        CARDS["Card Collection"]:::database
    end

    %% External Services
    BINAPI["External BIN/IIN API"]:::external
    EMAILEXT["Email Service\n(SMTP/SendGrid)"]:::external

    %% Connections
    Browser -->|"HTTPS"| S
    S -->|Uses| DBCON
    S -->|Loads Routes| AR
    S -->|Loads Routes| CR
    S -->|Loads Routes| CTR
    S -->|Loads Routes| RR

    AR -->|calls| CTRL
    CR -->|calls| CTRL
    CTR -->|calls| CTRL
    RR -->|calls| CTRL

    CTRL -->|encrypt/decrypt| ENC
    CTRL -->|send email| EMAIL
    CTRL -->|DB Read/Write| DB
    CTRL -->|query| USERS
    CTRL -->|query| CARDS

    ENC -->|store encrypted| CARDS
    S -->|verify JWT| JWTM
    OAUTH -->|issue token| S

    CTRL -->|"GET /binlookup"| BINAPI
    CTRL -->|"POST /send-reset"| EMAILEXT

    Browser -->|login/signup| AR
    Browser -->|card CRUD| CR
    Browser -->|password reset| RR
    Browser -->|view cards| CR

    %% Click Events
    click Browser "https://github.com/vikarnjha/react-smartcardmanager/tree/main/frontend/src/"
    click RE "https://github.com/vikarnjha/react-smartcardmanager/blob/main/frontend/src/main.jsx"
    click APPR "https://github.com/vikarnjha/react-smartcardmanager/blob/main/frontend/src/App.jsx"
    click AUTHCTX "https://github.com/vikarnjha/react-smartcardmanager/blob/main/frontend/src/context/AuthContext.jsx"
    click UI "https://github.com/vikarnjha/react-smartcardmanager/tree/main/frontend/src/components/"
    click ICONS "https://github.com/vikarnjha/react-smartcardmanager/blob/main/frontend/src/config/cardIcons.js"
    click DATA "https://github.com/vikarnjha/react-smartcardmanager/blob/main/frontend/src/assets/cards.json"
    click SPINNER "https://github.com/vikarnjha/react-smartcardmanager/blob/main/frontend/src/loading/Loading.jsx"

    click S "https://github.com/vikarnjha/react-smartcardmanager/blob/main/backend/server.js"
    click DBCON "https://github.com/vikarnjha/react-smartcardmanager/blob/main/backend/configs/mongo.js"
    click OAUTH "https://github.com/vikarnjha/react-smartcardmanager/blob/main/backend/passport-setup.js"
    click JWTM "https://github.com/vikarnjha/react-smartcardmanager/blob/main/backend/middleware/auth.js"
    click AR "https://github.com/vikarnjha/react-smartcardmanager/blob/main/backend/routes/auth.route.js"
    click CR "https://github.com/vikarnjha/react-smartcardmanager/blob/main/backend/routes/card.route.js"
    click CTR "https://github.com/vikarnjha/react-smartcardmanager/blob/main/backend/routes/contact.route.js"
    click RR "https://github.com/vikarnjha/react-smartcardmanager/blob/main/backend/routes/reset.route.js"
    click CTRL "https://github.com/vikarnjha/react-smartcardmanager/blob/main/backend/controllers/auth.controller.js"
    click ENC "https://github.com/vikarnjha/react-smartcardmanager/blob/main/backend/utils/cryptoUtils.js"
    click EMAIL "https://github.com/vikarnjha/react-smartcardmanager/blob/main/backend/utils/email.js"

    %% Styles
    classDef frontend fill:#D8B4FE,stroke:#9333EA,color:#000
    classDef backend fill:#BFDBFE,stroke:#2563EB,color:#000
    classDef database fill:#BBF7D0,stroke:#15803D,color:#000
    classDef external fill:#FED7AA,stroke:#EA580C,color:#000
```
