How avinashkrishnaaqe/ai-chat-app works
This is an AI chat application with a Next.js client and FastAPI backend. The main workflow is user authentication, conversation management, and streamed model responses, with persistent conversation history and refresh-token sessions. The graph includes the documented model-selection and chat UI components, plus the backend authentication, chat, and LLM layers. Evidence is limited to the supplied excerpts and SOURCE INDEX; links for unsampled frontend-to-chat API wiring are omitted where no relationship is shown.
Main entry points: auth_service.py Auth service · chat_service.py Conversation service · auth.py Auth endpoints · ChatWindow.tsx Chat window
Components 28
Web client
- Chat window
frontend/src/components/chat/ChatWindow.tsx - Message composer
frontend/src/components/chat/Composer.tsx - Model picker
frontend/src/components/chat/ModelPicker.tsx - Quick prompts
frontend/src/components/chat/QuickPrompts.tsx - Message list
frontend/src/components/chat/MessageList.tsx - Message bubble
frontend/src/components/chat/MessageBubble.tsx - Chat sidebar
frontend/src/components/sidebar/Sidebar.tsx - Chat API client
frontend/src/lib/api/chat.ts - Chat socket
frontend/src/lib/ws/chatSocket.ts - API request client
frontend/src/lib/api/client.ts - Auth state
frontend/src/store/useAuthStore.ts - Auth API client
frontend/src/lib/api/auth.ts
API and identity
- Auth endpoints
backend/app/api/v1/auth.py - Chat endpoints
backend/app/api/v1/chats.py - Streaming endpoint
backend/app/api/v1/ws_chat.py - API application
backend/app/main.py - Auth service
backend/app/services/auth_service.py - Auth dependencies
backend/app/api/deps.py
Conversation and generation
- Conversation service
backend/app/services/chat_service.py - LLM service
backend/app/services/llm_service.py
Persistence and security
- SQL database
backend/app/db/session.py - User records
backend/app/models/user.py - Refresh tokens
backend/app/models/refresh_token.py - Conversations
backend/app/models/conversation.py - Messages
backend/app/models/message.py - Token security
backend/app/core/security.py
Other components
- User
- OpenRouter models
Connections 30
- User → Chat window: uses
- Chat window → Message list: renders
frontend/src/components/chat/ChatWindow.tsx - Chat window → Message composer: renders
frontend/src/components/chat/ChatWindow.tsx - Chat window → Quick prompts: renders
frontend/src/components/chat/ChatWindow.tsx - Message composer → Model picker: renders
frontend/src/components/chat/Composer.tsx - Message list → Message bubble: renders
- API request client → Auth state: reads token
frontend/src/lib/api/client.ts - API request client → Auth state: updates session
frontend/src/lib/api/client.ts - Auth API client → API request client: uses requests
frontend/src/lib/api/auth.ts - API request client → Auth endpoints: refreshes session
frontend/src/lib/api/client.ts - User → Auth endpoints: authenticates
- API application → Auth endpoints: registers
backend/app/main.py - API application → Chat endpoints: registers
backend/app/main.py - API application → Streaming endpoint: registers
backend/app/main.py - Auth endpoints → Auth service: calls
backend/app/api/v1/auth.py - Auth endpoints → Auth dependencies: authenticates via
backend/app/api/v1/auth.py - Chat endpoints → Conversation service: calls
backend/app/api/v1/chats.py - Chat endpoints → LLM service: generates via
backend/app/api/v1/chats.py - Streaming endpoint → Conversation service: calls
backend/app/api/v1/ws_chat.py - Streaming endpoint → LLM service: streams via
backend/app/api/v1/ws_chat.py - LLM service → OpenRouter models: requests completion
backend/app/services/llm_service.py - Auth service → User records: reads and writes
backend/app/services/auth_service.py - Auth service → Refresh tokens: reads and writes
backend/app/services/auth_service.py - Auth service → Token security: creates and verifies tokens
backend/app/services/auth_service.py - Conversation service → Conversations: reads and writes
backend/app/services/chat_service.py - Conversation service → Messages: reads and writes
backend/app/services/chat_service.py - Auth service → SQL database: persists records
- Conversation service → SQL database: persists history
- Auth dependencies → Token security: decodes token
backend/app/api/deps.py - Auth dependencies → SQL database: loads user
backend/app/api/deps.py