# tsxcw/mtab architecture

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

- Interactive diagram: https://gitdiagram.com/tsxcw/mtab
- Repository: https://github.com/tsxcw/mtab

## Overview

##### Project Type and Purpose
- mTab is a full‐stack, self‐hostable bookmarks & notes management web application with optional browser‐extension and online tools.
- The README confirms it uses Docker, supports private deployment, a PHP backend, a JS/Vue front‐end, Redis, and MySQL.

##### High‐Level Architectural Components
a. Clients
- Web Browser (Vue.js‐based Single Page Application served from public/dist)
- Mobile Browser (responsive web UI)
- Browser Extension (built under extend/browserExt + extend/main.go)
b. Edge/Proxy
- Nginx (reverse proxy, serves static assets + routes PHP requests)
c. Application Layer
- PHP‐FPM process running ThinkPHP (app/ directory):
- Controllers (app/controller)
- Models (app/model)
- Views (app/view for install and error pages)
- Commands (app/command for CLI tasks)
- Custom extensions (extend/ directory for plugins, mail, image, upgrade)
d. Persistence
- MySQL (config/database.php; defaultData.sql; install.sql)
- Redis (session/cache queue; configured via docker/redis.conf)
e. External/Third‐Party Services
- IP Geolocation DB (app/controller/apps/weather/ipLocation)
- OAuth Provider (QQ login via app/view/qq_login.html, network calls in extend/Axios.php)
f. DevOps / Infrastructure
- Docker Compose (docker-compose.yml) orchestrates Nginx, PHP, Redis, MySQL
- Configuration files (docker/, config/, env.php)

##### Relationships and Data Flow
- Clients issue HTTP(S) requests to Nginx.
- Nginx serves static assets (JS/CSS from public/dist) or proxies API calls to PHP‐FPM.
- PHP‐FPM (ThinkPHP) routes requests (config/route.php) → Controller → Model → Database/Redis → Controller → JSON/HTML Response.
- CLI tools (app/command) run inside the PHP container for maintenance tasks.
- Browser extension communicates with the same API endpoints to sync data.
- OAuth login and IP Geo lookups call external services or use bundled DB.

##### Architectural Patterns and Design Principles
- Monolithic MVC application using ThinkPHP.
- 12-factor principles in Dockerized deployment.
- Clear separation of concerns:
- Presentation: public/dist (Vue) + app/view (PHP)
- Business Logic: app/controller + app/service
- Data Access: app/model
- Extensions: extend/
- Plugin system: extend/PluginsStaticSystem, PluginsInstall → modular extensibility.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Clients"
        Browser["Web & Mobile Browser"]:::ui
        Extension["Browser Extension"]:::ui
    end

    subgraph "Docker Compose Network"
        Nginx["Nginx Reverse Proxy\n(HTTP/80)"]:::app
        phpini["PHP-FPM Config"]:::app
        PHPFPM["PHP-FPM (ThinkPHP MVC)"]:::app
        subgraph "ThinkPHP Core"
            Controllers["Controllers"]:::app
            Models["Models"]:::app
            Commands["Commands (CLI)"]:::app
            Services["Services & Bootstrap"]:::app
            Exception["Exception & Middleware"]:::app
        end
        Redis["Redis Session Cache\n(port 6379)"]:::data
        MySQL["MySQL Database\n(port 3306)"]:::data
        DC["Docker Compose"]:::app
    end

    subgraph "External Services"
        OAuth["OAuth Provider\n(QQ Login)"]:::external
        GeoIP["IP Geolocation DB"]:::external
    end

    Browser -->|"HTTP/HTTPS"| Nginx
    Extension -->|"HTTP API"| Nginx
    Nginx -->|"Serves JS/CSS"| VueSPA
    Nginx -->|"Proxies API"| PHPFPM
    Nginx -->|"Serves PHP Views"| PHPViews

    PHPFPM --> Controllers
    PHPFPM --> Models
    PHPFPM --> Services
    PHPFPM --> Exception
    PHPFPM --> Redis
    PHPFPM --> MySQL
    PHPFPM --> OAuth
    PHPFPM --> GeoIP

    DC --> Nginx
    DC --> PHPFPM
    DC --> Redis
    DC --> MySQL

    click VueSPA "https://github.com/tsxcw/mtab/tree/itushan/public/dist/"
    click Extension "https://github.com/tsxcw/mtab/tree/itushan/extend/browserExt/"
    click PHPViews "https://github.com/tsxcw/mtab/tree/itushan/app/view/"
    click Controllers "https://github.com/tsxcw/mtab/tree/itushan/app/controller/"
    click Models "https://github.com/tsxcw/mtab/tree/itushan/app/model/"
    click Commands "https://github.com/tsxcw/mtab/tree/itushan/app/command/"
    click Services "https://github.com/tsxcw/mtab/blob/itushan/app/AppService.php"
    click Exception "https://github.com/tsxcw/mtab/blob/itushan/app/ExceptionHandle.php"
    click Redis "https://github.com/tsxcw/mtab/blob/itushan/docker/redis.conf"
    click MySQL "https://github.com/tsxcw/mtab/blob/itushan/config/database.php"
    click OAuth "https://github.com/tsxcw/mtab/blob/itushan/app/view/qq_login.html"
    click GeoIP "https://github.com/tsxcw/mtab/blob/itushan/app/controller/apps/weather/ipLocation/IP2LOCATION-LITE-DB5.BIN"
    click DC "https://github.com/tsxcw/mtab/blob/itushan/docker-compose.yaml"
    click phpini "https://github.com/tsxcw/mtab/blob/itushan/docker/php.ini"
    click Nginx "https://github.com/tsxcw/mtab/blob/itushan/docker/nginx.conf"

    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef app fill:#9FE2BF,stroke:#333,stroke-width:1px;
    classDef data fill:#FFFF99,stroke:#333,stroke-width:1px;
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px;
```
