# bilal-akag/gen_ai architecture

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

- Interactive diagram: https://gitdiagram.com/bilal-akag/gen_ai
- Repository: https://github.com/bilal-akag/gen_ai

## Overview

##### Main Components
- Frontend (Client Side):
- The public folder contains the static assets.
- Subdirectories like auth, chat, modal, navigation, profile, and streaming suggest modularized JavaScript components handling different aspects of the UI and client functionality.
- Backend (Server Side):
- The server folder includes the main application entry point (server/index.js) that processes requests.
- It is responsible for business logic, authentication, and interaction with the database.
- Database:
- MySQL database based on the server/database.sql file, which stores user data, chat histories, and other persistent data.
- External Service:
- An external component representing Cohere’s AI API that provides the intelligent responses for the chatbot.

##### Relationships and Interactions
- The browser loads the frontend assets (HTML, CSS, and JavaScript) which takes care of the user interface.
- The frontend makes API calls to the backend server hosted on Node.js. These calls manage user authentication, sending and receiving chat messages, and retrieving or updating chat history.
- The backend interacts with the MySQL database, reading and writing user details and chat logs.
- When processing chat requests, the backend communicates with the external Cohere API to utilize AI capabilities, relaying the processed responses back to the frontend.

##### Architectural Patterns and Design Principles
- Client-Server Architecture: Clearly separate responsibilities between the presentation layer (frontend) and business/data handling layers (backend with database interactions).
- Modular Design: The public folder’s structure suggests a modular approach to client-side functionality, where each module (authentication, chat, etc.) acts as a distinct component.
- Security: Inclusion of authentication mechanisms (JWT token management per .env file configs) and secure API handling.
- External API Integration: Delegation of AI responses to an external service (Cohere).

##### Relevant Technologies, Frameworks, and Libraries
- Node.js for the server.
- MySQL for the database.
- Plain JavaScript for the frontend with modularized scripts for different UI elements.
- Environment configuration using .env variables.
- External API integration with Cohere.

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User Browser"]:::user

    subgraph "Frontend (Client Side)"
        FE_Static["Static Assets (public)"]:::frontend
        FE_Auth["Authentication Module"]:::frontend
        FE_Chat["Chat Module"]:::frontend
        FE_Modal["Modal Module"]:::frontend
        FE_Nav["Navigation Module"]:::frontend
        FE_Profile["Profile Module"]:::frontend
        FE_Stream["Streaming Module"]:::frontend
    end

    subgraph "Backend (Server Side)"
        BE_Server["Node.js Server"]:::backend
    end

    DB["MySQL Database"]:::database
    EX["External Service (Cohere API)"]:::external

    %% Connections
    User -->|"loads"| FE_Static
    FE_Static -->|"APIcalls"| BE_Server

    FE_Auth -->|"APIcalls"| BE_Server
    FE_Chat -->|"APIcalls"| BE_Server
    FE_Modal -->|"APIcalls"| BE_Server
    FE_Nav -->|"APIcalls"| BE_Server
    FE_Profile -->|"APIcalls"| BE_Server
    FE_Stream -->|"APIcalls"| BE_Server

    BE_Server -->|"DBread/write"| DB
    BE_Server -->|"AIprocessing"| EX
    EX -->|"response"| BE_Server

    %% Click Events
    click FE_Static "https://github.com/bilal-akag/gen_ai/tree/master/public/"
    click FE_Auth "https://github.com/bilal-akag/gen_ai/blob/master/public/modules/auth/auth.js"
    click FE_Chat "https://github.com/bilal-akag/gen_ai/blob/master/public/modules/chat/chat.js"
    click FE_Modal "https://github.com/bilal-akag/gen_ai/blob/master/public/modules/modal/modal.js"
    click FE_Nav "https://github.com/bilal-akag/gen_ai/blob/master/public/modules/navigation/navigation.js"
    click FE_Profile "https://github.com/bilal-akag/gen_ai/blob/master/public/modules/profile/profile.js"
    click FE_Stream "https://github.com/bilal-akag/gen_ai/blob/master/public/modules/streaming/stream.js"
    click BE_Server "https://github.com/bilal-akag/gen_ai/blob/master/server/index.js"
    click DB "https://github.com/bilal-akag/gen_ai/blob/master/server/database.sql"
    click EX "https://github.com/bilal-akag/gen_ai/blob/master/.env"

    %% Styles
    classDef user fill:#F3F315,stroke:#333,stroke-width:2px;
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef database fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#943126,stroke-width:2px;
```
