# maheshwarreddy970/corinna-ai architecture

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

- Interactive diagram: https://gitdiagram.com/maheshwarreddy970/corinna-ai
- Repository: https://github.com/maheshwarreddy970/corinna-ai

## Overview

##### Main Components
- Frontend (Next.js app router pages & React components in `src/app` + `src/components`)
- Backend API / Server Actions (Next.js server-side functions in `src/actions` + `src/app/api`)
- Database (Prisma ORM → underlying SQL database via `prisma/schema.prisma`)
- Authentication (Clerk)
- Real-time Chat (Pusher)
- AI Engine (OpenAI API)
- Payments (Stripe Connect + Stripe API)
- Email (NodeMailer via custom mailer service)
- File Uploads (UploadCare)

##### Relationships & Data Flows
a. User’s Browser ←→ Next.js Frontend
b. Frontend → Server Actions / API Routes (HTTP / fetch / Server Actions calls)
c. Server Actions → Prisma → Database
d. Server Actions → Clerk SDK (authenticate, user metadata)
e. Server Actions → Pusher (publish/subscribe chat events)
f. Server Actions → OpenAI (chatbot intelligence)
g. Server Actions → Stripe (payment intents, connect accounts)
h. Server Actions → NodeMailer (outgoing emails)
i. Frontend → UploadCare widget (direct uploads)

##### Architectural Patterns & Design Principles
- Monolithic full-stack: UI & API live under one Next.js codebase
- App Router with React Server & Client components → SSR/ISR where appropriate
- “Actions” folder as service layer: each domain (appointments, auth, bot, etc.) encapsulates business logic
- Domain-based routing (portal routes under `/portal/[domainid]`, dashboard under `/dashboard`)
- Prisma as the single source of truth for data models
- Environment-driven integration points (Clerk, Stripe, Pusher, OpenAI, UploadCare)

