Configuration Overview
FinAI uses environment variables to manage sensitive configuration data. All configuration is centralized inconfig.py and loads values from a .env file.
config.py
Environment Variables
Creating the .env File
Create a.env file in the root directory of your project:
Required Variables
Flask secret key used for session management, CSRF protection, and cryptographic signing.Generation:Example:
Google Gemini API key for AI-powered features including transaction categorization and chatbot functionality.How to obtain:Usage in code:
- Visit Google AI Studio
- Sign in with your Google account
- Create a new API key
- Copy the key to your
.envfile
app/ai_service.py
Without this key, AI categorization and chatbot features will not function.
Gmail address used to send password reset emails.Example:
Gmail App Password (not your regular Gmail password) for SMTP authentication.How to generate an App Password:
- Go to your Google Account settings
- Navigate to Security > 2-Step Verification
- Scroll to “App passwords” at the bottom
- Generate a new app password for “Mail”
- Copy the 16-character password
Complete .env Template
.env
Email Configuration Details
The email system is used exclusively for password reset functionality. Configuration is handled inconfig.py:
- Gmail (default configuration)
- For other providers, modify
MAIL_SERVERandMAIL_PORTinconfig.py
Database Configuration
FinAI uses SQLite by default with automatic path resolution:config.py
instance/quanlychitieu.db
For production deployments, consider migrating to PostgreSQL or MySQL. Update the
SQLALCHEMY_DATABASE_URI environment variable accordingly.PostgreSQL Example (Production)
To use PostgreSQL in production:- Install the PostgreSQL adapter:
- Add to
.env:
- Modify
config.py:
AI Model Configuration
The Gemini AI model is configured inai_service.py:
app/ai_service.py
- Transaction categorization with JSON response
- Context-aware chatbot with streaming responses
- RAG (Retrieval Augmented Generation) for financial insights
Response times depend on Google Gemini API availability (typically 2-5 seconds).
Verifying Configuration
After setting up your.env file, verify the configuration:
