How ahsan7162/ai-communication-coach works
Main Components
• Frontend: Built with React.js. Key elements include the main application (App.tsx), separate pages for chat, login, and signup, and associated styles, configurations, and service calls (e.g., authApis.ts and chatApi.ts).
• Backend: Built with FastAPI in Python. It is organized into distinct directories:
– Routes: Contains API endpoints for chat, login, signup, home, and fetching LLM responses.
– Services: Contains the business logic for interfacing with Gemini (get_ai_coach_reply, llm integration, context extraction).
– Models: Contains data models and schemas (e.g., chat messages, login requests, token data) that are used with SQLAlchemy and SQLite.
– Database: Includes SQLite database files and setup scripts (db_setup.py, get_db.py) to configure and manage persistence.
– Prompts: Contains Gemini-specific prompts that tailor the AI coaching behavior.
– Helpers: Provides utility functions such as extracting user data from JWT tokens.
• Database: A SQLite database (aicoach.db) utilized by the backend for storing user data, chat logs, etc.
• External Service Integration: Gemini LLM is used to generate responses and coaching prompts—this integration is woven into the services layer.
Relationships and Data Flow
• User interactions occur at the Frontend where the React app captures actions (login, signup, chat messages).
• Frontend then communicates with the Backend using API calls defined in the routes.
• The Backend routes invoke services that use the LLM (Gemini) and access the SQLite database via the models and helper methods.
• Business logic in the services determines the AI responses and processes the data based on prompt templates.
• Data is stored and retrieved from the SQLite database using SQLAlchemy through model definitions within the backend.
• Response data flows back to the Frontend, which then displays the AI communication coaching output to the user.
Architectural Patterns and Design Principles
• Separation of Concerns: The project neatly separates API endpoints (routes), business logic (services), data persistence (models and database), and AI prompt handling (prompts).
• Layered Architecture: Each layer (frontend, API, database, integration with Gemini) is clearly defined.
• Consistent Naming and Module Organization: Directories such as “models”, “routes”, “services”, and “helpers” indicate a modular approach to design.
• Clear API Contract: The use of specific request and response models in the models directory ensures that the API is well-documented and standardized.
Key Elements
• Dependency relationships:
– Indicate that the backend’s “routes” depend on “models” and “services” to process requests.
– Show the connection between “database” setup and ORM models.