##### Essential Details to Capture
- Division between pages (`/auth`, `/dashboard`, `/portal`, `/blogs`, `/chatbot`) and shared UI library (`src/components/ui`)
- Central “Service Layer” (`src/actions/…`) as the orchestrator of business logic
- Middleware (`middleware.ts`) for domain routing or auth redirection
- Real-time chat loop: Frontend ↔ Pusher ↔ Bot service (OpenAI)
- Payment flow: Frontend → Stripe Connect API route → Stripe → Webhook back to Server Actions → Prisma

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    Browser["User Browser"]:::frontend
    NextApp["Next.js Frontend\n(src/app)"]:::frontend
    SharedUI["Shared UI Components\n(src/components/ui)"]:::frontend
    DomainUI["Domain UI Components\n(src/components)"]:::frontend
    UploadWidget["UploadCare Widget\n(src/components/upload-button/index.tsx)"]:::frontend
    PusherClient["Pusher Client"]:::frontend

    Browser -->|uses| NextApp
    NextApp -->|renders| SharedUI
    NextApp -->|renders| DomainUI
    NextApp -->|includes| UploadWidget
    NextApp -->|listens| PusherClient
    NextApp -->|calls| Server

    %% Backend Layer
    Server["Next.js Server\nAPI Routes\n(src/app/api)"]:::backend
    Middleware["Middleware\n(src/middleware.ts)"]:::backend
    ServiceLayer["Service Layer\n(src/actions)"]:::backend
    PrismaClient["Prisma Client\n(src/lib/prisma.ts)"]:::backend
    Database["Database\n(prisma/schema.prisma)"]:::db

    Server -->|middleware| Middleware
    Middleware -->|routes| Server
    Server -->|dispatches| ServiceLayer
    ServiceLayer -->|uses| PrismaClient
    PrismaClient -->|connects| Database

    %% Service Modules
    AuthS["Auth Service\n(src/actions/auth/index.ts)"]:::backend
    AppointmentS["Appointment Service\n(src/actions/appointment/index.ts)"]:::backend
    BotS["Bot Service\n(src/actions/bot/index.ts)"]:::backend
    ConversationS["Conversation Service\n(src/actions/conversation/index.ts)"]:::backend
    DashboardS["Dashboard Service\n(src/actions/dashboard/index.ts)"]:::backend
    MailerS["Mailer Service\n(src/actions/mailer/index.ts)"]:::backend
    MailS["Email Marketing\n(src/actions/mail/index.ts)"]:::backend
    PaymentsS["Payment Processing\n(src/actions/payments/index.ts)"]:::backend
    SettingsS["Settings Service\n(src/actions/settings/index.ts)"]:::backend
    StripeBL["Stripe Business Logic\n(src/actions/stripe/index.ts)"]:::backend

    ServiceLayer --> AuthS
    ServiceLayer --> AppointmentS
    ServiceLayer --> BotS
    ServiceLayer --> ConversationS
    ServiceLayer --> DashboardS
    ServiceLayer --> MailerS
    ServiceLayer --> MailS
    ServiceLayer --> PaymentsS
    ServiceLayer --> SettingsS
    ServiceLayer --> StripeBL

    %% External Services
    Clerk["Clerk"]:::external
    PusherExt["Pusher"]:::external
    OpenAIExt["OpenAI API"]:::external
    StripeExt["Stripe API"]:::external
    SMTP["Email SMTP"]:::external
    UploadCareExt["UploadCare"]:::external

    AuthS -->|auth| Clerk
    ConversationS -->|publish/subscribe| PusherExt
    BotS -->|requests| OpenAIExt
    PaymentsS -->|creates intents| StripeExt
    StripeBL -->|handles connect| StripeExt
    MailerS -->|sends| SMTP
    UploadWidget -->|uploads| UploadCareExt
    PusherClient -- "events" --- PusherExt

    %% Click Events
    click NextApp "https://github.com/maheshwarreddy970/corinna-ai/tree/main/src/app"
    click SharedUI "https://github.com/maheshwarreddy970/corinna-ai/tree/main/src/components/ui"
    click DomainUI "https://github.com/maheshwarreddy970/corinna-ai/tree/main/src/components"
    click UploadWidget "https://github.com/maheshwarreddy970/corinna-ai/blob/main/src/components/upload-button/index.tsx"
    click Server "https://github.com/maheshwarreddy970/corinna-ai/tree/main/src/app/api"
    click Middleware "https://github.com/maheshwarreddy970/corinna-ai/blob/main/src/middleware.ts"
    click ServiceLayer "https://github.com/maheshwarreddy970/corinna-ai/tree/main/src/actions"
    click PrismaClient "https://github.com/maheshwarreddy970/corinna-ai/blob/main/src/lib/prisma.ts"
    click Database "https://github.com/maheshwarreddy970/corinna-ai/blob/main/prisma/schema.prisma"
    click AuthS "https://github.com/maheshwarreddy970/corinna-ai/blob/main/src/actions/auth/index.ts"
    click AppointmentS "https://github.com/maheshwarreddy970/corinna-ai/blob/main/src/actions/appointment/index.ts"
    click BotS "https://github.com/maheshwarreddy970/corinna-ai/blob/main/src/actions/bot/index.ts"
    click ConversationS "https://github.com/maheshwarreddy970/corinna-ai/blob/main/src/actions/conversation/index.ts"
    click DashboardS "https://github.com/maheshwarreddy970/corinna-ai/blob/main/src/actions/dashboard/index.ts"
    click MailerS "https://github.com/maheshwarreddy970/corinna-ai/blob/main/src/actions/mailer/index.ts"
    click MailS "https://github.com/maheshwarreddy970/corinna-ai/blob/main/src/actions/mail/index.ts"
    click PaymentsS "https://github.com/maheshwarreddy970/corinna-ai/blob/main/src/actions/payments/index.ts"
    click SettingsS "https://github.com/maheshwarreddy970/corinna-ai/blob/main/src/actions/settings/index.ts"
    click StripeBL "https://github.com/maheshwarreddy970/corinna-ai/blob/main/src/actions/stripe/index.ts"

    %% Styles
    classDef frontend fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef backend fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef external fill:#ffdd99,stroke:#333,stroke-width:1px
    classDef db fill:#dddddd,stroke:#333,stroke-width:1px
```
