# durgesh0108/spectra architecture

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

- Interactive diagram: https://gitdiagram.com/durgesh0108/spectra
- Repository: https://github.com/durgesh0108/spectra

## Overview

##### Project type and purpose
- This is a full-stack e-commerce web application (“Spectra Glasses Website”) built with Node.js, Express, MongoDB/Mongoose, and EJS/Pug for server-side rendering.
- It exposes product listings (glasses), user authentication, bookings/orders, reviews, and payment integration (Stripe via public/js/stripe.js).

##### File structure
- Top-level server: server.js and app.js configure and launch the Express app.
- Controllers: handle incoming HTTP requests (authController, glassController, bookingController, reviewController, userController, viewController, errorController, handlerFactory).
- Routes: map URL endpoints to controllers (routes/*.js).
- Models: Mongoose schemas for Glass, User, Review, Booking.
- Views: Pug/EJS templates for server-rendered pages (views/*.pug, views/*.ejs).
- Public assets: CSS/JS/images under public-1 and public.
- Utils: shared helpers (apiFeatures for query filtering/pagination, catchAsync, appError, email).
- Dev-data: seed scripts and JSON fixtures for development.
- Configuration: .eslintrc.json, .prettierrc, tailwind.config.js.

##### Key insights from README
- Confirms Express/MongoDB/Mongoose stack.
- Fully working e-commerce site (products, users, bookings, reviews, payments, emails).

##### Detail without over-thinking
- Controllers or group them under “Controllers” if space is limited
- Utilities like error handling and API features as sub-components of the Express server

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client and Static Assets
    Client["Browser/Mobile"]:::client
    StaticAssets["Static Assets (CSS/JS/Images)"]:::assets

    %% Express Server
    subgraph "Express Web Server" 
        direction TB
        ServerJS["server.js"]:::services
        AppJS["app.js"]:::services

        subgraph "Routes" 
            direction TB
            ViewRoutes["viewRoutes.js"]:::routes
            UserRoutes["userRoute.js"]:::routes
            GlassRoutes["glassRoute.js"]:::routes
            BookingRoutes["bookingRoute.js"]:::routes
            ReviewRoutes["reviewRoute.js"]:::routes
        end

        subgraph "Controllers" 
            direction TB
            ViewController["viewController.js"]:::controllers
            AuthController["authController.js"]:::controllers
            UserController["userController.js"]:::controllers
            GlassController["glassController.js"]:::controllers
            BookingController["bookingController.js"]:::controllers
            ReviewController["reviewController.js"]:::controllers
            ErrorController["errorController.js"]:::controllers
            HandlerFactory["handlerFactory.js"]:::controllers
        end

        subgraph "Models" 
            direction TB
            UserModel["userModel.js"]:::models
            GlassModel["glassModel.js"]:::models
            BookingModel["bookingModel.js"]:::models
            ReviewModel["reviewModel.js"]:::models
        end

        subgraph "Utils/Shared Services"
            direction TB
            APIFeatures["apiFeatures.js"]:::util
            CatchAsync["catchAsync.js"]:::util
            AppError["appError.js"]:::util
            EmailUtil["email.js"]:::external
        end
    end

    %% Database and External Services
    MongoDB["MongoDB"]:::db
    Stripe["Stripe API"]:::external
    EmailService["SMTP/Email Service"]:::external

    %% Dev Data & Config
    DevData["dev-data & Seed Scripts"]:::config
    ConfigFiles["Configuration Files"]:::config

    %% Connections
    Client -->|"HTTP GET/POST"| ServerJS
    Client -->|loads assets| StaticAssets

    ServerJS --> AppJS
    AppJS --> ViewRoutes
    AppJS --> UserRoutes
    AppJS --> GlassRoutes
    AppJS --> BookingRoutes
    AppJS --> ReviewRoutes

    ViewRoutes --> ViewController
    UserRoutes --> AuthController
    UserRoutes --> UserController
    GlassRoutes --> GlassController
    BookingRoutes --> BookingController
    ReviewRoutes --> ReviewController

    ViewController -->|renders templates| StaticAssets
    AuthController --> UserModel
    UserController --> UserModel
    GlassController --> GlassModel
    BookingController --> BookingModel
    ReviewController --> ReviewModel

    AuthController -->|uses| CatchAsync
    AuthController -->|uses| AppError
    BookingController -->|calls| Stripe
    BookingController --> BookingModel
    ReviewController --> ReviewModel

    HandlerFactory --> GlassController
    HandlerFactory --> UserController
    HandlerFactory --> BookingController
    HandlerFactory --> ReviewController

    APIFeatures --> GlassController
    APIFeatures --> BookingController

    EmailUtil --> EmailService
    AuthController --> EmailUtil

    GlassModel --> MongoDB
    UserModel --> MongoDB
    BookingModel --> MongoDB
    ReviewModel --> MongoDB

    DevData --> MongoDB
    AppJS --> ConfigFiles

    %% Click Events
    click ServerJS "https://github.com/durgesh0108/spectra/blob/main/server.js"
    click AppJS "https://github.com/durgesh0108/spectra/blob/main/app.js"
    click ViewRoutes "https://github.com/durgesh0108/spectra/blob/main/routes/viewRoutes.js"
    click UserRoutes "https://github.com/durgesh0108/spectra/blob/main/routes/userRoute.js"
    click GlassRoutes "https://github.com/durgesh0108/spectra/blob/main/routes/glassRoute.js"
    click BookingRoutes "https://github.com/durgesh0108/spectra/blob/main/routes/bookingRoute.js"
    click ReviewRoutes "https://github.com/durgesh0108/spectra/blob/main/routes/reviewRoute.js"
    click ViewController "https://github.com/durgesh0108/spectra/blob/main/controllers/viewController.js"
    click AuthController "https://github.com/durgesh0108/spectra/blob/main/controllers/authController.js"
    click UserController "https://github.com/durgesh0108/spectra/blob/main/controllers/userController.js"
    click GlassController "https://github.com/durgesh0108/spectra/blob/main/controllers/glassController.js"
    click BookingController "https://github.com/durgesh0108/spectra/blob/main/controllers/bookingController.js"
    click ReviewController "https://github.com/durgesh0108/spectra/blob/main/controllers/reviewController.js"
    click ErrorController "https://github.com/durgesh0108/spectra/blob/main/controllers/errorController.js"
    click HandlerFactory "https://github.com/durgesh0108/spectra/blob/main/controllers/handlerFactory.js"
    click UserModel "https://github.com/durgesh0108/spectra/blob/main/models/userModel.js"
    click GlassModel "https://github.com/durgesh0108/spectra/blob/main/models/glassModel.js"
    click BookingModel "https://github.com/durgesh0108/spectra/blob/main/models/bookingModel.js"
    click ReviewModel "https://github.com/durgesh0108/spectra/blob/main/models/reviewModel.js"
    click APIFeatures "https://github.com/durgesh0108/spectra/blob/main/utils/apiFeatures.js"
    click CatchAsync "https://github.com/durgesh0108/spectra/blob/main/utils/catchAsync.js"
    click AppError "https://github.com/durgesh0108/spectra/blob/main/utils/appError.js"
    click EmailUtil "https://github.com/durgesh0108/spectra/blob/main/utils/email.js"
    click DevData "https://github.com/durgesh0108/spectra/blob/main/dev-data/data/import-dev-data.js"
    click StaticAssets "https://github.com/durgesh0108/spectra/blob/main/public-1/css/style.css"
    click StaticAssets "https://github.com/durgesh0108/spectra/blob/main/public-1/js/alerts.js"
    click StaticAssets "https://github.com/durgesh0108/spectra/blob/main/public-1/js/login.js"
    click StaticAssets "https://github.com/durgesh0108/spectra/blob/main/public-1/js/review.js"
    click StaticAssets "https://github.com/durgesh0108/spectra/blob/main/public-1/js/stripe.js"
    click StaticAssets "https://github.com/durgesh0108/spectra/blob/main/public-1/js/updateSettings.js"
    click ConfigFiles "https://github.com/durgesh0108/spectra/blob/main/.eslintrc.json"

    %% Styles
    classDef services fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef db fill:#90EE90,stroke:#333,stroke-width:1px
    classDef client fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef assets fill:#FFD700,stroke:#333,stroke-width:1px
    classDef util fill:#F0E68C,stroke:#333,stroke-width:1px
    classDef external fill:#FFB6C1,stroke:#333,stroke-width:1px
    classDef controllers fill:#E6E6FA,stroke:#333,stroke-width:1px
    classDef routes fill:#FFDEAD,stroke:#333,stroke-width:1px
    classDef models fill:#98FB98,stroke:#333,stroke-width:1px
    classDef config fill:#F5DEB3,stroke:#333,stroke-width:1px
```
