### Tasks
- [ ] Abstract the current `database` functions into a `DatabaseManager` class that will handle all interactions with the database, including connection management and query execution.
- [ ] Develop a Config class responsible for loading and managing environment settings and other global configurations.
- [ ] Build a QueryHandler class that will utilize an AI model to process SQL queries and generate responses. This class will interact with the DatabaseManager to run queries against the database.
- [ ] Update the FastAPI router.py to use the new class instances instead of the current procedural code.
- [ ] Ensure that the endpoints receive JSON-formatted prompt inputs and return JSON-formatted answer outputs.
- [ ] Identify all parts of the existing codebase that interact with the database or AI services.
- [ ] Refactor these parts to use the new class-based structure.
- [ ] Write unit tests for the new classes to ensure that they work as expected.
### Acceptance Criteria
- [ ] The new class-based structure should be clear and well-organized within the project's directory structure.
- [ ] All FastAPI endpoints must function as before, correctly processing requests and returning responses.
- [ ] The application must pass all unit and integration tests with the new structure.