GEMINI.md
1/GEMINI.mdGEMINI.md
Quality
81/100
Scores the file, not the repository.Length
1,214 words
11 headings · 5 code blocksRepository
0
— · pushed 1 days agoLast changed
3 days ago
First indexed 3 days ago.1# Project: Customer Support AI Agent23## 1. Project Overview45This is an enterprise-grade, AI-powered customer support system featuring a microservices-based architecture with a React frontend and a FastAPI backend. The project is fully implemented, functional, and has evolved significantly beyond its initial design.67The core of the application is a sophisticated, custom-built AI agent orchestrator capable of real-time chat (via WebSockets), Retrieval-Augmented Generation (RAG) for knowledge retrieval, conversation memory management, and processing of user-uploaded documents.89**Project Status:** Implemented, Functional, and Ready for Feature Development/Bug Fixing.1011## 2. Technology Stack1213* **Frontend:** React, TypeScript, Vite, Tailwind CSS, Zustand (for state management), Axios.14* **Backend:** FastAPI, Python 3.11+, SQLAlchemy, Alembic (for migrations).15* **AI/ML:** A custom agent orchestrator. Tools leverage SentenceTransformers (e.g., `all-MiniLM-L6-v2`) and ChromaDB for RAG.16* **Infrastructure:** Docker, Redis, SQLite (dev), PostgreSQL (prod-ready).1718## 3. System Architecture1920The application follows a decoupled frontend/backend architecture. The frontend is a Single Page Application (SPA) built with React, and the backend is a FastAPI service. During development, the Vite dev server proxies API and WebSocket requests to the backend to avoid CORS issues.2122### 3.1. Backend Architecture2324The backend is a highly modular, production-grade FastAPI application.2526* **Core Component (`CustomerSupportAgent`)**: The heart of the backend is the `CustomerSupportAgent` (`backend/app/agents/chat_agent.py`). It is a sophisticated orchestrator that manages the entire conversation flow, tool usage, and state.2728* **Distributed Session Management**: A key architectural pillar is the externalized session management system, designed for horizontal scalability.29 * **Pluggable Backends**: It uses a `SessionStore` abstraction (`backend/app/session/session_store.py`) with two implementations: a simple `InMemorySessionStore` for development and a production-grade `RedisSessionStore`.30 * **High-Performance & Consistency**: The Redis store uses atomic Lua scripts for operations, features an in-memory L1 cache (`TTLCache`) to reduce latency, and employs Redis-based distributed locks (`backend/app/session/distributed_lock.py`) to prevent race conditions in a multi-instance environment.31 * **Security**: Session data can be encrypted at rest, configured via `backend/app/config.py`.3233* **Extensible Tooling Architecture**: The system features a dynamic and resilient tool-use framework.34 * **Tool Registry**: Instead of hardcoding tools, the agent uses a `ToolRegistry` (`backend/app/tools/registry.py`) to dynamically load and initialize tools based on configuration. This makes adding new capabilities (like the implemented CRM, Billing, and Inventory tools) straightforward.35 * **Standardized Contracts**: All tools inherit from a `BaseTool` (`backend/app/tools/base_tool.py`) and return a standardized `ToolResult`, ensuring predictable integrations.36 * **Resilience**: Tool calls are wrapped with resilience patterns like retries and circuit breakers (via `backend/app/tools/tool_call_wrapper.py`), making the system robust against transient failures of external services.3738* **Configuration-Driven System**: The entire backend's behavior is controlled by a comprehensive, type-safe configuration system in `backend/app/config.py`. This Pydantic-based setup allows for easy management of different environments, feature flags, and fine-grained tuning of all components, from the database pool to session encryption keys.3940* **Robust Application Lifecycle**: The `app/main.py` entry point defines a clean application lifecycle with a `lifespan` manager. This ensures graceful startup (including database checks, agent initialization) and shutdown. It also registers a full-featured middleware pipeline for rate limiting, request timing, correlation IDs, and global error handling.4142### 3.2. Frontend Architecture4344The frontend is a modern React application built with Vite and TypeScript.4546* **Component-Based UI**: The UI is built with React components located in `frontend/src/components`. The main view is the `ChatInterface.tsx`.47* **Hook-Based Logic**: Core business logic and state management for the chat are encapsulated in custom hooks, primarily `useChat.ts`. This hook orchestrates API calls and WebSocket events.48* **Service Layer**: API and WebSocket communications are abstracted into singleton services (`frontend/src/services/api.ts` and `frontend/src/services/websocket.ts`), keeping network logic separate from UI components.49* **State Management**: The primary chat state is managed within the `useChat` hook using `useState`.50* **Styling**: Tailwind CSS is used for styling, with custom configurations in `tailwind.config.js`.5152## 4. Key Workflows & Data Flows5354### 4.1. Session Initialization and WebSocket Connection5556This workflow is critical for starting a conversation and was the source of a key bug.57581. **Frontend**: The `ChatInterface` component mounts and, via the `useChat` hook, calls `initializeSession()`.592. **Frontend**: `initializeSession` makes a `POST` request to the backend's `/api/sessions` endpoint.603. **Backend**: The `create_session` route in `sessions.py` creates a new session in the database and returns a `SessionResponse` object.614. **Data Contract (Compatibility Fix)**: The backend returns a JSON object with `snake_case` keys (e.g., `{"session_id": "sess_..."}`). The frontend was previously expecting `camelCase` keys (`sessionId`), causing it to read `undefined` for the session ID. The type definition in `frontend/src/types/index.ts` and the property access in `frontend/src/hooks/useChat.ts` have been **corrected** to use `session_id`.625. **Frontend**: After successfully receiving the `session_id`, the `useChat` hook immediately calls `websocket.connect(session_id)`.636. **Frontend**: The `websocket.ts` service constructs the connection URL: `ws://<host>/ws?session_id=<session_id>`.647. **Backend**: The `websocket_endpoint` in `websocket.py` receives the connection, validates the `session_id`, and begins the real-time communication loop.6566### 4.2. Sending a Message6768Messages can be sent via HTTP (as a fallback) or WebSocket.6970* **WebSocket (Primary)**:71 1. The user submits a message.72 2. `useChat.ts` calls `websocket.sendMessage(content, attachments)`.73 3. The `websocket.ts` service sends a JSON payload of `type: "message"` over the active WebSocket connection.74 4. The backend's `websocket_endpoint` receives the message and streams back the agent's response in chunks (`type: "text"`, `type: "sources"`, etc.), culminating in a `type: "complete"` message.7576* **HTTP (Fallback)**:77 1. If the WebSocket is not connected, `useChat.ts` calls `api.sendMessage(sessionId, content, attachments)`.78 2. `api.ts` sends a `POST` request with `FormData` to `/api/chat/sessions/{sessionId}/messages`.79 3. The backend's `send_message` route processes the entire request via `agent.process_message` and returns a complete `ChatResponse` once finished.8081## 5. Development Conventions8283The project follows modern development conventions. The current codebase should be considered the source of truth for all patterns.8485* **Code Style:**86 * **Python:** PEP 8, extensive type hints, and a focus on readable, modular code.87 * **TypeScript:** The project is set up with ESLint and Prettier for code quality.88* **Testing:**89 * **Backend**: The testing framework is in place using `pytest`. Run tests with `./scripts/run_tests.sh`.90 * **Frontend**: The testing framework uses `vitest`. Run tests with `npm test`.91* **Architecture Patterns:**92 * **Service-Oriented**: The codebase demonstrates a clear separation of concerns between API routes (`app/api`), agent logic (`app/agents`), tools (`app/tools`), and services (`app/services`). This pattern should be followed for new features.93 * **Adding New Tools**: To add a new tool, create a new class inheriting from `BaseTool`, implement its logic, and register it in the `ToolRegistry` (`app/tools/registry.py`). Enable it via configuration in `app/config/tool_settings.py`.94 * **Configuration**: All new features should be configurable through `app/config.py` and `app/config/tool_settings.py`. Avoid hardcoded values.95 * **Session State**: All session-related state must be stored and retrieved through the `SessionStore` abstraction to ensure compatibility with distributed deployments. Do not store state directly in the agent instance.9697## 6. Building and Running9899The project is fully runnable. The following instructions have been updated to reflect the most stable and reliable startup procedure.1001011. **Initialize the Python backend:**102```bash103 cd backend104 python -m venv venv105 source venv/bin/activate106 pip install -r requirements.txt107```1081092. **Initialize the Node.js frontend:**110```bash111 cd frontend112 npm install113```114115**Running the application:**116117* **Using Docker Compose (Recommended):**118```bash119 docker-compose up -d120```121* **Manual Development Setup (Verified):**122 * **Backend:** The startup process has been simplified into a single script. This is the recommended way to run the backend manually.123```bash124 ./backend_start.sh125```126 * **Frontend:**127```bash128 cd frontend129 npm run dev130```131 * **Note:** The frontend development server uses a proxy to communicate with the backend. Ensure that API calls in the code use relative paths (e.g., `/api/sessions`) so they are correctly routed.132
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| google-gemini/gemini-cliGEMINI.md · 106k | GEMINI.md | setupbuildtestlint-format+6 | 91/100 | 3 days ago | |
| diegosouzapw/OmniRouteGEMINI.md · 38k | GEMINI.md | testlint-formatarchsecurity+2 | 87/100 | 3 days ago | |
| compozy/gographGEMINI.md · 9 | GEMINI.md | setuptestlint-formatarch+4 | 86/100 | 3 days ago | |
| nodejs/nodedeps/v8/GEMINI.md · 119k | GEMINI.md | buildteststylearch+4 | 77/100 | 3 days ago | |
| abpframework/abpnpm/ng-packs/packages/schematics/src/commands/ai-config/files/gemini/.gemini/GEMINI.md · 14k | GEMINI.md | testlint-formatstylearch+8 | 76/100 | 2 days ago | |
| zyx77550/spardaGEMINI.md · 4 | GEMINI.md | testlint-formatgitapi+2 | 75/100 | 3 days ago | |
| google-gemini/gemini-clipackages/devtools/GEMINI.md · 106k | GEMINI.md | setupbuildarchapi+1 | 74/100 | 3 days ago | |
| danielvm-git/bigpowersGEMINI.md · 114 | GEMINI.md | setupstyledo-notagent-behaviour | 67/100 | 3 days ago |
