# gicehajunior/sproutpy-framework architecture

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

- Interactive diagram: https://gitdiagram.com/gicehajunior/sproutpy-framework
- Repository: https://github.com/gicehajunior/sproutpy-framework

## Overview

##### Main Components
- Framework Core (sproutpy package): This includes modules such as DatabaseManager, Router, SprouteApp, SprouteRequest, SprouteRequestHandler, TemplatingEngine, and Helper. They are the internal backbone of the framework, handling routing, database interactions, request processing, and templating.
- Application Layer (app directory): This encompasses the HTTP-related components:
- Controllers (in app/http/controllers) like DashboardController
- Authentication (in app/http/authentication & models) including AuthController, middleware for authentication (app/http/middlewares/Auth.py, app/models/Auth.py)
- Utilities (in app/http/utils) for helper functionality.
- Configuration (config directory): Contains config files for overall app settings and database configuration.
- Resources (resources directory): Houses HTML templates and layout files (like header, footer, and authentication views) that are rendered by the templating engine.
- Routes (routes directory): Responsible for defining the URL mapping (the routes/pathway.py file) that ties HTTP requests to controllers.
- Public Assets (public directory): Contains static files such as CSS, JS (including public/index.js), and other asset files that are built using Node/npm and Webpack.
- Tests (tests directory): Contains unit tests and documentation on testing approaches.

##### Relationships and Interactions
- The controller (in app/http/controllers) handles the business logic, and if required, communicates with models for data interactions.
- The views (resources directory) are rendered using the templating engine (sproutepy/TemplatingEngine.py), and final HTML output is sent back to the client.
- An authentication flow is evident—from HTTP request authentication, middleware validation (app/http/middlewares/Auth.py) to corresponding controller actions.
- Configuration settings from the config files (config/configuration.py and config/database.py) are used throughout the app and by the Sproutpy core components.
- The asset flow is managed separately via Node.js and built with Webpack (webpack.config.js, package.json, package-lock.json), and these assets reside in the public directory.

