# dimachep1408/shop_project architecture

> Architecture diagram of the GitHub repository dimachep1408/shop_project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dimachep1408/shop_project
- Repository: https://github.com/dimachep1408/shop_project

## Overview

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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    CB["Client Browser"]:::external
    TC["Telegram Client"]:::external
    FlaskApp["Flask Application (settings, urls, login_manager, mail_config)"]:::flask
    DB["SQLite Database"]:::database
    Models["Data Models (User, Product)"]:::database
    Migrations["Migrations (project/migrations)"]:::database
    EmailService["Email Service"]:::external
    TelegramService["Telegram Service"]:::external

    %% Client Requests to Flask Application
    CB -->|"HTTP_Request"| FlaskApp

    %% Blueprint Modules
    subgraph "User Management"
        L1["login_page"]:::blueprint
        L2["login_page2"]:::blueprint
        R1["registration_page"]:::blueprint
        R2["registration_page2"]:::blueprint
    end

    subgraph "Public Views"
        M1["main_page"]:::blueprint
        M2["main_page2"]:::blueprint
        SP["shop_page"]:::blueprint
    end

    subgraph "Shopping Flow"
        BS["basket_page"]:::blueprint
        OR["order_page"]:::blueprint
    end

    subgraph "Administrative"
        AA["admin_app"]:::blueprint
        AP["add_page"]:::blueprint
        RP["redact_page"]:::blueprint
    end

    subgraph "Telegram Bot Module"
        BOT["bot_app"]:::blueprint
    end

    %% Flask Application registers blueprints
    FlaskApp -->|"register"| L1
    FlaskApp -->|"register"| L2
    FlaskApp -->|"register"| R1
    FlaskApp -->|"register"| R2
    FlaskApp -->|"register"| M1
    FlaskApp -->|"register"| M2
    FlaskApp -->|"register"| SP
    FlaskApp -->|"register"| BS
    FlaskApp -->|"register"| OR
    FlaskApp -->|"register"| AA
    FlaskApp -->|"register"| AP
    FlaskApp -->|"register"| RP
    FlaskApp -->|"register"| BOT

    %% Database Interactions from Blueprints
    L1 -->|"DB_Query"| DB
    L2 -->|"DB_Query"| DB
    R1 -->|"DB_Query"| DB
    R2 -->|"DB_Query"| DB
    M1 -->|"DB_Query"| DB
    M2 -->|"DB_Query"| DB
    SP -->|"DB_Query"| DB
    BS -->|"DB_Query"| DB
    OR -->|"DB_Query"| DB
    AA -->|"DB_Query"| DB
    AP -->|"DB_Query"| DB
    RP -->|"DB_Query"| DB
    BOT -->|"DB_Query"| DB

    %% Database contains models and migrations
    DB -->|"contains"| Models
    DB -->|"migrations"| Migrations

    %% External Service Integrations
    OR -->|"Email_Trigger"| EmailService
    BOT -->|"Telegram_Command"| TelegramService

    %% Telegram Client accesses Bot Module
    TC -->|"Bot_Request"| BOT

    %% Click Events for Web Server files
    click FlaskApp "https://github.com/dimachep1408/shop_project/blob/main/project/settings.py"
    
    %% Click Events for User Management Blueprints
    click L1 "https://github.com/dimachep1408/shop_project/blob/main/login_page/app.py"
    click L2 "https://github.com/dimachep1408/shop_project/blob/main/login_page2/app.py"
    click R1 "https://github.com/dimachep1408/shop_project/blob/main/registration_page/app.py"
    click R2 "https://github.com/dimachep1408/shop_project/blob/main/registration_page2/app.py"

    %% Click Events for Public Views Blueprints
    click M1 "https://github.com/dimachep1408/shop_project/blob/main/main_page/app.py"
    click M2 "https://github.com/dimachep1408/shop_project/blob/main/main_page2/app.py"
    click SP "https://github.com/dimachep1408/shop_project/blob/main/shop_page/app.py"

    %% Click Events for Shopping Functionality Blueprints
    click BS "https://github.com/dimachep1408/shop_project/blob/main/basket_page/app.py"
    click OR "https://github.com/dimachep1408/shop_project/blob/main/order_page/app.py"

    %% Click Events for Administrative Functionality Blueprints
    click AA "https://github.com/dimachep1408/shop_project/blob/main/admin_app/app.py"
    click AP "https://github.com/dimachep1408/shop_project/blob/main/add_page/app.py"
    click RP "https://github.com/dimachep1408/shop_project/blob/main/redact_page/app.py"

    %% Click Event for Telegram Bot
    click BOT "https://github.com/dimachep1408/shop_project/blob/main/bot_app/main.py"

    %% Click Events for Database and Migrations
    click DB "https://github.com/dimachep1408/shop_project/blob/main/project/data.db"
    click Migrations "https://github.com/dimachep1408/shop_project/tree/main/project/migrations"

    %% Click Event for Data Models (choose registration_page models for User)
    click Models "https://github.com/dimachep1408/shop_project/blob/main/registration_page/models.py"

    %% Click Event for External Email Service configuration
    click EmailService "https://github.com/dimachep1408/shop_project/blob/main/project/mail_config.py"

    %% Styles
    classDef flask fill:#bbf,stroke:#333,stroke-width:2px;
    classDef blueprint fill:#cfc,stroke:#333,stroke-width:2px;
    classDef database fill:#fc9,stroke:#333,stroke-width:2px;
    classDef external fill:#ffa,stroke:#333,stroke-width:2px;
```
