# mollygit001/summer-mern architecture

> Architecture diagram of the GitHub repository mollygit001/summer-mern, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mollygit001/summer-mern
- Repository: https://github.com/mollygit001/summer-mern

## Overview

##### Project type and purpose
- This is a full-stack MERN-style web application (“MERN Summer Project”).
- Purpose: provide secure authentication (email/password & Google OAuth), role-based user management, link CRUD with click-tracking analytics, and payment/credit subscription workflows. The UI is React + Tailwind, backend is Node/Express + MongoDB.

##### File structure
- Top-level:
- public/ + index.html  → static assets served to client
- src/                 → React UI (components, pages, Redux store, config, utilities)
- server/              → Express API (controllers, routes, middleware, models, services, scripts)
- config files: vite.config.js, eslint.config.js
- server/src follows an MVC-style layering:
- routes → map endpoints to controllers
- middleware → auth, authorization, validation
- controller → business logic entrypoints organized by domain (auth, user, links, payments)
- services → helper modules (emailService)
- model → Mongoose schemas (Users, Links, Clicks)
- constants/utilities
- Client src uses Redux Toolkit (features/form), React Router (ProtectedRoute, Can), and component-based pages/layouts.

##### Insights from the README
- Key architectural points:
- JWT in HTTP-only cookies for auth
- Role-based access control
- Google OAuth & Payments (likely Stripe or similar via server/paymentController)
- Two .env contexts (client vs server)
- Tech Stack: React, Redux Toolkit, Tailwind, Express, MongoDB, Mongoose, bcryptjs, Google OAuth, ESLint

a. Main components
- Client (Browser/React + Vite Dev Server)
- API Server (Node.js + Express)
- Authentication Service (JWT issuance, Google OAuth flow)
- Business Domain Services (UserService, LinkService, PaymentService, EmailService)
- Data Layer (MongoDB database)
- External Services
- Google OAuth Provider
- Email Provider (SMTP/SendGrid)
- Payment Gateway (Stripe/PayPal)
b. Relationships & interactions
1. User → Browser UI → Redux → React components → Axios HTTP calls →
2. Express API Routes → Auth Middleware → Controller → Service → Model → MongoDB
3. AuthController ↔ JWT issuance & cookie set
4. authController ↔ Google OAuth external flow
5. paymentController ↔ Payment Gateway external API
6. emailService ↔ Email Provider API
7. analytics: Link clicks increment Clicks collection
c. Architectural patterns
- Layered Architecture (Client / API Layer / Service Layer / Data Layer)
- MVC-style on server
- Redux for client-side state management
- RBAC implemented via middleware (authorizeMiddleware, Can component)
- Separation of concerns: controllers vs services vs models
d. Key technologies
- Frontend: React, Redux Toolkit, React Router, Tailwind CSS, Vite
- Backend: Express, Mongoose, JWT, bcryptjs, dotenv
- Database: MongoDB
- External: Google OAuth, SMTP or transactional email, Payment Gateway

