# idityage/blind-chat architecture

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

- Interactive diagram: https://gitdiagram.com/idityage/blind-chat
- Repository: https://github.com/idityage/blind-chat

## Overview

##### Main Components

A. Frontend Layer (Next.js Application):
- Authentication Module
- Chat Interface
- Landing Page Components
- Theme System
- User Management

B. Backend Components:
- Next.js API Routes (Authentication & User Management)
- WebSocket Server (Real-time Communication)
- Database Layer (PostgreSQL with Prisma)
- Email Service (Nodemailer)

**Client Tier**
- Next.js Frontend (Port 3000)
- Public Routes
- Landing Page
- Authentication Pages
- Protected Routes
- Chat Interface

**API Tier**
- Next.js API Routes (Port 3000)
- Authentication APIs
- User Management APIs
- WebSocket Server (Port 8080)
- Socket Manager

**Data Tier**
- PostgreSQL Database
- Email Service

##### Key Interactions to Highlight

- Email notifications (wavy lines)

##### Component Details

Frontend Components (Blue):
- Route structure (/auth, /chat)
- Components like chat interface, forms
- Theme provider and context providers

API Layer (Green):
- API endpoints
- WebSocket connection handling
- Authentication middleware

Database Layer (Yellow):
- Main database tables (Users, Messages)
- Prisma ORM layer
- Email service integration

##### Security & Authentication Flow

A separate section showing:
- JWT token flow
- Email verification process
- Student email validation
- Rate limiting implementation

##### Infrastructure Elements

Deployment-related components:
- Nginx configuration
- Environment configurations
- Database migrations

Use these visual elements:
- 🔒 for security features
- 📧 for email-related components
- 🔄 for real-time features
- 🎨 for UI/theme components

- Different types of connections
- Component groupings

This system design should emphasize the real-time nature of the application while showing how the student authentication and email verification systems are integrated into the overall architecture.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Tier (Port 3000)"]
        FE_Public["Public Routes"]
        FE_Protected["Protected Routes"]
        
        Landing["Landing Page"]:::landing
        Auth["Authentication Pages"]:::auth
        Chat["Chat Interface"]:::chat
        Theme["Theme System"]:::theme
        UserMenu["User Management"]:::user
        
        FE_Public --> Landing
        FE_Public --> Auth
        FE_Protected --> Chat
        FE_Protected --> UserMenu
    end

    subgraph API["API Tier"]
        API_Auth["Authentication APIs"]:::auth
        API_User["User Management APIs"]:::user
        WS["WebSocket Server (Port 8080)"]:::ws
        Socket["Socket Manager"]:::ws
        Security["Security Middleware"]:::security
        
        WS --> Socket
        Security --> API_Auth
        Security --> API_User
    end

    subgraph Data["Data Tier"]
        DB[(PostgreSQL)]:::db
        Prisma["Prisma ORM"]:::db
        Email["Email Service"]:::email
        Config["College Email Config"]:::config
    end

    %% Connections
    Landing --> API_Auth
    Auth --> API_Auth
    Chat --> WS
    UserMenu --> API_User
    
    API_Auth --> Prisma
    API_User --> Prisma
    Socket --> Prisma
    Prisma --> DB
    
    API_Auth --> Email
    Email --> Config

    %% Legend
    classDef landing fill:#e1f5fe,stroke:#01579b
    classDef auth fill:#e8f5e9,stroke:#1b5e20
    classDef chat fill:#f3e5f5,stroke:#4a148c
    classDef theme fill:#fff3e0,stroke:#e65100
    classDef user fill:#e8eaf6,stroke:#1a237e
    classDef ws fill:#fce4ec,stroke:#880e4f
    classDef db fill:#fff8e1,stroke:#f57f17
    classDef email fill:#e0f2f1,stroke:#004d40
    classDef security fill:#ffebee,stroke:#b71c1c
    classDef config fill:#f3e5f5,stroke:#4a148c

    %% Click Events
    click Landing "https://github.com/idityaGE/Blind-Chat/blob/main/nextjs-app/app/page.tsx"
    click Auth "https://github.com/idityaGE/Blind-Chat/tree/main/nextjs-app/app/(auth)"
    click Chat "https://github.com/idityaGE/Blind-Chat/blob/main/nextjs-app/components/chat/chat-interface.tsx"
    click Theme "https://github.com/idityaGE/Blind-Chat/blob/main/nextjs-app/components/provider/theme-provider.tsx"
    click UserMenu "https://github.com/idityaGE/Blind-Chat/blob/main/nextjs-app/components/navbar/UserMenu.tsx"
    click API_Auth "https://github.com/idityaGE/Blind-Chat/tree/main/nextjs-app/app/api/auth"
    click WS "https://github.com/idityaGE/Blind-Chat/tree/main/websocket-server"
    click Socket "https://github.com/idityaGE/Blind-Chat/blob/main/websocket-server/src/services/socketManager.ts"
    click Prisma "https://github.com/idityaGE/Blind-Chat/tree/main/nextjs-app/prisma"
    click Email "https://github.com/idityaGE/Blind-Chat/blob/main/nextjs-app/services/mail/mail.ts"
    click Security "https://github.com/idityaGE/Blind-Chat/blob/main/nextjs-app/middleware.ts"
    click Config "https://github.com/idityaGE/Blind-Chat/blob/main/nextjs-app/config/student-email.config.ts"
```
