# quynit/connect-work architecture

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

- Interactive diagram: https://gitdiagram.com/quynit/connect-work
- Repository: https://github.com/quynit/connect-work

## Overview

##### Project Type and Purpose
- This is a hybrid monorepo combining:
a) A full-stack enterprise management system (“ConnectWork”) built with a NestJS backend and a Vite/React frontend, plus Firebase for real-time chat/notifications.
b) A standalone Python “ragchatbox” microservice that uses a Retrieval-Augmented Generation (RAG) pipeline (Streamlit UI, FAISS, LangChain, Gemini LLM) to analyze and query internal documents (.docx/.pdf).

##### Main Components
- Frontend (React + TypeScript + Vite + Tailwind + Redux + Firebase)
- Backend API (NestJS + TypeScript + MongoDB + JWT auth + Google Drive integration)
- AI Microservice (“ragchatbox”) (Python + Streamlit UI + FAISS vector store + Gemini 1.5 Pro + LangChain)
- Datastores:
- MongoDB – primary application data (users, projects, tasks, attendance, payroll, etc.)
- Firebase Firestore – real-time chat & notifications
- Firebase Storage – user-uploaded files/images
- Local or cloud file storage – processed documents for RAG service
- External Services:
- Google Generative AI (Gemini) – LLM for answer generation
- FAISS – vector index for similarity search
- Google Drive API – optional file storage/integration

##### Relationships & Data Flows
- User’s browser ↔ Frontend: HTTP(S) for UI, WebSockets (or Firestore listeners) for real-time chat/notifications
- Frontend ↔ Backend REST API:
- Auth endpoints → JWT tokens
- CRUD for recruitment, projects, attendance, payroll, tasks
- File uploads (CVs, attachments)
- Frontend ↔ Firebase Firestore/Storage: real-time chat messages, notifications, image uploads
- Backend ↔ MongoDB: persistent storage via NestJS repositories (Repository pattern)
- Backend ↔ Google Drive (google-drive.service): optional storage of assets
- Frontend or Backend ↔ AI Microservice: HTTP or HTTP-based Streamlit interface for document Q&A
- AI Microservice ↔ FAISS: vector index read/write for document chunks
- AI Microservice ↔ Gemini LLM via LangChain: prompt → model → response

