# debasys/sharepoint-qna-system architecture

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

- Interactive diagram: https://gitdiagram.com/debasys/sharepoint-qna-system
- Repository: https://github.com/debasys/sharepoint-qna-system

## Overview

##### Project type and purpose
- This is a full-stack, microservices-style Q&A system built for SharePoint Online.
- Frontend: an SPFx (SharePoint Framework) React web part that provides the UI.
- Backend: a Node.js/TypeScript REST API that processes documents, generates semantic embeddings, enforces ACLs, and performs vector search.
- External services: Azure AD for authentication, SharePoint Online (Graph/REST APIs) for document retrieval and ACLs, OpenAI for embeddings, and Pinecone for vector storage.

##### File structure
- Top-level:
- README.md and config.example
- /backend – Express API in TS (index.ts, middleware/, routes/, services/, utils/)
- /spfx-webpart – React SPFx solution (WebPart.tsx, SCSS, manifest, types)
- /backend:
- middleware handles errors and SharePoint auth
- routes split between document processing and search
- services implement logic: document.service.ts (fetches & embeds), search.service.ts (queries Pinecone)
- /spfx-webpart:
- standard SPFx layout under src/webparts/qnaWebPart

##### Extract README insights
- High-level flow described under “Architecture”
- Key integrations: Azure AD, Pinecone, OpenAI, SharePoint ACL enforcement
- Microservice style with clearly separated responsibilities

##### Detail
- Middleware layer intercepting incoming requests for auth and error handling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        UI["SPFx Q&A Web Part\n(React)"]:::frontend
        Styles["QnAWebPart.module.scss"]:::frontend
        Manifest["QnaWebPart.manifest.json"]:::frontend
        Types["QnaWebPart.types.ts"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend API\n(Node.js/Express)" 
        Entry["index.ts"]:::backendComp
        Config["config.example"]:::backendComp
        Pkg["package.json"]:::backendComp
        TSCfg["tsconfig.json"]:::backendComp

        subgraph Middleware
            Err["errorHandler.ts"]:::backendComp
            AuthMW["sharepointAuth.ts"]:::backendComp
        end

        subgraph Routes
            DocRoute["document.routes.ts"]:::backendComp
            SearchRoute["search.routes.ts"]:::backendComp
        end

        subgraph Services
            DocService["document.service.ts"]:::backendComp
            SearchService["search.service.ts"]:::backendComp
        end

        AuthUtil["auth.ts\n(utils)"]:::backendComp
    end

    %% External Services
    AzureAD["Azure AD\n(OAuth2/OpenID)"]:::external
    SPO["SharePoint Online\n(Graph API & ACLs)"]:::external
    OpenAI["OpenAI Embedding API"]:::external
    Pinecone["Pinecone Vector DB"]:::external

    %% Flows
    User(("User")) -->|opens web part| UI
    UI -->|authenticate| AzureAD
    UI -->|GET /api/*\nBearer token| Entry

    Entry --> AuthMW
    Entry --> Err
    AuthMW --> DocRoute
    AuthMW --> SearchRoute
    DocRoute -->|"POST /documents"| DocService
    SearchRoute -->|"GET /search?q="| SearchService

    DocService -->|"download docs"| SPO
    DocService -->|"generate embeddings"| OpenAI
    DocService -->|"upsert vectors"| Pinecone

    SearchService -->|"query vectors"| Pinecone
    SearchService -->|"fetch ACLs"| SPO

    SearchService --> Entry
    Entry -->|return results| UI

    %% Click Events
    click UI "https://github.com/debasys/sharepoint-qna-system/blob/main/spfx-webpart/src/webparts/qnaWebPart/QnaWebPart.tsx"
    click Styles "https://github.com/debasys/sharepoint-qna-system/blob/main/spfx-webpart/src/webparts/qnaWebPart/QnaWebPart.module.scss"
    click Manifest "https://github.com/debasys/sharepoint-qna-system/blob/main/spfx-webpart/src/webparts/qnaWebPart/QnaWebPart.manifest.json"
    click Types "https://github.com/debasys/sharepoint-qna-system/blob/main/spfx-webpart/src/webparts/qnaWebPart/QnaWebPart.types.ts"
    click Entry "https://github.com/debasys/sharepoint-qna-system/blob/main/backend/src/index.ts"
    click Config "https://github.com/debasys/sharepoint-qna-system/blob/main/config.example"
    click Pkg "https://github.com/debasys/sharepoint-qna-system/blob/main/backend/package.json"
    click Err "https://github.com/debasys/sharepoint-qna-system/blob/main/backend/src/middleware/errorHandler.ts"
    click AuthMW "https://github.com/debasys/sharepoint-qna-system/blob/main/backend/src/middleware/sharepointAuth.ts"
    click DocRoute "https://github.com/debasys/sharepoint-qna-system/blob/main/backend/src/routes/document.routes.ts"
    click SearchRoute "https://github.com/debasys/sharepoint-qna-system/blob/main/backend/src/routes/search.routes.ts"
    click DocService "https://github.com/debasys/sharepoint-qna-system/blob/main/backend/src/services/document.service.ts"
    click SearchService "https://github.com/debasys/sharepoint-qna-system/blob/main/backend/src/services/search.service.ts"
    click AuthUtil "https://github.com/debasys/sharepoint-qna-system/blob/main/backend/src/utils/auth.ts"
    click TSCfg "https://github.com/debasys/sharepoint-qna-system/blob/main/backend/tsconfig.json"

    %% Styles
    classDef frontend fill:#D0E7FF,stroke:#0366d6,color:#0366d6;
    classDef backendComp fill:#E6F9E6,stroke:#239823,color:#239823;
    classDef external fill:#FFE6CC,stroke:#D2691E,color:#D2691E;
    class UI,Styles,Manifest,Types frontend
    class Entry,Config,Pkg,TSCfg,Err,AuthMW,DocRoute,SearchRoute,DocService,SearchService,AuthUtil backendComp
    class AzureAD,SPO,OpenAI,Pinecone external
```
