# justinlin63/flask_project1130 architecture

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

- Interactive diagram: https://gitdiagram.com/justinlin63/flask_project1130
- Repository: https://github.com/justinlin63/flask_project1130

## Overview

##### Project type and purpose
- This is a monolithic, server-rendered full-stack web application built with Flask.
- It uses Blueprints (one per business function: home, login, register, cart, orders, pay, admin, redirect, reset_password) to separate routes/controllers.
- It renders HTML templates on the server side and persists data in a MySQL database.

##### File structure
- Top-level entrypoint: `run.py` – initializes Flask app, loads `app/config.py`, registers all Blueprints under `app/functions/*/route.py`.
- `app/config.py` – central configuration (e.g., database URI, secret keys).
- `app/functions/` – each subfolder is a Flask Blueprint:
– `route.py` files define HTTP endpoints.
– `use_model.py` files encapsulate business logic and call into the model layer.
- `app/functions/models/` – the data layer:
– `sql_connect.py` opens/closes MySQL connections.
– `sql_setting.py` holds SQL parameters.
– Domain objects/utilities (e.g., `user.py`, `useful_string.py`).
- `app/templates/` – Jinja2 templates grouped per Blueprint.
- `app/static/assets/` – CSS/JS/images for client.
- `requirements.txt` – Python dependencies (Flask, PyMySQL, etc.).
- Deployment consideration: likely run behind a WSGI server (e.g., Gunicorn).

##### Key insights from README
- The application requires MySQL.
- Developer must configure database connection in `app/config.py` before starting.

##### How to model the system
1. Client (browser)
2. Web Server/Flask App
– Entrypoint: `run.py`
– Config module
– Blueprints (controllers): home, login, register, cart, orders, pay, admin, redirect, reset_password
– Templates (views)
– Static assets
– Model layer (data access): `sql_connect`, domain model files
3. MySQL Database

- Client → HTTP request → Flask App (Blueprint route)
- Blueprint route → calls use_model → model layer → SQL connector → MySQL
- Model layer → returns results → Blueprint route → renders templates → HTTP response → Client
- Static asset requests → Flask static handler → Client

c. Architectural patterns & principles:
- MVC-style separation:
– Controllers = `route.py`
– Models = `app/functions/models/*`
– Views = `app/templates/*`
- Modularization via Flask Blueprints
- Single shared configuration file
- Centralized DB connection management
- Server-side rendering with Jinja2

d. Technologies / frameworks:
- Python 3, Flask
- Jinja2 templating
- PyMySQL or MySQLdb
- MySQL server
- WSGI server (Gunicorn/uWSGI) for production

## Diagram (Mermaid)

