# shifashah3/workrightsai architecture

> Architecture diagram of the GitHub repository shifashah3/workrightsai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shifashah3/workrightsai
- Repository: https://github.com/shifashah3/workrightsai

## Overview

WorkRightsAI is a multilingual assistant for questions about Pakistani labour law. A user enters a question in the React chat; the frontend posts it to FastAPI, which invokes the chatbot and returns its answer. The documented RAG path retrieves relevant legal-text chunks, formats evidence for the model, and returns a cited response, with safety checks and interaction logging. The repository also includes a legal-corpus preparation and indexing path. Those stages and capabilities are documented, but their wiring is not verified from the sampled source excerpts.

Main entry points: [`chatbot.py`](https://github.com/shifashah3/workrightsai/blob/main/chatbot.py) (RAG chatbot), [`Work Rights AI frontend/src/app/App.tsx`](https://github.com/shifashah3/workrightsai/blob/main/Work%20Rights%20AI%20frontend/src/app/App.tsx) (Chat interface), [`server.py`](https://github.com/shifashah3/workrightsai/blob/main/server.py) (Chat API), [`embeddings.py`](https://github.com/shifashah3/workrightsai/blob/main/embeddings.py) (Embedding indexer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Chat experience"]
  node_app["Chat interface<br/>[App.tsx]"]
  node_chatmessage["Message display<br/>[ChatMessage.tsx]"]
end

subgraph group_answer["Answer service"]
  node_api["Chat API<br/>[server.py]"]
  node_chatbot["RAG chatbot<br/>[chatbot.py]"]
  node_vectorstore[("Legal vector store")]
end

subgraph group_corpus["Legal corpus"]
  node_embeddings["Embedding indexer<br/>[embeddings.py]"]
  node_chunker["Legal chunking<br/>[create_chunks.py]"]
  node_ocr["PDF extraction<br/>[OCR.py]"]
end

subgraph group_operations["Safety and audit"]
  node_guardrails["Safety checks<br/>[guardrails.py]"]
  node_logger["Interaction log<br/>[logger.py]"]
end

node_worker(("Question asker"))
node_legalpdfs["Legal PDFs"]
node_groq{{"Groq LLM"}}

node_worker -->|"asks"| node_app
node_app -->|"posts question"| node_api
node_api -->|"calls ask"| node_chatbot
node_chatbot -->|"retrieves chunks"| node_vectorstore
node_chatbot -->|"generates answer"| node_groq
node_chatbot -->|"checks safety"| node_guardrails
node_chatbot -->|"logs interaction"| node_logger
node_api -->|"returns answer"| node_app
node_app -->|"renders messages"| node_chatmessage
node_legalpdfs -->|"extracts text"| node_ocr
node_ocr -->|"provides text"| node_chunker
node_chunker -->|"provides chunks"| node_embeddings
node_embeddings -->|"indexes chunks"| node_vectorstore

click node_app "https://github.com/shifashah3/workrightsai/blob/main/Work%20Rights%20AI%20frontend/src/app/App.tsx"
click node_chatmessage "https://github.com/shifashah3/workrightsai/blob/main/Work%20Rights%20AI%20frontend/src/app/components/ChatMessage.tsx"
click node_api "https://github.com/shifashah3/workrightsai/blob/main/server.py"
click node_chatbot "https://github.com/shifashah3/workrightsai/blob/main/chatbot.py"
click node_embeddings "https://github.com/shifashah3/workrightsai/blob/main/embeddings.py"
click node_chunker "https://github.com/shifashah3/workrightsai/blob/main/create_chunks.py"
click node_ocr "https://github.com/shifashah3/workrightsai/blob/main/OCR.py"
click node_guardrails "https://github.com/shifashah3/workrightsai/blob/main/guardrails.py"
click node_logger "https://github.com/shifashah3/workrightsai/blob/main/logger.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_chatmessage toneBlue
class node_api,node_chatbot,node_vectorstore toneAmber
class node_embeddings,node_chunker,node_ocr toneMint
class node_guardrails,node_logger toneRose
class node_worker,node_legalpdfs,node_groq toneIndigo
```

## Components

### Chat experience

- [Chat interface](https://github.com/shifashah3/workrightsai/blob/main/Work%20Rights%20AI%20frontend/src/app/App.tsx): `Work Rights AI frontend/src/app/App.tsx`
- [Message display](https://github.com/shifashah3/workrightsai/blob/main/Work%20Rights%20AI%20frontend/src/app/components/ChatMessage.tsx): `Work Rights AI frontend/src/app/components/ChatMessage.tsx`

### Answer service

- [Chat API](https://github.com/shifashah3/workrightsai/blob/main/server.py): `server.py`
- [RAG chatbot](https://github.com/shifashah3/workrightsai/blob/main/chatbot.py): `chatbot.py`
- **Legal vector store**

### Legal corpus

- [Embedding indexer](https://github.com/shifashah3/workrightsai/blob/main/embeddings.py): `embeddings.py`
- [Legal chunking](https://github.com/shifashah3/workrightsai/blob/main/create_chunks.py): `create_chunks.py`
- [PDF extraction](https://github.com/shifashah3/workrightsai/blob/main/OCR.py): `OCR.py`

### Safety and audit

- [Safety checks](https://github.com/shifashah3/workrightsai/blob/main/guardrails.py): `guardrails.py`
- [Interaction log](https://github.com/shifashah3/workrightsai/blob/main/logger.py): `logger.py`

### Other components

- **Question asker**
- **Legal PDFs**
- **Groq LLM**

## Connections

- Question asker → Chat interface: asks
- Chat interface → Chat API: posts question
- Chat API → RAG chatbot: calls ask
- RAG chatbot → Legal vector store: retrieves chunks
- RAG chatbot → Groq LLM: generates answer
- RAG chatbot → Safety checks: checks safety
- RAG chatbot → Interaction log: logs interaction
- Chat API → Chat interface: returns answer
- Chat interface → Message display: renders messages
- Legal PDFs → PDF extraction: extracts text
- PDF extraction → Legal chunking: provides text
- Legal chunking → Embedding indexer: provides chunks
- Embedding indexer → Legal vector store: indexes chunks
