# vinothkumars1710/buddyai architecture

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

- Interactive diagram: https://gitdiagram.com/vinothkumars1710/buddyai
- Repository: https://github.com/vinothkumars1710/buddyai

## Overview

BuddyAI is a full-stack AI chat application with account access, persistent conversations, image generation and sharing, and credit purchases. Users authenticate in the React client, use chat and community pages, and manage credits; the Express API applies authentication and rate limits, invokes AI or payment services, and persists account, chat, and transaction data. The sampled code shows the text/image generation and credit-order paths; payment completion and some route/controller details are documented or indexed but not fully excerpted, so those links are limited to supported evidence.

Main entry points: [`server/server.js`](https://github.com/vinothkumars1710/buddyai/blob/main/server/server.js) (Express API), [`client/src/App.jsx`](https://github.com/vinothkumars1710/buddyai/blob/main/client/src/App.jsx) (Application shell), [`client/src/routes/AllRoutes.jsx`](https://github.com/vinothkumars1710/buddyai/blob/main/client/src/routes/AllRoutes.jsx) (Page routing), [`server/controllers/messageController.js`](https://github.com/vinothkumars1710/buddyai/blob/main/server/controllers/messageController.js) (Message generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client experience"]
  node_app["Application shell<br/>[App.jsx]"]
  node_context["App state<br/>[AppContext.jsx]"]
  node_login["Login<br/>[Login.jsx]"]
  node_chatui["Chat interface<br/>[ChatBox.jsx]"]
  node_messages["Message rendering<br/>[Message.jsx]"]
  node_sidebar["Chat navigation<br/>[SideBar.jsx]"]
  node_routes["Page routing<br/>[AllRoutes.jsx]"]
  node_creditsui["Credit plans<br/>[Credits.jsx]"]
  node_community["Image community<br/>[Community.jsx]"]
end

subgraph group_api["API and access"]
  node_api["Express API<br/>[server.js]"]
  node_userctrl["Account handlers<br/>[userController.js]"]
  node_chatctrl["Chat handlers<br/>[chatController.js]"]
  node_auth["JWT protection<br/>[auth.js]"]
end

subgraph group_ai["AI generation"]
  node_messagectrl["Message generation"]
  node_aiproviders["AI providers<br/>[openai.js]"]
  node_imagekit["Image storage<br/>[imageKit.js]"]
end

subgraph group_commerce["Credits and payments"]
  node_creditctrl["Credit orders"]
  node_webhook["Payment webhook<br/>[webhooks.js]"]
  node_razorpay["Razorpay<br/>[razorpay.js]"]
end

subgraph group_data["Persistent data"]
  node_users[("User records<br/>[User.js]")]
  node_chats[("Chat history<br/>[Chat.js]")]
  node_transactions[("Transactions<br/>[Transaction.js]")]
end

node_person(("User"))
node_mongodb[("MongoDB")]

node_person -->|"uses"| node_app
node_app -->|"reads state"| node_context
node_app -->|"shows when signed out"| node_login
node_app -->|"renders"| node_sidebar
node_app -->|"renders"| node_routes
node_routes -->|"checks loading"| node_context
node_routes -->|"routes to"| node_chatui
node_routes -->|"routes to"| node_creditsui
node_routes -->|"routes to"| node_community
node_chatui -->|"uses state"| node_context
node_chatui -->|"renders"| node_messages
node_sidebar -->|"uses state"| node_context
node_context -->|"requests user and chats"| node_api
node_creditsui -.->|"requests plans and purchase"| node_api
node_community -.->|"requests published images"| node_api
node_api -->|"mounts user routes"| node_userctrl
node_api -->|"mounts chat routes"| node_chatctrl
node_api -->|"mounts message routes"| node_messagectrl
node_api -->|"mounts credit routes"| node_creditctrl
node_api -->|"registers webhook"| node_webhook
node_userctrl -->|"reads and writes"| node_users
node_userctrl -->|"queries published images"| node_chats
node_chatctrl -->|"uses chat model"| node_chats
node_messagectrl -->|"loads and saves"| node_chats
node_messagectrl -->|"deducts credits"| node_users
node_messagectrl -->|"requests completion"| node_aiproviders
node_messagectrl -->|"uploads image"| node_imagekit
node_creditctrl -->|"creates order record"| node_transactions
node_creditctrl -->|"creates payment order"| node_razorpay
node_webhook -->|"updates payment"| node_transactions
node_webhook -->|"updates credits"| node_users
node_auth -->|"loads account"| node_users
node_mongodb -.->|"stores application data"| node_api

click node_app "https://github.com/vinothkumars1710/buddyai/blob/main/client/src/App.jsx"
click node_context "https://github.com/vinothkumars1710/buddyai/blob/main/client/src/context/AppContext.jsx"
click node_login "https://github.com/vinothkumars1710/buddyai/blob/main/client/src/pages/Login.jsx"
click node_chatui "https://github.com/vinothkumars1710/buddyai/blob/main/client/src/components/ChatBox.jsx"
click node_messages "https://github.com/vinothkumars1710/buddyai/blob/main/client/src/components/Message.jsx"
click node_sidebar "https://github.com/vinothkumars1710/buddyai/blob/main/client/src/components/SideBar.jsx"
click node_routes "https://github.com/vinothkumars1710/buddyai/blob/main/client/src/routes/AllRoutes.jsx"
click node_creditsui "https://github.com/vinothkumars1710/buddyai/blob/main/client/src/pages/Credits.jsx"
click node_community "https://github.com/vinothkumars1710/buddyai/blob/main/client/src/pages/Community.jsx"
click node_api "https://github.com/vinothkumars1710/buddyai/blob/main/server/server.js"
click node_userctrl "https://github.com/vinothkumars1710/buddyai/blob/main/server/controllers/userController.js"
click node_chatctrl "https://github.com/vinothkumars1710/buddyai/blob/main/server/controllers/chatController.js"
click node_auth "https://github.com/vinothkumars1710/buddyai/blob/main/server/middlewares/auth.js"
click node_messagectrl "https://github.com/vinothkumars1710/buddyai/blob/main/server/controllers/messageController.js"
click node_aiproviders "https://github.com/vinothkumars1710/buddyai/blob/main/server/configs/openai.js"
click node_imagekit "https://github.com/vinothkumars1710/buddyai/blob/main/server/configs/imageKit.js"
click node_creditctrl "https://github.com/vinothkumars1710/buddyai/blob/main/server/controllers/creditController.js"
click node_webhook "https://github.com/vinothkumars1710/buddyai/blob/main/server/controllers/webhooks.js"
click node_razorpay "https://github.com/vinothkumars1710/buddyai/blob/main/server/configs/razorpay.js"
click node_users "https://github.com/vinothkumars1710/buddyai/blob/main/server/models/User.js"
click node_chats "https://github.com/vinothkumars1710/buddyai/blob/main/server/models/Chat.js"
click node_transactions "https://github.com/vinothkumars1710/buddyai/blob/main/server/models/Transaction.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_context,node_login,node_chatui,node_messages,node_sidebar,node_routes,node_creditsui,node_community,node_person toneBlue
class node_api,node_userctrl,node_chatctrl,node_auth,node_mongodb toneAmber
class node_messagectrl,node_aiproviders,node_imagekit toneMint
class node_creditctrl,node_webhook,node_razorpay toneRose
class node_users,node_chats,node_transactions toneIndigo
```

## Components

### Client experience

- [Application shell](https://github.com/vinothkumars1710/buddyai/blob/main/client/src/App.jsx): `client/src/App.jsx`
- [App state](https://github.com/vinothkumars1710/buddyai/blob/main/client/src/context/AppContext.jsx): `client/src/context/AppContext.jsx`
- [Login](https://github.com/vinothkumars1710/buddyai/blob/main/client/src/pages/Login.jsx): `client/src/pages/Login.jsx`
- [Chat interface](https://github.com/vinothkumars1710/buddyai/blob/main/client/src/components/ChatBox.jsx): `client/src/components/ChatBox.jsx`
- [Message rendering](https://github.com/vinothkumars1710/buddyai/blob/main/client/src/components/Message.jsx): `client/src/components/Message.jsx`
- [Chat navigation](https://github.com/vinothkumars1710/buddyai/blob/main/client/src/components/SideBar.jsx): `client/src/components/SideBar.jsx`
- [Page routing](https://github.com/vinothkumars1710/buddyai/blob/main/client/src/routes/AllRoutes.jsx): `client/src/routes/AllRoutes.jsx`
- [Credit plans](https://github.com/vinothkumars1710/buddyai/blob/main/client/src/pages/Credits.jsx): `client/src/pages/Credits.jsx`
- [Image community](https://github.com/vinothkumars1710/buddyai/blob/main/client/src/pages/Community.jsx): `client/src/pages/Community.jsx`

### API and access

- [Express API](https://github.com/vinothkumars1710/buddyai/blob/main/server/server.js): `server/server.js`
- [Account handlers](https://github.com/vinothkumars1710/buddyai/blob/main/server/controllers/userController.js): `server/controllers/userController.js`
- [Chat handlers](https://github.com/vinothkumars1710/buddyai/blob/main/server/controllers/chatController.js): `server/controllers/chatController.js`
- [JWT protection](https://github.com/vinothkumars1710/buddyai/blob/main/server/middlewares/auth.js): `server/middlewares/auth.js`

### AI generation

- [Message generation](https://github.com/vinothkumars1710/buddyai/blob/main/server/controllers/messageController.js): `server/controllers/messageController.js`
- [AI providers](https://github.com/vinothkumars1710/buddyai/blob/main/server/configs/openai.js): `server/configs/openai.js`
- [Image storage](https://github.com/vinothkumars1710/buddyai/blob/main/server/configs/imageKit.js): `server/configs/imageKit.js`

### Credits and payments

- [Credit orders](https://github.com/vinothkumars1710/buddyai/blob/main/server/controllers/creditController.js): `server/controllers/creditController.js`
- [Payment webhook](https://github.com/vinothkumars1710/buddyai/blob/main/server/controllers/webhooks.js): `server/controllers/webhooks.js`
- [Razorpay](https://github.com/vinothkumars1710/buddyai/blob/main/server/configs/razorpay.js): `server/configs/razorpay.js`

### Persistent data

- [User records](https://github.com/vinothkumars1710/buddyai/blob/main/server/models/User.js): `server/models/User.js`
- [Chat history](https://github.com/vinothkumars1710/buddyai/blob/main/server/models/Chat.js): `server/models/Chat.js`
- [Transactions](https://github.com/vinothkumars1710/buddyai/blob/main/server/models/Transaction.js): `server/models/Transaction.js`

### Other components

- **User**
- **MongoDB**

## Connections

- User → Application shell: uses (evidence: `README.md`)
- Application shell → App state: reads state (evidence: `client/src/App.jsx`)
- Application shell → Login: shows when signed out (evidence: `client/src/App.jsx`)
- Application shell → Chat navigation: renders (evidence: `client/src/App.jsx`)
- Application shell → Page routing: renders (evidence: `client/src/App.jsx`)
- Page routing → App state: checks loading (evidence: `client/src/routes/AllRoutes.jsx`)
- Page routing → Chat interface: routes to (evidence: `client/src/routes/AllRoutes.jsx`)
- Page routing → Credit plans: routes to (evidence: `client/src/routes/AllRoutes.jsx`)
- Page routing → Image community: routes to (evidence: `client/src/routes/AllRoutes.jsx`)
- Chat interface → App state: uses state (evidence: `client/src/components/ChatBox.jsx`)
- Chat interface → Message rendering: renders (evidence: `client/src/components/ChatBox.jsx`)
- Chat navigation → App state: uses state (evidence: `client/src/components/SideBar.jsx`)
- App state → Express API: requests user and chats (evidence: `client/src/context/AppContext.jsx`)
- Credit plans → Express API: requests plans and purchase
- Image community → Express API: requests published images
- Express API → Account handlers: mounts user routes (evidence: `server/server.js`)
- Express API → Chat handlers: mounts chat routes (evidence: `server/server.js`)
- Express API → Message generation: mounts message routes (evidence: `server/server.js`)
- Express API → Credit orders: mounts credit routes (evidence: `server/server.js`)
- Express API → Payment webhook: registers webhook (evidence: `server/server.js`)
- Account handlers → User records: reads and writes (evidence: `server/controllers/userController.js`)
- Account handlers → Chat history: queries published images (evidence: `server/controllers/userController.js`)
- Chat handlers → Chat history: uses chat model (evidence: `server/controllers/chatController.js`)
- Message generation → Chat history: loads and saves (evidence: `server/controllers/messageController.js`)
- Message generation → User records: deducts credits (evidence: `server/controllers/messageController.js`)
- Message generation → AI providers: requests completion (evidence: `server/controllers/messageController.js`)
- Message generation → Image storage: uploads image (evidence: `server/controllers/messageController.js`)
- Credit orders → Transactions: creates order record (evidence: `server/controllers/creditController.js`)
- Credit orders → Razorpay: creates payment order (evidence: `server/controllers/creditController.js`)
- Payment webhook → Transactions: updates payment (evidence: `server/controllers/webhooks.js`)
- Payment webhook → User records: updates credits (evidence: `server/controllers/webhooks.js`)
- JWT protection → User records: loads account (evidence: `server/middlewares/auth.js`)
- MongoDB → Express API: stores application data