##### Detailed capture of architectural elements
- Single MongoDB instance behind all models.
- Call out RBAC: authorizeMiddleware on server + ProtectedRoute/Can on client.
- Click-tracking: Link redirect endpoint increments Clicks model.

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "Client Side"
    direction TB
    Browser["Browser UI\n(React + Vite)"]:::frontend
    Components["UI Components & Layouts"]:::frontend
    click Components "https://github.com/mollygit001/summer-mern/tree/main/src/components/"
    Pages["Pages"]:::frontend
    click Pages "https://github.com/mollygit001/summer-mern/tree/main/src/components/pages/"
    Redux["Redux Store"]:::frontend
    click Redux "https://github.com/mollygit001/summer-mern/blob/main/src/app/store.js"
    FormSlice["formSlice"]:::frontend
    click FormSlice "https://github.com/mollygit001/summer-mern/blob/main/src/features/form/formSlice.js"
    Router["React Router\n(ProtectedRoute/Can)"]:::frontend
    ProtectedRoute["ProtectedRoute.jsx"]:::frontend
    click ProtectedRoute "https://github.com/mollygit001/summer-mern/blob/main/src/rbac/ProtectedRoute.jsx"
    CanComp["Can.jsx"]:::frontend
    click CanComp "https://github.com/mollygit001/summer-mern/blob/main/src/rbac/Can.jsx"
    Permissions["permissions.js"]:::frontend
    click Permissions "https://github.com/mollygit001/summer-mern/blob/main/src/rbac/permissions.js"
    Config["Tailwind & Vite Config"]:::frontend
    click Config "https://github.com/mollygit001/summer-mern/blob/main/src/index.css"
    click Config "https://github.com/mollygit001/summer-mern/blob/main/vite.config.js"
  end

  Browser --> Components --> Pages
  Pages --> Redux --> FormSlice
  Redux --> Router
  Router --> ProtectedRoute
  Router --> CanComp
  Router --> Permissions
  Browser -->|"HTTP Requests"| API["API Endpoint\n(server/index.js)"]:::backend
  click API "https://github.com/mollygit001/summer-mern/blob/main/server/index.js"

  subgraph "Server Side"
    direction TB
    Entry["Entry Point\n(server/index.js)"]:::backend
    entryRoutes["Routes"]:::backend
    AR["authRoutes.js"]:::backend
    click AR "https://github.com/mollygit001/summer-mern/blob/main/server/src/routes/authRoutes.js"
    UR["userRoutes.js"]:::backend
    click UR "https://github.com/mollygit001/summer-mern/blob/main/server/src/routes/userRoutes.js"
    LR["linkRoutes.js"]:::backend
    click LR "https://github.com/mollygit001/summer-mern/blob/main/server/src/routes/linkRoutes.js"
    PR["paymentRoutes.js"]:::backend
    click PR "https://github.com/mollygit001/summer-mern/blob/main/server/src/routes/paymentRoutes.js"

    MW["Middleware"]:::backend
    AuthMW["authMiddleware.js"]:::backend
    click AuthMW "https://github.com/mollygit001/summer-mern/blob/main/server/src/middleware/authMiddleware.js"
    AuthorizeMW["authorizeMiddleware.js"]:::backend
    click AuthorizeMW "https://github.com/mollygit001/summer-mern/blob/main/server/src/middleware/authorizeMiddleware.js"
    ValMW["validators.js"]:::backend
    click ValMW "https://github.com/mollygit001/summer-mern/blob/main/server/src/middleware/validators.js"

    Ctrl["Controllers"]:::backend
    AuthCtrl["authController.js"]:::backend
    click AuthCtrl "https://github.com/mollygit001/summer-mern/blob/main/server/src/controller/authController.js"
    UserCtrl["UserController.js"]:::backend
    click UserCtrl "https://github.com/mollygit001/summer-mern/blob/main/server/src/controller/UserController.js"
    LinkCtrl["linksController.js"]:::backend
    click LinkCtrl "https://github.com/mollygit001/summer-mern/blob/main/server/src/controller/linksController.js"
    PayCtrl["paymentController.js"]:::backend
    click PayCtrl "https://github.com/mollygit001/summer-mern/blob/main/server/src/controller/paymentController.js"

    Svc["Services & Utilities"]:::backend
    EmailSvc["emailService.js"]:::backend
    click EmailSvc "https://github.com/mollygit001/summer-mern/blob/main/server/src/services/emailService.js"
    LinksUtil["linksUtility.js"]:::backend
    click LinksUtil "https://github.com/mollygit001/summer-mern/blob/main/server/utilities/linksUtility.js"

    Models["Models"]:::backend
    UserModel["Users.js"]:::backend
    click UserModel "https://github.com/mollygit001/summer-mern/blob/main/server/src/model/Users.js"
    LinkModel["Links.js"]:::backend
    click LinkModel "https://github.com/mollygit001/summer-mern/blob/main/server/src/model/Links.js"
    ClickModel["Clicks.js"]:::backend
    click ClickModel "https://github.com/mollygit001/summer-mern/blob/main/server/src/model/Clicks.js"

    Entry --> entryRoutes
    entryRoutes --> AR
    entryRoutes --> UR
    entryRoutes --> LR
    entryRoutes --> PR
    AR --> MW
    UR --> MW
    LR --> MW
    PR --> MW
    MW --> Ctrl
    Ctrl --> Svc
    Svc --> Models
    Models --> DB
  end

  API --> Entry
  DB["MongoDB\n(Database)"]:::database

  subgraph "External Services"
    direction TB
    Google["Google OAuth"]:::external
    EmailProv["Email Provider"]:::external
    PayGW["Payment Gateway"]:::external
  end

  AuthCtrl -->|OAuth Flow| Google
  EmailSvc -->|SMTP/API| EmailProv
  PayCtrl -->|API Calls| PayGW
  AuthCtrl -.->|Set JWT cookie| Browser

  classDef frontend fill:#E0F7FA,stroke:#006064,color:#004D40
  classDef backend fill:#E8F5E9,stroke:#1B5E20,color:#2E7D32
  classDef database fill:#FFF3E0,stroke:#E65100,color:#BF360C
  classDef external fill:#EDE7F6,stroke:#4A148C,color:#4A148C
```
