Environment Variables
The application uses python-dotenv to load configuration from a.env file.
SECRET_KEY
Flask session encryption key. Must be cryptographically secure.Usage: Used by Flask to sign session cookies and prevent tampering.Location:
.env file in the application rootSecurity: Should never be committed to version controlImplementation
app.py:11-15
Generating a Secure Key
Use Python’ssecrets module to generate a cryptographically secure key:
The recommended key length is 32 bytes (64 hex characters) for production environments.
.env File Example
Session Management
Flask sessions store temporary data between requests. The application uses server-side sessions signed with SECRET_KEY.Session Storage Structure
User-configured keywords for filtering tasksDefault:
['solicitar peça', 'quebrado', 'quebrada', 'quebrados', 'orçamento', 'danificada', 'danificado', 'danificados', 'danificadas', 'trocar cabo', 'soldar', 'trocar', 'instalar', 'orçamento']Persistence: Stored in session until browser is closed or session expiresUnique filename for temporarily stored processing resultsFormat: UUID hex string +
.csv extensionExample: "a1b2c3d4e5f67890.csv"Purpose: References the temporary file containing filtered resultsStatistics from the most recent file processingStructure:
History of processed files (last 10 entries)Structure:Max Size: Limited to 10 most recent entries
Session Implementation
app.py:112, 137, 152, 155
Custom Keyword Configuration
Default Keywords
The application ships with predefined keywords for common maintenance scenarios:app.py:115
Configuration Route
Endpoint:/configMethods:
GET, POSTTemplate:
config.html
GET Request
Displays current keywords for editing:app.py:108-116
POST Request
Updates keywords from form submission:app.py:110-113
Comma-separated list of keywordsProcessing:
- Split by comma
- Strip whitespace from each keyword
- Filter out empty strings
- Store in session
"quebrado, trocar peça, soldar, orçamento"Keyword Usage in Filtering
Keywords are combined into a regex pattern:app.py:137, 47
Keywords are used with the regex OR operator (
|), so any single match will include the record in results.Temporary File Storage
Configuration
app.py:19-21
Directory for storing temporary processing resultsLocation:
temp/ subdirectory relative to app.pyAuto-creation: Created automatically if it doesn’t exist on app startupPermissions: Should be writable by the Flask processFile Naming Strategy
app.py:145-146
UUID-based filename ensures uniqueness and prevents collisionsFormat:
{32-char-hex-uuid}.csvExample: "a1b2c3d4e5f67890a1b2c3d4e5f67890.csv"Security: Random filenames prevent guessing/enumeration attacksFile Lifecycle
- Creation: When a file is processed via
/upload - Storage: Filtered results saved as CSV in
TEMP_FOLDER - Reference: Filename stored in
session['temp_filename'] - Retrieval: Read from disk for Excel/PDF export
- Expiration: Implicitly cleared when session expires
Reading Temporary Files
app.py:87-98
History Management
History Storage
app.py:75-84
History Limit: Only the 10 most recent processing operations are retained using list slicing
[:10].History Route
Endpoint:/historicoMethods:
GETTemplate:
historico.html
app.py:118-121
Configuration Best Practices
Security
- Never commit
.envto version control - Use a strong, random SECRET_KEY in production
- Rotate SECRET_KEY periodically
- Ensure
temp/directory has appropriate permissions
Performance
- Implement cleanup for old temp files
- Consider using Redis for session storage in production
- Monitor temp folder disk usage
Customization
- Keywords can be changed per-session via
/config - Default keywords are Portuguese maintenance terms
- Regex special characters in keywords should be escaped if literal matching is needed