How sebampuero/simple_chatgpt_4 works
Main Components Identification
a. Frontend (React App):
• Located in the "react-app" directory.
• Contains all React components, styling files, and API communication logic (e.g., src/api/api.js).
• Manages UI elements such as ChatInput, ChatMessages, ChatPage, and ChatSidebar.
b. Backend:
• The entry point is main.py and server package.
• Contains HTTP routes, websocket (ws) handling, and various request handlers (e.g., chat, login, models).
c. Components (Business Logic and Services):
• Organized within the "components" directory.
• Divided into submodules for handling chat states, database connectivity (DynamoDB connectors), Elasticsearch operations, login (JWT management and actual login routines), and a repository layer for user management and data access.
• Includes abstraction for different LLMs in the "components/llm" folder.
d. Middleware:
• A separate module for handling authentication (located in middleware/authentication.py).
e. External Services and Integrations:
• DynamoDB for storing chat history and authorized users.
• Elasticsearch, which can be deployed via docker-compose (see included configuration).
• Google OAuth (via external configuration and environment variables).
• Cloud-based LLM APIs (OpenAI, Gemini, etc.).
f. Infrastructure & Deployment:
• Dockerfile, .dockerignore, docker-compose.yml – for containerization and orchestration.
• Environment configuration files (.env.dist and others) and setup scripts (setup.sh, add_authorized_email.sh, start_dev.sh, start_prd.sh).
Relationships and Interactions
• The React frontend communicates with the backend (through API calls and websockets), making requests to endpoints defined in the server package.
• The server routes requests to appropriate handlers (chat, login, models, ws) which in turn interact with the components.
• The authentication middleware intercepts requests to secure routes using JWT tokens.
• The LLM components call external APIs to generate responses and models encapsulate each LLM’s specifics.
• The database components handle both asynchronous and synchronous interactions with DynamoDB.
• When a search operation is done, the server will leverage the Elasticsearch component, connecting through the ElasticClient defined in components/elasticsearch.
Architectural Patterns and Design Principles
• The project follows a clear separation of concerns, with distinct layers:
• Presentation layer (React frontend).
• API/Controller layer (server handlers).
• Business/service layer (components) splitting functionalities for chat logic, database operations, authentication, and LLM integration.
• Uses modular design, making it easier to extend, test (note the components/tests folder), and maintain.
• Integration of external services is encapsulated behind specific connectors (e.g., DDBConnector for AWS DynamoDB, ElasticClient for Elasticsearch).
Technologies, Frameworks, and Libraries
• React (for frontend UI) with its ecosystem (including CSS, testing, and proxy configurations).
• Python for backend logic with server packages, middleware, and components.
• AWS DynamoDB (database connectivity configured through Python scripts and AWS CLI instructions in the README).
• Elasticsearch (for search capabilities, with a provided docker-compose example).
• Google OAuth for user authentication integrating with JWT for session management.
• Containerization (Dockerfile, docker-compose file) and configuration management (.env, setup scripts).
Elements
• "React Frontend" (with possible subdivisions for components and API layer)
• "Python Backend" leading to "API Endpoints" which further branch to handlers (chat, login, etc.)
• "Components" grouping Chat, Database, LLM, Login, Repository.
• "Middleware" for authentication.
• "External Services" including AWS DynamoDB, Elasticsearch, Google OAuth, and external LLM APIs.
• Frontend → Backend API (API calls and websockets)
• API → Business Components (invoking specific functionalities)
• Components → External Services (for database access, search queries, and LLM queries).
• Ovals or cloud symbols for external services.