This project has been restructured into a modular architecture for better maintainability and organization.
lead-qualification-system/
├── app.py # Main application entry point
├── config.py # Configuration and environment variables
├── database.py # Database operations and SQLite functions
├── email_service.py # Email functionality and routing
├── agents.py # Agent system, handoffs, and processing logic
├── utils.py # Utility functions (logging, lead extraction)
├── ui.py # Streamlit UI components
├── leads.db # SQLite database file
└── venv/ # Virtual environment
- Purpose: Main application entry point
- Responsibilities: Orchestrates all modules and runs the Streamlit application
- Key Functions:
main()
- Purpose: Centralized configuration management
- Responsibilities: Environment variables, API keys, email settings, database configuration
- Key Variables:
OPENAI_API_KEY,EMAIL_USER,EMAIL_APP_PASSWORD,DB_FILE,EMAIL_ROUTING
- Purpose: Database operations and data persistence
- Responsibilities: SQLite database initialization, lead storage, data retrieval
- Key Functions:
init_database(),save_lead_to_database(),get_all_leads(),clear_all_leads()
- Purpose: Email functionality and notification system
- Responsibilities: Email sending, lead routing, deduplication, test emails
- Key Functions:
send_email_message(),route_lead_email(),force_lead_email(),send_test_email()
- Purpose: AI agent system and conversation processing
- Responsibilities: Agent creation, handoffs, message processing, tool functions
- Key Functions:
create_agent_system(),process_user_message(),create_handoff_callback()
- Purpose: Utility functions and helper methods
- Responsibilities: System logging, lead information extraction, text processing
- Key Functions:
log_system_message(),extract_lead_details()
- Purpose: Streamlit user interface components
- Responsibilities: Page layout, sidebar controls, chat interface, system logs display
- Key Functions:
render_sidebar(),render_main_content(),render_header(),setup_page_config()
- Separation of Concerns: Each module has a single responsibility
- Maintainability: Easier to locate and modify specific functionality
- Testability: Individual modules can be tested in isolation
- Reusability: Modules can be imported and used in other projects
- Scalability: New features can be added without affecting existing code
- Code Organization: Related functionality is grouped together
The application can be run using the same command as before:
streamlit run app.pyAll functionality remains the same, but the code is now organized in a more maintainable structure.
The modular structure maintains all original dependencies:
streamlitopenaipandassqlite3smtplibpython-dotenvagents(custom agent framework)
- All original functionality has been preserved
- No changes to the database schema or email configuration
- The user interface remains identical
- All agent behaviors and handoffs work as before
- Environment variables and configuration remain the same