# typecho/typecho architecture

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

- Interactive diagram: https://gitdiagram.com/typecho/typecho
- Repository: https://github.com/typecho/typecho

## Overview

##### High-Level Components

a) Frontend Layer
- Theme System (usr/themes/)
- Admin Interface (admin/)
- Public Interface

b) Core Application Layer
- Widget System (var/Widget/)
- Router (var/Typecho/Router/)
- Plugin System (var/Typecho/Plugin/)

c) Data Access Layer
- Database Abstraction (var/Typecho/Db/)
- Multiple Database Adapters
- MySQL
- PostgreSQL
- SQLite

##### Component Relationships

a) Request Flow:
**Client Request → Router → Widget System → Database Layer**

b) Extension Points:
**Core System ←→ Plugins**
**Theme System ←→ Template Files**

##### Specific Implementation Details

Key architectural elements:

a) Core Services (var/Typecho/):
- I18n (Internationalization)
- Config Management
- Request/Response Handling
- Router
- Feed Generation
- Security

b) Widget System:
- Content Management
- User Management
- Comment System
- Options Management
- Media Management

##### Key Architectural Patterns to Highlight

- MVC-like pattern with Widgets acting as Controllers
- Plugin architecture for extensibility
- Database abstraction layer for multiple database support
- Theme system for presentation layer customization

**┌─ Client Layer ─────────────────────┐**
- Admin Interface   Public Interface  │
- ┬─┘
**┌─ Application Layer ───────────────┴─┐**
- Router → Widgets → Core Services    │
- ↕         ↕                     │
- Plugins    Themes                  │
- ┬─┘
**┌─ Data Access Layer ───────────────┴─┐**
- Database Abstraction Layer          │
- MySQL │ PostgreSQL │ SQLite         │
- ┘

##### Technical Details

- PHP 7.4+ requirement
- Database version requirements
- Core feature modules:
- Markdown processing
- Custom fields
- XML-RPC support
- Media management

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        AdminUI["Admin Interface"]
        PublicUI["Public Interface"]
    end

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        %% Core Components
        Router["Router System"]:::core
        WidgetSystem["Widget System"]:::core
        
        %% Core Services
        subgraph CoreServices["Core Services"]
            I18n["Internationalization"]:::core
            Config["Configuration"]:::core
            Request["Request Handler"]:::core
            Response["Response Handler"]:::core
            Feed["Feed Generator"]:::core
        end
        
        %% Widget Components
        subgraph Widgets["Widget Components"]
            Content["Content Management"]:::widget
            Users["User Management"]:::widget
            Comments["Comment System"]:::widget
            Media["Media Management"]:::widget
        end
        
        %% Extension Systems
        PluginSystem["Plugin System"]:::extension
        ThemeSystem["Theme System"]:::extension
    end
    
    %% Data Access Layer
    subgraph DataLayer["Data Access Layer"]
        DbAbstraction["Database Abstraction Layer"]:::database
        MySQL["MySQL Adapter"]:::database
        PostgreSQL["PostgreSQL Adapter"]:::database
        SQLite["SQLite Adapter"]:::database
    end

    %% Relationships
    AdminUI & PublicUI --> Router
    Router --> WidgetSystem
    WidgetSystem --> CoreServices
    WidgetSystem --> Widgets
    WidgetSystem <--> PluginSystem
    WidgetSystem <--> ThemeSystem
    Widgets --> DbAbstraction
    DbAbstraction --> MySQL & PostgreSQL & SQLite

    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef extension fill:#4CAF50,stroke:#2E7D32,color:white
    classDef database fill:#FFC107,stroke:#FFA000,color:black
    classDef widget fill:#9C27B0,stroke:#7B1FA2,color:white

    %% Click Events
    click AdminUI "https://github.com/typecho/typecho/tree/master/admin/"
    click ThemeSystem "https://github.com/typecho/typecho/tree/master/usr/themes/"
    click WidgetSystem "https://github.com/typecho/typecho/tree/master/var/Widget/"
    click Router "https://github.com/typecho/typecho/tree/master/var/Typecho/Router/"
    click PluginSystem "https://github.com/typecho/typecho/tree/master/var/Typecho/Plugin/"
    click DbAbstraction "https://github.com/typecho/typecho/tree/master/var/Typecho/Db/"
    click MySQL "https://github.com/typecho/typecho/blob/master/var/Typecho/Db/Adapter/Mysqli.php"
    click PostgreSQL "https://github.com/typecho/typecho/blob/master/var/Typecho/Db/Adapter/Pgsql.php"
    click SQLite "https://github.com/typecho/typecho/blob/master/var/Typecho/Db/Adapter/SQLite.php"
    click I18n "https://github.com/typecho/typecho/tree/master/var/Typecho/I18n/"
    click Config "https://github.com/typecho/typecho/blob/master/var/Typecho/Config.php"
    click Request "https://github.com/typecho/typecho/blob/master/var/Typecho/Request.php"
    click Response "https://github.com/typecho/typecho/blob/master/var/Typecho/Response.php"
    click Feed "https://github.com/typecho/typecho/blob/master/var/Typecho/Feed.php"
    click Content "https://github.com/typecho/typecho/tree/master/var/Widget/Contents/"
    click Users "https://github.com/typecho/typecho/tree/master/var/Widget/Users/"
    click Comments "https://github.com/typecho/typecho/tree/master/var/Widget/Comments/"
    click Media "https://github.com/typecho/typecho/tree/master/var/Widget/Contents/Attachment/"
```
