# web2py/py4web architecture

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

- Interactive diagram: https://gitdiagram.com/web2py/py4web
- Repository: https://github.com/web2py/py4web

## Overview

##### Main Components Identification

The system should be divided into these core components:

a) Core Framework Layer
- Request/Response Handling (based on ombott)
- Routing System
- Template Engine (YATL/Renoir)
- Database Abstraction (pyDAL)
- Authentication System
- Session Management
- Asset Management

b) Dashboard & Admin Interface
- File Editor
- Database Administration
- App Management
- Security Controls

c) Application Layer
- Multiple Apps Support
- Static Assets
- Templates
- Controllers
- Models

##### Specific Implementation Details

Technical elements:

**Client Layer**
- ↓ HTTP/HTTPS
**Server Layer (Multiple Adapters)**
- ↓ [wsgiref, tornado, gunicorn, gevent, etc.]
**Routing Layer (ombott-based)**
- ↓
**Core Framework**
- → Template Engine (YATL/Renoir)
- → Database (pyDAL)
- → Auth System
- → Session Handler (JWT/DB/Redis/Memcache)
- → Asset Manager
- ↓
**Applications Layer**
- → _dashboard (Admin Interface)
- → _default
- → user_apps

##### Technical Details

- Server adapter options
- Template syntax ([[...]] delimiters)
- Session storage options
- Authentication methods
- Static asset versioning (/{appname}/static/_0.0.0/{path})
- Cache implementation (memoize)

## Diagram (Mermaid)

```mermaid
graph TB
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef template fill:#2ecc71,stroke:#27ae60,color:white
    classDef db fill:#e67e22,stroke:#d35400,color:white
    classDef auth fill:#9b59b6,stroke:#8e44ad,color:white
    classDef session fill:#f1c40f,stroke:#f39c12,color:black
    classDef asset fill:#e74c3c,stroke:#c0392b,color:white
    classDef dashboard fill:#1abc9c,stroke:#16a085,color:white
    classDef app fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef server fill:#34495e,stroke:#2c3e50,color:white

    subgraph Client
        CL[Client Browser]
    end

    subgraph "Server Layer"
        SA["Server Adapters"]:::server
        click SA "https://github.com/web2py/py4web/tree/master/py4web/server_adapters/"
    end

    subgraph "Core Framework Layer"
        CF["Core Framework"]:::core
        click CF "https://github.com/web2py/py4web/blob/master/py4web/core.py"
        
        TE["Template Engine\nYATL/Renoir"]:::template
        click TE "https://github.com/web2py/py4web/blob/master/py4web/utils/factories.py"
        
        DB["Database Layer\npyDAL"]:::db
        
        AU["Authentication System"]:::auth
        click AU "https://github.com/web2py/py4web/blob/master/py4web/utils/auth.py"
        
        AP["Auth Plugins"]:::auth
        click AP "https://github.com/web2py/py4web/tree/master/py4web/utils/auth_plugins/"
        
        SH["Session Handler\nJWT/DB/Redis"]:::session
        
        AM["Asset Manager"]:::asset
        
        US["URL Signer"]:::auth
        click US "https://github.com/web2py/py4web/blob/master/py4web/utils/url_signer.py"
        
        SE["Security Utils"]:::auth
        click SE "https://github.com/web2py/py4web/blob/master/py4web/utils/security.py"
    end

    subgraph "Dashboard"
        DA["Dashboard Interface"]:::dashboard
        click DA "https://github.com/web2py/py4web/tree/master/apps/_dashboard/"
        
        DT["Dashboard Templates"]:::dashboard
        click DT "https://github.com/web2py/py4web/tree/master/apps/_dashboard/templates/"
        
        DB_ADMIN["Database Admin"]:::dashboard
        click DB_ADMIN "https://github.com/web2py/py4web/blob/master/apps/_dashboard/templates/dbadmin.html"
        
        FE["File Editor"]:::dashboard
        click FE "https://github.com/web2py/py4web/tree/master/apps/_dashboard/static/js/ace/"
    end

    subgraph "Applications Layer"
        SC["Scaffold Template"]:::app
        click SC "https://github.com/web2py/py4web/tree/master/apps/_scaffold/"
        
        MD["Models"]:::app
        click MD "https://github.com/web2py/py4web/blob/master/apps/_scaffold/models.py"
        
        CT["Controllers"]:::app
        click CT "https://github.com/web2py/py4web/blob/master/apps/_scaffold/controllers.py"
        
        AT["App Templates"]:::app
        click AT "https://github.com/web2py/py4web/tree/master/apps/_scaffold/templates/"
        
        ST["Static Assets"]:::app
        click ST "https://github.com/web2py/py4web/tree/master/apps/_scaffold/static/"
    end

    CL --> SA
    SA --> CF
    CF --> TE
    CF --> DB
    CF --> AU
    AU --> AP
    CF --> SH
    CF --> AM
    CF --> US
    CF --> SE
    
    CF --> DA
    DA --> DT
    DA --> DB_ADMIN
    DA --> FE
    
    CF --> SC
    SC --> MD
    SC --> CT
    SC --> AT
    SC --> ST

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Template Engine"]:::template
        L3["Database Components"]:::db
        L4["Auth Components"]:::auth
        L5["Session Handling"]:::session
        L6["Asset Management"]:::asset
        L7["Dashboard"]:::dashboard
        L8["Application"]:::app
        L9["Server"]:::server
    end
```