```mermaid
flowchart TB
    Client["Web Client (Browser)"]:::client
    subgraph "Flask Application" 
        Run["Entrypoint: run.py"]:::entry
        Config["Configuration: config.py"]:::config

        subgraph "Blueprints (Controllers & Business Logic)"
            direction TB
            Home_Route["home: route.py"]:::blueprint
            Home_Model["home: use_model.py"]:::blueprint

            Login_Route["login: route.py"]:::blueprint
            Login_Model["login: use_model.py"]:::blueprint

            Register_Route["register: route.py"]:::blueprint
            Register_Model["register: use_model.py"]:::blueprint

            Cart_Route["cart: route.py"]:::blueprint
            Cart_Model["cart: use_model.py"]:::blueprint

            Orders_Route["orders: route.py"]:::blueprint
            Orders_Model["orders: use_model.py"]:::blueprint

            Pay_Route["pay: route.py"]:::blueprint
            Pay_Model["pay: use_model.py"]:::blueprint

            Admin_Route["admin: route.py"]:::blueprint
            Admin_Model["admin: use_model.py"]:::blueprint

            Redirect_Route["redirect: route.py"]:::blueprint
            Redirect_Model["redirect: use_model.py"]:::blueprint

            Reset_Route["reset_password: route.py"]:::blueprint
            Reset_Model["reset_password: use_model.py"]:::blueprint
        end

        subgraph "Data Access Layer (Models)"
            direction TB
            SQL_Conn["sql_connect.py"]:::model
            SQL_Set["sql_setting.py"]:::model
            Domain_User["user.py"]:::model
            Domain_Util["useful_string.py"]:::model
        end

        Templates["Templates (Jinja2)"]:::template
        Static["Static Assets (CSS/JS/Images)"]:::static
    end

    DB["MySQL Database"]:::database

    %% Connections
    Client -->|"HTTP Request"| Run
    Run --> Config
    Run -->|"Registers Blueprints"| Home_Route
    Config --> SQL_Conn
    Config --> Run

    Home_Route -->|"calls"| Home_Model
    Login_Route --> Login_Model
    Register_Route --> Register_Model
    Cart_Route --> Cart_Model
    Orders_Route --> Orders_Model
    Pay_Route --> Pay_Model
    Admin_Route --> Admin_Model
    Redirect_Route --> Redirect_Model
    Reset_Route --> Reset_Model

    Home_Model --> SQL_Conn
    Login_Model --> SQL_Conn
    Register_Model --> SQL_Conn
    Cart_Model --> SQL_Conn
    Orders_Model --> SQL_Conn
    Pay_Model --> SQL_Conn
    Admin_Model --> SQL_Conn
    Redirect_Model --> SQL_Conn
    Reset_Model --> SQL_Conn

    SQL_Conn --> SQL_Set
    SQL_Conn --> DB
    DB --> SQL_Conn

    Home_Route --> Templates
    Login_Route --> Templates
    Register_Route --> Templates
    Cart_Route --> Templates
    Orders_Route --> Templates
    Pay_Route --> Templates
    Admin_Route --> Templates
    Redirect_Route --> Templates
    Reset_Route --> Templates

    Templates -->|"Rendered HTML"| Client
    Static -->|"Served Assets"| Client

    %% Click Events
    click Run "https://github.com/justinlin63/flask_project1130/blob/master/run.py"
    click Config "https://github.com/justinlin63/flask_project1130/blob/master/app/config.py"
    click Home_Route "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/home/route.py"
    click Home_Model "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/home/use_model.py"
    click Login_Route "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/login/route.py"
    click Login_Model "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/login/use_model.py"
    click Register_Route "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/register/route.py"
    click Register_Model "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/register/use_model.py"
    click Cart_Route "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/cart/route.py"
    click Cart_Model "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/cart/use_model.py"
    click Orders_Route "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/orders/route.py"
    click Orders_Model "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/orders/use_model.py"
    click Pay_Route "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/pay/route.py"
    click Pay_Model "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/pay/use_model.py"
    click Admin_Route "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/admin/route.py"
    click Admin_Model "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/admin/use_model.py"
    click Redirect_Route "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/redirect/route.py"
    click Redirect_Model "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/redirect/use_model.py"
    click Reset_Route "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/reset_password/route.py"
    click Reset_Model "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/reset_password/use_model.py"
    click SQL_Conn "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/models/sql_connect.py"
    click SQL_Set "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/models/sql_setting.py"
    click Domain_User "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/models/user.py"
    click Domain_Util "https://github.com/justinlin63/flask_project1130/blob/master/app/functions/models/useful_string.py"
    click Templates "https://github.com/justinlin63/flask_project1130/tree/master/app/templates/"
    click Static "https://github.com/justinlin63/flask_project1130/tree/master/app/static/assets/"

    %% Styles
    classDef client fill:#BBDEFB,stroke:#0D47A1,color:#0D47A1
    classDef entry fill:#C8E6C9,stroke:#1B5E20,color:#1B5E20
    classDef config fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32
    classDef blueprint fill:#FFF3E0,stroke:#E65100,color:#E65100
    classDef model fill:#E1F5FE,stroke:#01579B,color:#01579B
    classDef template fill:#F3E5F5,stroke:#4A148C,color:#4A148C
    classDef static fill:#FFEBEE,stroke:#B71C1C,color:#B71C1C
    classDef database fill:#FFE0B2,stroke:#E65100,color:#E65100
```
