# nihalgound/botly-ai architecture

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

- Interactive diagram: https://gitdiagram.com/nihalgound/botly-ai
- Repository: https://github.com/nihalgound/botly-ai

## Overview

##### Main Components
- Frontend (Presentation) Layer:
- The Next.js-based UI residing in the “src/app” directory. This contains pages for dashboards, authentication (sign-in, sign-up), chatbot, and portals.
- UI components under “src/components” form the visual building blocks (buttons, forms, modals, navbars, etc.).
- Context providers and custom hooks (in “src/context” and “src/hooks”) that manage application state such as authentication, theme, chat, sidebar, and settings.
- Backend / Business Logic Layer:
- The “src/actions” directory contains logic for different functionalities (appointment, auth, bot, conversation, dashboard, mail, payment, settings, Stripe integration, etc.). These can be viewed as controllers or service handlers that process incoming requests.
- Data Layer:
- The “prisma” folder, containing schema.prisma and the related configuration, acts as the ORM layer, allowing the application to interact with a database.
- Utility functions (in “src/lib” and “src/schemas”) support data validation, manipulation, and common database interactions.
- Public & Assets:
- DevOps and Configuration:
- Next.js configurations (next.config.mjs), ESLint settings, Tailwind and PostCSS configurations, package management files, etc., which define how the project is built, linted, and deployed.

##### Relationships and Interactions
- The browser (client) accesses the Next.js application, which renders pages using React components under “src/app” and “src/components.”
- User interactions on the frontend are managed by UI components and handled by custom hooks, which coordinate with context providers.
- Actions (in “src/actions”) serve as the intermediary for processing business logic. For instance, when a user makes an appointment or authenticates, the corresponding action (or controller) is invoked.
- These actions communicate with the database layer using Prisma (managed in “prisma” and “src/lib/prisma.ts”) to create, read, update, or delete data.
- External services (e.g., Stripe for payments, email services, possibly chatbot integrations) are accessed through designated action modules that encapsulate their interfaces.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project cleanly separates UI rendering (React components in the app and components directories) from business logic (actions) and data management (Prisma).
- Modular Design: By grouping similar functionalities (authentication, appointments, dashboard, etc.) into their respective directories in both the “actions” and “app” layers, the project promotes scalability and maintainability.
- API Routing & File-based Routing: Next.js file-based routing in the “src/app” directory defines how pages and API calls are delivered.
- Use of Custom Hooks and Context Providers: Helps maintain a predictable state across the application.

##### Technologies, Frameworks, and Libraries
- Next.js for the frontend framework and server-side rendering.
- React for building UI components.
- Prisma as an ORM for database management.
- Tailwind CSS (configured via tailwind.config.ts) for styling.
- Various integrations (e.g., Stripe, mail services) as indicated by the “src/actions” directory.
- ESLint and PostCSS for code quality and styling processing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    Client["Browser/Client"]:::client

    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Next.js Frontend"]:::frontend
        UI["UI Components"]:::frontend
        CTX["Context Providers"]:::frontend
        HOOKS["Custom Hooks"]:::frontend
        PA["Public Assets"]:::frontend
    end

    %% Business Logic / API Actions
    subgraph "Business Logic / API Actions"
        APPT["Appointment API"]:::backend
        AUTH["Authentication API"]:::backend
        CHAT["Chatbot API"]:::backend
        CONV["Conversation API"]:::backend
        DASH["Dashboard API"]:::backend
        EMAIL["Email API"]:::backend
        MAILER["Mailer API"]:::backend
        PAY["Payment API"]:::backend
        SETT["Settings API"]:::backend
        STRIPE["Stripe API"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        DB["Database (Prisma)"]:::database
        UTIL["Data Utilities"]:::utility
        SCHEMA["Data Schemas"]:::utility
    end

    %% External Integrations
    subgraph "External Integrations"
        EXT_STRIPE["Stripe Service"]:::external
        EXT_EMAIL["Email Provider"]:::external
        EXT_CHAT["Chatbot Integration"]:::external
    end

    %% Connections from Client to Frontend Layer
    Client --> FE

    %% Connections within Frontend Layer
    FE --> UI
    FE --> CTX
    FE --> HOOKS
    FE --> PA

    %% Connection from Frontend to Business Logic / API Actions
    FE --> APPT
    FE --> AUTH
    FE --> CHAT
    FE --> CONV
    FE --> DASH
    FE --> EMAIL
    FE --> MAILER
    FE --> PAY
    FE --> SETT
    FE --> STRIPE

    %% Connections from Business Logic to Data Layer
    APPT --> DB
    AUTH --> DB
    CHAT --> DB
    CONV --> DB
    DASH --> DB
    EMAIL --> DB
    MAILER --> DB
    PAY --> DB
    SETT --> DB
    STRIPE --> DB

    %% Representative connection to Data Utilities & Schemas
    APPT --> UTIL
    UTIL --> SCHEMA

    %% Connections from specific API Actions to External Integrations
    STRIPE --> EXT_STRIPE
    EMAIL --> EXT_EMAIL
    CHAT --> EXT_CHAT

    %% Click Events
    click FE "https://github.com/nihalgound/botly-ai/tree/main/src/app"
    click UI "https://github.com/nihalgound/botly-ai/tree/main/src/components"
    click CTX "https://github.com/nihalgound/botly-ai/tree/main/src/context"
    click HOOKS "https://github.com/nihalgound/botly-ai/tree/main/src/hooks"
    click PA "https://github.com/nihalgound/botly-ai/tree/main/public"
    click APPT "https://github.com/nihalgound/botly-ai/tree/main/src/actions/appointment"
    click AUTH "https://github.com/nihalgound/botly-ai/tree/main/src/actions/auth"
    click CHAT "https://github.com/nihalgound/botly-ai/tree/main/src/actions/bot"
    click CONV "https://github.com/nihalgound/botly-ai/tree/main/src/actions/conversation"
    click DASH "https://github.com/nihalgound/botly-ai/tree/main/src/actions/dashboard"
    click EMAIL "https://github.com/nihalgound/botly-ai/tree/main/src/actions/mail"
    click MAILER "https://github.com/nihalgound/botly-ai/tree/main/src/actions/mailer"
    click PAY "https://github.com/nihalgound/botly-ai/tree/main/src/actions/payment"
    click SETT "https://github.com/nihalgound/botly-ai/tree/main/src/actions/settings"
    click STRIPE "https://github.com/nihalgound/botly-ai/tree/main/src/actions/stripe"
    click DB "https://github.com/nihalgound/botly-ai/blob/main/prisma/schema.prisma"
    click UTIL "https://github.com/nihalgound/botly-ai/tree/main/src/lib"
    click SCHEMA "https://github.com/nihalgound/botly-ai/tree/main/src/schemas"

    %% Styles
    classDef client fill:#bbf,stroke:#333,stroke-width:2px;
    classDef frontend fill:#cfc,stroke:#333,stroke-width:2px;
    classDef backend fill:#fc9,stroke:#333,stroke-width:2px;
    classDef database fill:#afa,stroke:#333,stroke-width:2px;
    classDef external fill:#fdd,stroke:#333,stroke-width:2px;
    classDef utility fill:#ddf,stroke:#333,stroke-width:2px;
```
