# goyam02/flask_blog architecture

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

- Interactive diagram: https://gitdiagram.com/goyam02/flask_blog
- Repository: https://github.com/goyam02/flask_blog

## Overview

##### Project Type and Purpose
- This is a monolithic, full-stack web application built with Flask.
- Purpose: Provide a blogging platform with user authentication, profile management, password reset, and CRUD operations for posts.

##### File Structure
- Top-level files:
– run.py: Application entry point
– config.py: App configuration and environment variables
– requirements.txt: Python dependencies
– instance/site.db: SQLite database
- flaskblog/ package:
– __init__.py: Creates the Flask app, initializes extensions (SQLAlchemy, Flask-Login, Bcrypt, Flask-Mail)
– models.py: Defines User and Post ORM models
– errors/: Error-handler blueprint
– main/: “Main” blueprint for static pages and home feed
– users/: “Users” blueprint for registration, login, profile, password reset
– posts/: “Posts” blueprint for create/read/update/delete blog posts
– static/: CSS, profile pictures
– templates/: Jinja2 HTML templates (layout + views)

##### Extract Insights from the README
- Technical stack: Flask, Flask-SQLAlchemy, Flask-WTForms, Flask-Login, Flask-Mail, Bcrypt, SQLite, Bootstrap
- Features called out map directly to blueprints / modules in the file structure.

##### Components
a. Client Layer
– Web Browser
– Static assets (CSS, profile pics)
b. Application Layer (Flask App)
– Blueprints (Main, Users, Posts, Errors)
– Form Validation (Flask-WTForms)
– Business Logic (routes.py in each blueprint)
– Extensions:
- Flask-SQLAlchemy (ORM)
- Flask-Login (session management)
- Flask-Mail (SMTP integration)
- Bcrypt (password hashing)
c. Data Layer
– SQLite database (site.db)
d. External Services
– SMTP email provider
e. Configuration / Deployment
– Environment variables (SECRET_KEY, EMAIL_USER, EMAIL_PASS)
– run.py launches the Flask development server

##### Relationships and Data Flows
- Requests: Browser → Flask App (run.py)
- Routing: App dispatches to individual blueprints → route handlers
- Business Logic: Handlers validate forms → invoke ORM → read/write DB
- Authentication: Flask-Login checks session → protected routes
- Email: Password reset requests → Flask-Mail → SMTP server
- Responses: Jinja2 renders templates → HTML → Browser
- Static files: Served directly via Flask’s static endpoint

