How dimachep1408/shop_project works
Based on your project file tree and README, this is a Flask-based internet shop application that uses the blueprint modular pattern. It supports user registration, login/authentication, shopping (product display, basket, order placement), administrative functions (adding, editing, and deleting products), and even a Telegram bot for additional management. The project interacts with a SQLite database (using SQLAlchemy and Flask‐Migrate) and makes use of Flask extensions for login, mailing, and more.
Main Components
• Web Server (Flask Application): This is the central “shop” instance defined in your project/settings.py. It is configured with key extensions (Flask-SQLAlchemy, Flask-Migrate, Flask-Login, Flask-Mail) and defines the global settings.
• Blueprints for Different Pages (Modules):
– User Management: login_page, login_page2, registration_page, registration_page2 (handling login, registration and authorization)
– Public and Main Views: main_page, main_page2, shop_page (home and product display)
– Shopping Functionality: basket_page and order_page (basket view, order placement, and email sending)
– Administrative Functions: admin_app, add_page, redact_page (admin panel for adding, editing, and deleting products)
– Telegram Bot: bot_app (a separate module handling bot operations via telebot)
• Database:
– SQLite database (project/data.db) accessed via SQLAlchemy.
– Data models include “User” and “Product” (located in models files under registration_page and admin_app respectively). Migrations are set up in the project/migrations folder.
• External Services and Tools:
– Email Service: Configured in project/mail_config.py to handle outgoing emails.
– Telegram Bot: Managed by the bot_app using the telebot module.
– Third-party libraries: pandas is used to read and write product data from Excel files.
Out Interactions & Relationships
• Client Interaction:
– End Users (customers) access public pages such as the main_page/main_page2 and shop_page.
– Registered users perform login/registration using the corresponding blueprints.
– The basket_page and order_page are used for shopping flow.
• Administrative Interaction:
– Admin users log in via the login pages and then navigate to the admin_app (and its related pages add_page and redact_page) to manage product data.
• Data Layer:
– All pages use the same centralized database, where product and user information is stored and queried.
– Blueprints interact with the database using SQLAlchemy sessions.
• External Services:
– The mail system (configured in mail_config) is triggered during order placement.
– The bot_app (a separate Python script) runs in parallel and interacts with the same database, offering administrative features via Telegram.
• Routing and Blueprint Registration:
– In the main configuration file (project/urls.py or via shop.register_blueprint calls), all individual blueprints are registered with specific URL rules so that each module handles its own URL space.
Architectural Patterns and Important Design Principles
• Modularization with Blueprints: Each functional section (user auth, shop, basket, admin, bot) exists as its own module with its own “app.py”, “views.py”, templates, and static files. This separation of concerns enhances maintainability.
• MVC (Model–View–Controller) Concepts:
– Models: Defined in the “models” files (User, Product).
– Views: Each blueprint “views.py” contains the logic for processing requests and rendering output.
– Templates: HTML templates (stored in blueprint-specific template folders) form the presentation layer.
• Centralized Configuration: The shop dictionary in project/settings.py centralizes the configuration and integrates extensions.
• Integration with External APIs: The Telegram bot and email service integration shows how the project extends its core functionality.