##### Architectural Patterns & Design Principles
- Backend:
- Modular structure (NestJS modules per entity: user, project, task, etc.)
- Controller → Service → Repository layers (standard NestJS / MVC)
- DTOs for input validation and shaping
- Frontend:
- Component hierarchy (layouts, pages, UI components)
- Global state via Redux slices (notifications, auth)
- Contexts for auth
- Microservice:
- RAG pipeline split into extraction, chunking, indexing, query
- Caching via functools.lru_cache for repeated queries
- Separation of Concerns: UI vs business logic vs data access vs AI logic

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Layer
    Browser["User Browser"]:::ui

    %% Frontend Application
    subgraph "Frontend Application" 
        direction TB
        Vite["Vite"]:::frontend
        ReactRouter["React Router"]:::frontend
        ReduxStore["Redux Store"]:::frontend
        AuthContext["AuthContext"]:::frontend
        FirebaseClient["Firebase (Firestore & Storage)"]:::frontend
    end

    %% Backend API
    subgraph "Backend API" 
        direction TB
        NestApp["NestJS Application"]:::backend
        Controllers["Controllers"]:::backend
        Services["Services"]:::backend
        Repos["Repositories"]:::backend
        GoogleDriveSvc["Google Drive Service"]:::backend
    end

    %% AI Microservice
    subgraph "AI Microservice (ragchatbox)"
        direction TB
        StreamlitUI["Streamlit UI"]:::ai
        DocProcessor["Document Processor"]:::ai
        FAISSIndex["FAISS Vector Store"]:::datastore
        LangChainMod["LangChain + Gemini"]:::ai
    end

    %% Datastores & External
    subgraph "Datastores & External Services"
        direction TB
        MongoDB["MongoDB"]:::datastore
        Firestore["Firebase Firestore"]:::datastore
        StorageFS["Firebase Storage"]:::datastore
        FAISSStore["FAISS Index"]:::datastore
        Gemini["Gemini LLM"]:::external
        GoogleDrive["Google Drive API"]:::external
    end

    %% Connections
    Browser -->|"HTTP(S) UI"| Vite
    Browser -->|WebSocket / Firestore Listeners| FirebaseClient

    Vite -->|"REST API (JWT)"| NestApp
    FirebaseClient -->|Real-time Chat & Notifications| Firestore
    FirebaseClient -->|Uploads| StorageFS

    NestApp -->|MongoDB Access| MongoDB
    NestApp -->|Optional Storage| GoogleDrive
    NestApp -->|JWT Auth| Controllers

    Vite -->|AuthContext| AuthContext
    Vite -->|Global State| ReduxStore
    Vite -->|Routing| ReactRouter

    NestApp -->|controllers| Controllers
    Controllers -->|call services| Services
    Services -->|use repositories| Repos
    Services -->|use Google Drive| GoogleDriveSvc

    Vite -->|Queries| DocProcessor
    NestApp -->|Triggers Q&A| DocProcessor

    DocProcessor -->|Ingest & Query| FAISSIndex
    DocProcessor -->|Prompt/Response| LangChainMod
    LangChainMod -->|API| Gemini

    %% Click Events
    click Vite "https://github.com/quynit/connect-work/blob/main/frontend/vite.config.ts"
    click ReactRouter "https://github.com/quynit/connect-work/blob/main/frontend/src/App.tsx"
    click ReduxStore "https://github.com/quynit/connect-work/blob/main/frontend/src/redux/store.ts"
    click AuthContext "https://github.com/quynit/connect-work/tree/main/frontend/src/components/"
    click FirebaseClient "https://github.com/quynit/connect-work/blob/main/frontend/src/firebase/config.ts"
    click NestApp "https://github.com/quynit/connect-work/blob/main/backend/src/app.module.ts"
    click Controllers "https://github.com/quynit/connect-work/tree/main/backend/src/controllers/"
    click Services "https://github.com/quynit/connect-work/tree/main/backend/src/services/"
    click Repos "https://github.com/quynit/connect-work/tree/main/backend/src/services/repositories/"
    click GoogleDriveSvc "https://github.com/quynit/connect-work/blob/main/backend/src/services/google-drive.service.ts"
    click DocProcessor "https://github.com/quynit/connect-work/blob/main/ragchatbox/api.py"
    click FAISSIndex "https://github.com/quynit/connect-work/blob/main/ragchatbox/api.py"
    click StreamlitUI "https://github.com/quynit/connect-work/blob/main/ragchatbox/api.py"
    click LangChainMod "https://github.com/quynit/connect-work/blob/main/ragchatbox/api.py"
    click MongoDB "https://github.com/quynit/connect-work/tree/main/backend/src/models/"
    click Firestore "https://github.com/quynit/connect-work/blob/main/frontend/src/firebase/config.ts"
    click StorageFS "https://github.com/quynit/connect-work/blob/main/frontend/src/firebase/config.ts"
    click Gemini "https://github.com/quynit/connect-work/blob/main/ragchatbox/requirements.txt"
    click GoogleDrive "https://github.com/quynit/connect-work/blob/main/backend/src/services/google-drive.service.ts"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0288D1,color:#000;
    classDef frontend fill:#DFFFD0,stroke:#689F38,color:#000;
    classDef backend fill:#FFE0B2,stroke:#FB8C00,color:#000;
    classDef ai fill:#E1BEE7,stroke:#8E24AA,color:#000;
    classDef datastore fill:#EEEEEE,stroke:#9E9E9E,color:#000;
    classDef external fill:#CFD8DC,stroke:#455A64,color:#000;
```
