How farhaouiayoub/mini_projet_flask_ayoub-farhaoui-idai works
Main Components
• Application Entry Point: app.py – This is where the Flask application is initialized and started.
• Configuration: config.py – Contains settings such as SECRET_KEY, DATABASE_URL, SESSION_TYPE, and CACHE_TYPE.
• Models: The "models" directory, mainly user.py, where the data model (e.g., user schema) is defined with SQLite as the default database.
• Controllers: The "controllers" directory that holds business logic, especially in auth_controller.py for handling authentication tasks.
• Views/Routes: The "views" directory includes auth_views.py that maps routes to controller actions and renders responses.
• Templates: The "templates" directory contains HTML files (base.html, login.html, register.html, profile.html, edit_profile.html) responsible for rendering the user interface.
• Static Resources: The "static" directory holds assets like CSS (style.css) and JavaScript (script.js) to support client-side interactions.
• Utilities: The "utils" folder provides helper functionalities (e.g., decorators for route protection with login_required and cache management).
• Session Management: Although integrated via Flask-Session, the “flask_session” directory reflects the file-based session storage.
• Database: The "instance" directory includes SQLite database file (app.db).
Relationships and Interactions
• The Web Browser (Client) sends HTTP requests to the Flask Application via different URLs (e.g., /login, /register, /profile).
• The Flask Application (app.py) handles incoming requests by routing them to the appropriate view functions defined in the views.
• View functions call the corresponding controller functions (from controllers/auth_controller.py) to process business logic.
• Controllers interact with the models (in models/user.py) to perform database operations (such as creating users, hashing passwords, and retrieving user info).
• Utilities (in utils/decorators.py and utils/cache.py) provide cross-cutting concerns like route protection and caching to optimize performance.
• The configuration parameters (from config.py) ensure that sessions (managed by Flask-Session) are correctly handled using a file system-based session store.
• Finally, the rendered templates combine with static assets to produce the final HTML sent back to the client.
Architectural Patterns and Design Principles
• Modularity: Separation of concerns is clear with dedicated directories for models, controllers, views, templates, and utilities.
• MVC-like Separation: While Flask doesn’t enforce a strict MVC pattern, controllers (for business logic), views (for request routing), and templates (for presentation) mimic this design.
• Security Practices: Usage of password hashing (Werkzeug), session management with expiration, and route protection using custom decorators.
• Caching Pattern: Use of a simple caching mechanism to store frequently accessed user data to reduce database hits.