# yssf132/sheet2db-internship architecture

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

- Interactive diagram: https://gitdiagram.com/yssf132/sheet2db-internship
- Repository: https://github.com/yssf132/sheet2db-internship

## Overview

##### Project type and purpose
- Full-stack web application (“Sheet2DB”) for importing Excel/CSV into MongoDB.
- Provides file upload, preview, validation, column selection, batch import, and JWT-based authentication.

##### File structure
- Top‐level dirs:
– “frontend”: React 18 + TypeScript + Vite + Tailwind CSS + Axios + context/hooks/services/pages/components.
– “backend”: Node.js + Express + TypeScript + Mongoose + Multer + JWT. Follows an MVC-style layout:
· config (DB connection)
· controllers (Auth, Upload, Import, Preview, Ping)
· middleware (auth, validation, upload)
· routes
· services (DatabaseService, ImportService)
· models (User, ImportTypes)
· utils (ParseUtils, JWT utils, constants).
- Config files: .env, tsconfig.json, package.json, Vite config.

##### Extract architecture notes from README
- HTTP/REST interface from React Client ↔ Express Server.
- MongoDB (via Mongoose) as primary datastore.
- JWT for authentication; Multer for file handling.
- Workflow: Upload → Preview/Validate → Column Selection → Import → DB insertion.