##### Architectural Patterns and Design Principles
- The framework uses an MVC-like pattern: Controllers and Models exist in the app directory, and Views are separated into the resources directory.
- Separation of concerns is emphasized through distinct directories (configuration, public assets, tests, and sproutepy core libraries).
- The modular design of the sproutepy library, including the Router and RequestHandler components, indicates adherence to a layered architecture.
- There’s clear integration between the backend (Python, HTTP handling) and frontend assets (built via Node/npm).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    Client["Client Browser"]:::external

    %% Entry Point
    Serve["serve.py"]

    %% Framework Core Subgraph
    subgraph "Framework Core"
        SpApp["SprouteApp"]:::framework
        Router["Router"]:::framework
        Request["SprouteRequest"]:::framework
        RequestHandler["SprouteRequestHandler"]:::framework
        Templating["TemplatingEngine"]:::framework
        DBManager["DatabaseManager"]:::framework
        Helper["Helper"]:::framework
    end

    %% Routes Subgraph
    subgraph "Routes"
        RouteMapping["RouteMapping"]:::config
    end

    %% Application Layer Subgraph
    subgraph "Application Layer"
        DashboardCtrl["DashboardController"]:::application
        AuthCtrl["AuthController"]:::application
        AuthMiddle["AuthMiddleware"]:::application
        AuthModel["AuthModel"]:::application
        AuthUtil["AuthUtil"]:::application
        Util["Util"]:::application
    end

    %% Configuration Subgraph
    subgraph "Configuration"
        AppConfig["AppConfig"]:::config
        DBConfig["DatabaseConfig"]:::config
    end

    %% Resources Subgraph
    subgraph "Resources"
        Login["login.html"]:::resources
        Signup["signup.html"]:::resources
        PartialsHeader["partials/header.html"]:::resources
        LayoutHeader["layout/header.html"]:::resources
        LayoutFooter["layout/footer.html"]:::resources
        DashboardView["dashboard.html"]:::resources
    end

    %% Public Assets Subgraph
    subgraph "Public Assets"
        IndexJS["index.js"]:::public
        AuthCSS["auth.css"]:::public
        MainCSS["main.css"]:::public
    end

    %% Asset Build Subgraph
    subgraph "Asset Build"
        Webpack["webpack.config.js"]:::asset
        PackageJSON["package.json"]:::asset
        PackageLock["package-lock.json"]:::asset
    end

    %% Tests Subgraph
    subgraph "Tests"
        TestsNode["Tests (readMe.md)"]:::tests
    end

    %% Flow Connections for Dynamic Request
    Client --> Serve
    Serve --> SpApp
    SpApp --> Router
    Router --> RouteMapping
    RouteMapping --> DashboardCtrl
    RouteMapping --> AuthCtrl

    %% Framework Core internal connections
    SpApp --> RequestHandler
    SpApp --> Request
    RequestHandler --> AuthMiddle
    DashboardCtrl --> Templating
    AuthCtrl --> Templating
    AuthMiddle --> AuthCtrl
    DashboardCtrl --> Helper
    AuthCtrl --> AuthUtil
    AuthCtrl --> Util

    %% Templating Engine renders Resources (Views)
    Templating -->|"renders"| DashboardView
    Templating -- "renders" --> Login
    Templating -- "renders" --> Signup
    Templating -- "renders" --> PartialsHeader
    Templating -- "renders" --> LayoutHeader
    Templating -- "renders" --> LayoutFooter

    %% Templating sends response back to Client
    Templating --> Client

    %% Configuration influences Framework Core
    AppConfig --- SpApp
    DBConfig --- DBManager

    %% Static Asset Flow
    Client --- IndexJS
    Webpack -->|builds| IndexJS
    PackageJSON -->|builds| IndexJS
    PackageLock -->|builds| IndexJS
    Webpack -->|builds| AuthCSS
    PackageJSON -->|builds| AuthCSS
    PackageLock -->|builds| AuthCSS
    Webpack -->|builds| MainCSS
    PackageJSON -->|builds| MainCSS
    PackageLock -->|builds| MainCSS

    %% Class Definitions
    classDef external fill:#fff,stroke:#000,stroke-width:2px;
    classDef framework fill:#ADD8E6,stroke:#0000FF,stroke-width:2px;
    classDef application fill:#90EE90,stroke:#008000,stroke-width:2px;
    classDef config fill:#FFFACD,stroke:#DAA520,stroke-width:2px;
    classDef resources fill:#FFDAB9,stroke:#FF8C00,stroke-width:2px;
    classDef public fill:#FFC0CB,stroke:#FF1493,stroke-width:2px;
    classDef tests fill:#D3D3D3,stroke:#696969,stroke-width:2px;
    classDef asset fill:#E6E6FA,stroke:#8A2BE2,stroke-width:2px;

    %% Click Events for Framework Core
    click DBManager "https://github.com/gicehajunior/sproutpy-framework/blob/main/sproutepy/DatabaseManager.py"
    click Helper "https://github.com/gicehajunior/sproutpy-framework/blob/main/sproutepy/Helper.py"
    click Router "https://github.com/gicehajunior/sproutpy-framework/blob/main/sproutepy/Router.py"
    click SpApp "https://github.com/gicehajunior/sproutpy-framework/blob/main/sproutepy/SprouteApp.py"
    click Request "https://github.com/gicehajunior/sproutpy-framework/blob/main/sproutepy/SprouteRequest.py"
    click RequestHandler "https://github.com/gicehajunior/sproutpy-framework/blob/main/sproutepy/SprouteRequestHandler.py"
    click Templating "https://github.com/gicehajunior/sproutpy-framework/blob/main/sproutepy/TemplatingEngine.py"

    %% Click Events for Application Layer
    click DashboardCtrl "https://github.com/gicehajunior/sproutpy-framework/blob/main/app/http/controllers/DashboardController.py"
    click AuthCtrl "https://github.com/gicehajunior/sproutpy-framework/blob/main/app/http/authentication/AuthController.py"
    click AuthMiddle "https://github.com/gicehajunior/sproutpy-framework/blob/main/app/http/middlewares/Auth.py"
    click AuthModel "https://github.com/gicehajunior/sproutpy-framework/blob/main/app/models/Auth.py"
    click AuthUtil "https://github.com/gicehajunior/sproutpy-framework/blob/main/app/http/utils/AuthUtil.py"
    click Util "https://github.com/gicehajunior/sproutpy-framework/blob/main/app/http/utils/Util.py"

    %% Click Events for Configuration
    click AppConfig "https://github.com/gicehajunior/sproutpy-framework/blob/main/config/configuration.py"
    click DBConfig "https://github.com/gicehajunior/sproutpy-framework/blob/main/config/database.py"

    %% Click Events for Resources
    click Login "https://github.com/gicehajunior/sproutpy-framework/blob/main/resources/auth/login.html"
    click Signup "https://github.com/gicehajunior/sproutpy-framework/blob/main/resources/auth/signup.html"
    click PartialsHeader "https://github.com/gicehajunior/sproutpy-framework/blob/main/resources/auth/partials/header.html"
    click LayoutHeader "https://github.com/gicehajunior/sproutpy-framework/blob/main/resources/layout/header.html"
    click LayoutFooter "https://github.com/gicehajunior/sproutpy-framework/blob/main/resources/layout/footer.html"
    click DashboardView "https://github.com/gicehajunior/sproutpy-framework/blob/main/resources/views/dashboard.html"

    %% Click Events for Routes
    click RouteMapping "https://github.com/gicehajunior/sproutpy-framework/blob/main/routes/pathway.py"

    %% Click Events for Public Assets
    click IndexJS "https://github.com/gicehajunior/sproutpy-framework/blob/main/public/index.js"
    click AuthCSS "https://github.com/gicehajunior/sproutpy-framework/blob/main/public/asst/css/auth.css"
    click MainCSS "https://github.com/gicehajunior/sproutpy-framework/blob/main/public/asst/css/main.css"

    %% Click Events for Tests
    click TestsNode "https://github.com/gicehajunior/sproutpy-framework/blob/main/tests/readMe.md"
    
    %% Click Events for Asset Build (if needed)
    click Webpack "https://github.com/gicehajunior/sproutpy-framework/blob/main/webpack.config.js"
    click PackageJSON "https://github.com/gicehajunior/sproutpy-framework/blob/main/package.json"
    click PackageLock "https://github.com/gicehajunior/sproutpy-framework/blob/main/package-lock.json"
```
