# mdhruvil/tuto architecture

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

- Interactive diagram: https://gitdiagram.com/mdhruvil/tuto
- Repository: https://github.com/mdhruvil/tuto

## Overview

##### Main System Components

a) Frontend Layer (Web Application)
- React-based SPA with Vite
- Authentication UI components
- Knowledge Base Management interface
- Chat interface
- Document Management interface

b) Backend Layer (API)
- Cloudflare Workers-based API
- Authentication service
- Document processing service
- AI/Chat service
- Database queries layer

c) External Services
- Neon Database (with pg_vector)
- Azure OpenAI
- Cloudflare (hosting/deployment)

##### Component Relationships

a) Client-Server Communication
- RESTful API routes between frontend and backend
- WebSocket/real-time connections for chat functionality

b) Data Flow
- Document upload flow
- Chat message flow
- Knowledge base management flow
- Authentication flow

##### Detailed Component Breakdown

Frontend (apps/web):
**┌─ Web Application ─────────────────┐**
- Auth Module                    │
- Knowledge Base Management      │
- Document Viewer/Manager        │
- Chat Interface                 │
- User Profile Management        │
- ┘

Backend (apps/api):
**┌─ API Layer ──────────────────────┐**
- Auth Middleware               │
- Route Handlers                │
- Document Processing           │
- AI Integration               │
- Database Operations          │
- ┘

##### Technical Stack Indicators

Technology choices:
- HONC stack components
- Vite/React frontend
- Cloudflare Workers
- pg_vector enabled Neon Database
- Azure OpenAI integration

##### Data Flow Patterns

Key flows:
**User → Upload Document → Processing → Vector Storage**
**User → Chat Query → Vector Search → AI Processing → Response**

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend["Frontend Layer"]
        direction TB
        Auth["Authentication UI"]
        KBM["Knowledge Base Management"]
        Chat["Chat Interface"]
        DocMgmt["Document Management"]
        Profile["User Profile"]
        APIInt["Frontend API Integration"]
    end

    subgraph Backend["Backend Layer"]
        direction TB
        AuthService["Authentication Service"]
        DocProcess["Document Processing"]
        AIService["AI/Chat Service"]
        DBOps["Database Operations"]
        Routes["API Routes"]
    end

    subgraph External["External Services"]
        direction TB
        NeonDB[(Neon Database<br/>with pg_vector)]
        AzureAI["Azure OpenAI"]
        CF["Cloudflare"]
    end

    %% Frontend to Backend Connections
    Auth --> AuthService
    KBM --> Routes
    Chat --> Routes
    DocMgmt --> Routes
    Profile --> Routes
    APIInt --> Routes

    %% Backend Internal Connections
    Routes --> AuthService
    Routes --> DocProcess
    Routes --> AIService
    Routes --> DBOps
    
    %% Backend to External Connections
    DBOps --> NeonDB
    AIService --> AzureAI
    Backend --> CF

    %% Data Flow
    DocProcess --> DBOps
    AIService --> DBOps

    %% Styling
    classDef frontend fill:#3498db,color:white
    classDef backend fill:#2ecc71,color:white
    classDef external fill:#f1c40f,color:black
    classDef security fill:#e74c3c,color:white
    classDef ai fill:#9b59b6,color:white

    class Auth,KBM,Chat,DocMgmt,Profile,APIInt frontend
    class AuthService,DocProcess,Routes,DBOps backend
    class AIService ai
    class NeonDB,AzureAI,CF external

    %% Click Events
    click Auth "https://github.com/mdhruvil/tuto/tree/master/apps/web/src/routes/auth"
    click KBM "https://github.com/mdhruvil/tuto/blob/master/apps/web/src/routes/dashboard/knowledge-bases.tsx"
    click Chat "https://github.com/mdhruvil/tuto/blob/master/apps/web/src/components/chat-message.tsx"
    click DocMgmt "https://github.com/mdhruvil/tuto/blob/master/apps/web/src/components/document-drawer.tsx"
    click Profile "https://github.com/mdhruvil/tuto/blob/master/apps/web/src/components/user-profile-button.tsx"
    click AuthService "https://github.com/mdhruvil/tuto/blob/master/apps/api/src/lib/auth.ts"
    click AIService "https://github.com/mdhruvil/tuto/blob/master/apps/api/src/lib/ai.ts"
    click DocProcess "https://github.com/mdhruvil/tuto/blob/master/apps/api/src/routes/document.ts"
    click DBOps "https://github.com/mdhruvil/tuto/blob/master/apps/api/src/db/schema.ts"
    click Routes "https://github.com/mdhruvil/tuto/tree/master/apps/api/src/routes"
    click APIInt "https://github.com/mdhruvil/tuto/blob/master/apps/web/src/lib/api.ts"
```