##### Architectural Patterns & Principles
- Blueprint-based modularization (separate concerns: users, posts, errors, main)
- MVC-like separation:
– Models: flaskblog/models.py
– Views/Templates: flaskblog/templates/*.html
– Controllers: blueprint routes
- Single-process monolith: All code lives in one Flask application
- Layered architecture: Presentation (templates + static), Application (routes + forms), Data (ORM + DB), External (mail server)

##### Final Checklist
- All components (Client, Static, Blueprints, Extensions, Database, SMTP) are present
- Groupings/boundaries to show modular structure (flaskblog package subdivisions)

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Client Layer"
        B["Web Browser"]:::frontend
        Static["Static Assets (CSS, profile_pics)"]:::frontend
    end

    subgraph "Application Layer"
        Run["run.py"]:::backend
        Config["config.py"]:::backend
        Init["__init__.py"]:::backend
        Models["models.py"]:::backend
        Extensions["Extensions\n(SQLAlchemy, Flask-Login, Flask-Mail, Bcrypt)"]:::backend
        Templates["Jinja2 Templates"]:::backend

        subgraph "Blueprints"
            subgraph "Main Blueprint"
                MainInit["main/__init__.py"]:::backend
                MainRoutes["main/routes.py"]:::backend
            end
            subgraph "Users Blueprint"
                UsersInit["users/__init__.py"]:::backend
                UsersRoutes["users/routes.py"]:::backend
                UsersForms["users/forms.py"]:::backend
                UsersUtils["users/utils.py"]:::backend
            end
            subgraph "Posts Blueprint"
                PostsInit["posts/__init__.py"]:::backend
                PostsRoutes["posts/routes.py"]:::backend
                PostsForms["posts/forms.py"]:::backend
            end
            subgraph "Errors Blueprint"
                ErrorsInit["errors/__init__.py"]:::backend
                ErrorsHandlers["errors/handlers.py"]:::backend
            end
        end
    end

    subgraph "Instance"
        DB["site.db"]:::data
    end

    subgraph "Config & Docs"
        Req["requirements.txt"]:::backend
        Readme["README.md"]:::backend
        GIt[".gitignore"]:::backend
    end

    subgraph "External Services"
        SMTP["SMTP Email Provider"]:::external
    end

    B -->|HTTP| Run
    Run -->|loads| Init
    Init --> Config
    Init --> Extensions
    Init --> Models
    Init --> MainInit
    Init --> UsersInit
    Init --> PostsInit
    Init --> ErrorsInit

    MainInit --> MainRoutes
    UsersInit --> UsersRoutes
    PostsInit --> PostsRoutes
    ErrorsInit --> ErrorsHandlers

    MainRoutes -->|renders| Templates
    UsersRoutes -->|renders| Templates
    PostsRoutes -->|renders| Templates

    UsersRoutes -->|validate forms| UsersForms
    PostsRoutes -->|validate forms| PostsForms

    UsersRoutes -->|auth| Extensions
    UsersRoutes -->|password reset| Extensions

    UsersRoutes -->|send email| Extensions
    Extensions -->|SMTP| SMTP

    MainRoutes -->|ORM calls| Models
    UsersRoutes -->|ORM calls| Models
    PostsRoutes -->|ORM calls| Models

    Models -->|SQL| DB
    DB -->|data| Models

    Run -->|serves static| Static
    Static -->|HTTP| B
    Run -->|HTTP response| B

    click Run "https://github.com/goyam02/flask_blog/blob/master/run.py"
    click Config "https://github.com/goyam02/flask_blog/blob/master/flaskblog/config.py"
    click Init "https://github.com/goyam02/flask_blog/blob/master/flaskblog/__init__.py"
    click Models "https://github.com/goyam02/flask_blog/blob/master/flaskblog/models.py"
    click MainInit "https://github.com/goyam02/flask_blog/blob/master/flaskblog/main/__init__.py"
    click MainRoutes "https://github.com/goyam02/flask_blog/blob/master/flaskblog/main/routes.py"
    click UsersInit "https://github.com/goyam02/flask_blog/blob/master/flaskblog/users/__init__.py"
    click UsersRoutes "https://github.com/goyam02/flask_blog/blob/master/flaskblog/users/routes.py"
    click UsersForms "https://github.com/goyam02/flask_blog/blob/master/flaskblog/users/forms.py"
    click UsersUtils "https://github.com/goyam02/flask_blog/blob/master/flaskblog/users/utils.py"
    click PostsInit "https://github.com/goyam02/flask_blog/blob/master/flaskblog/posts/__init__.py"
    click PostsRoutes "https://github.com/goyam02/flask_blog/blob/master/flaskblog/posts/routes.py"
    click PostsForms "https://github.com/goyam02/flask_blog/blob/master/flaskblog/posts/forms.py"
    click ErrorsInit "https://github.com/goyam02/flask_blog/blob/master/flaskblog/errors/__init__.py"
    click ErrorsHandlers "https://github.com/goyam02/flask_blog/blob/master/flaskblog/errors/handlers.py"
    click Static "https://github.com/goyam02/flask_blog/blob/master/flaskblog/static/main.css"
    click Static "https://github.com/goyam02/flask_blog/tree/master/flaskblog/static/profile_pics/"
    click Templates "https://github.com/goyam02/flask_blog/tree/master/flaskblog/templates/"
    click DB "https://github.com/goyam02/flask_blog/blob/master/instance/site.db"
    click Req "https://github.com/goyam02/flask_blog/blob/master/requirements.txt"
    click Readme "https://github.com/goyam02/flask_blog/blob/master/README.md"
    click GIt "https://github.com/goyam02/flask_blog/blob/master/.gitignore"

    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef data fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#FFFF00,stroke:#000,stroke-width:1px
```