##### Architectural patterns & design principles
- Frontend: component‐based + context + hooks (state management)
- Backend: MVC or layered architecture (controllers → services → models)
- Stateless auth (JWT)
- File‐upload pipeline: Multer → parse utils → validation → DB insertion
- Separation of concerns: UI vs API vs DB

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer" 
        direction TB
        ReactApp["React App\n(App.tsx)"]:::frontend
        LoginPage["Login Page"]:::frontend
        RegisterPage["Register Page"]:::frontend
        HomePage["Home Page"]:::frontend
        FileUploadComp["FileUpload Component"]:::frontend
        FilePreviewComp["FilePreview Component"]:::frontend
        ColumnSelectorComp["ColumnSelector Component"]:::frontend
        ImportSummaryComp["ImportSummary Component"]:::frontend
        ProtectedRouteComp["ProtectedRoute Component"]:::frontend
        ToastComp["Toast Notifications"]:::frontend
        LayoutComp["Layout & Navbar"]:::frontend
        AuthContext["AuthContext"]:::frontend
        FileUploadContext["FileUploadContext"]:::frontend
        useAuthHook["useAuth Hook"]:::frontend
        AuthService["authService"]:::frontend
        UploadService["uploadService"]:::frontend
        PreviewService["previewService"]:::frontend
        ProcessService["processService"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express.js + TypeScript)" 
        direction TB
        Server["Server Bootstrap\n(server.ts)"]:::backend
        AppSetup["Express App Setup\n(app.ts)"]:::backend
        ConfigDB["DatabaseService\n(config/db.ts)"]:::backend
        subgraph "Routes"
            direction TB
            AuthRoutes["AuthRoutes"]:::backend
            UploadRoutes["UploadRoutes"]:::backend
            PreviewRoutes["PreviewRoutes"]:::backend
            ImportRoutes["ImportRoutes"]:::backend
            PingRoutes["PingRoutes"]:::backend
        end
        subgraph "Controllers"
            direction TB
            AuthController["AuthController"]:::backend
            UploadController["UploadController"]:::backend
            PreviewController["PreviewController"]:::backend
            ImportController["ImportController"]:::backend
            PingController["PingController"]:::backend
        end
        subgraph "Middleware"
            direction TB
            AuthMiddleware["JWT Auth Middleware"]:::backend
            ValidationMiddleware["Validation Middleware"]:::backend
            UploadMiddleware["Multer Upload Middleware"]:::backend
        end
        subgraph "Services"
            direction TB
            DatabaseService["DatabaseService"]:::backend
            ImportService["ImportService"]:::backend
        end
        subgraph "Models"
            direction TB
            UserModel["User Model"]:::backend
            ImportTypesModel["ImportTypes Model"]:::backend
        end
        subgraph "Utilities"
            direction TB
            ParseUtils["ParseUtils"]:::backend
            JWTUtils["JWT Utils"]:::backend
            Constants["Constants"]:::backend
        end
    end

    %% Database Layer
    MongoDB["MongoDB"]:::database

    %% External Dependencies
    NPM["NPM Packages"]:::external

    %% Frontend to Backend HTTP calls
    ReactApp -->|1. POST /auth| AuthRoutes
    ReactApp -->|2. POST /upload| UploadRoutes
    ReactApp -->|3. GET /preview| PreviewRoutes
    ReactApp -->|4. POST /import| ImportRoutes

    %% Backend request flow
    Server --> AppSetup
    AppSetup --> ConfigDB
    AppSetup --> AuthRoutes
    AppSetup --> UploadRoutes
    AppSetup --> PreviewRoutes
    AppSetup --> ImportRoutes
    AppSetup --> PingRoutes

    AuthRoutes -->|uses| AuthController
    UploadRoutes -->|uses| UploadMiddleware
    UploadRoutes -->|uses| UploadController
    PreviewRoutes --> PreviewController
    ImportRoutes --> ValidationMiddleware
    ImportRoutes --> ImportController
    PingRoutes --> PingController

    AuthController -->|calls| DatabaseService
    UploadController --> ParseUtils
    UploadController --> ImportService
    PreviewController --> ParseUtils
    ImportController --> ImportService

    ImportService --> DatabaseService
    ImportService --> Constants
    ImportService --> ParseUtils

    DatabaseService --> UserModel
    DatabaseService --> ImportTypesModel

    %% Auth Middleware Flow
    AuthMiddleware -.-> AuthRoutes
    AuthMiddleware -.-> ImportRoutes

    %% Database storage
    ImportService --> MongoDB
    DatabaseService --> MongoDB

    %% External dependencies
    AppSetup --> NPM
    ReactApp --> NPM

    %% Click Events Frontend
    click ReactApp "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/App.tsx"
    click LoginPage "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/pages/LoginPage.tsx"
    click RegisterPage "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/pages/RegisterPage.tsx"
    click HomePage "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/pages/Home.tsx"
    click FileUploadComp "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/components/FileUpload.tsx"
    click FilePreviewComp "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/components/filePreview.tsx"
    click ColumnSelectorComp "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/components/ColumnSelector.tsx"
    click ImportSummaryComp "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/components/ImportSummary.tsx"
    click ProtectedRouteComp "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/components/ProtectedRoute.tsx"
    click ToastComp "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/components/elements/Toast.tsx"
    click LayoutComp "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/components/Layout.tsx"
    click NavbarComp "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/components/Navbar.tsx"
    click AuthContext "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/context/AuthContext.tsx"
    click FileUploadContext "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/context/FileUploadContext.tsx"
    click useAuthHook "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/hooks/useAuth.ts"
    click AuthService "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/services/authService.ts"
    click UploadService "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/services/uploadService.ts"
    click PreviewService "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/services/previewService.ts"
    click ProcessService "https://github.com/yssf132/sheet2db-internship/blob/main/frontend/src/services/processService.ts"

    %% Click Events Backend
    click Server "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/server.ts"
    click AppSetup "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/app.ts"
    click ConfigDB "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/config/db.ts"
    click AuthRoutes "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/routes/AuthRoutes.ts"
    click UploadRoutes "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/routes/UploadRoutes.ts"
    click PreviewRoutes "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/routes/PreviewRoutes.ts"
    click ImportRoutes "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/routes/ImportRoutes.ts"
    click AuthController "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/controllers/AuthController.ts"
    click UploadController "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/controllers/UploadController.ts"
    click PreviewController "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/controllers/PreviewController.ts"
    click ImportController "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/controllers/ImportController.ts"
    click PingController "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/controllers/PingController.ts"
    click AuthMiddleware "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/middleware/auth.ts"
    click ValidationMiddleware "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/middleware/validation.ts"
    click UploadMiddleware "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/middleware/UploadMiddleware.ts"
    click DatabaseService "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/services/DatabaseService.ts"
    click ImportService "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/services/ImportService.ts"
    click UserModel "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/models/User.ts"
    click ImportTypesModel "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/models/ImportTypes.ts"
    click ParseUtils "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/utils/ParseUtils.ts"
    click JWTUtils "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/utils/jwt.ts"
    click Constants "https://github.com/yssf132/sheet2db-internship/blob/main/backend/src/utils/constants.ts"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#005B96,stroke-width:1px;
    classDef backend fill:#DFF6DD,stroke:#2F8F00,stroke-width:1px;
    classDef database fill:#FFE4C4,stroke:#C47E00,stroke-width:1px,stroke-dasharray: 5 5;
    classDef external fill:#F2F2F2,stroke:#999999,stroke-width:1px;
```
