# vapor/university architecture

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

- Interactive diagram: https://gitdiagram.com/vapor/university
- Repository: https://github.com/vapor/university

## Overview

##### Project type and purpose
- This is a full-stack Swift web application built on the Vapor framework. It consists of two Vapor “microservices” or modules:
- api – a JSON API service exposing tutorial data (CRUD).
- client – a server-side rendered web front end that fetches data from the API, renders Leaf templates, and serves static assets.
- The README also mentions an iOS app (not in the repo), implying a third potential client of the same API.

##### File structure
- Top-level directories:
- api/ – a standalone Vapor Droplet configured via Config/*.json, defining Controllers, Models, Migrations.
- client/ – another Vapor Droplet with Leaf views (Resources/Views), static files (Public/), plus a RESTDriver to consume the API.
- design/ – Sketch file for the web UI mockup.
- Within each module you see an MVC pattern:
- Controllers ↔ Models ↔ Views (Leaf in client, JSON in api).
- Middleware (e.g. NotFound.swift, RequestFailedMiddleware.swift).
- Configuration files (droplet.json, server.json, mysql.json) define environment parameters.
- Package.swift & Package.pins in each module declare the Swift dependencies (Vapor, Fluent, Leaf).

##### README for additional insights
- Confirms the dual-service architecture: “Web application, iOS app, and API providing access to tutorials for the Vapor web framework.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Clients"
        Browser["Web Browser"]:::client
        iOSApp["iOS App"]:::client
    end

    subgraph "Web Server (client/)"
        subgraph "Configuration"
            C1["droplet.json"]:::config
            C2["development/app.json"]:::config
            C3["production/app.json"]:::config
            C4["production/server.json"]:::config
        end
        MiddlewareClient["RequestFailedMiddleware.swift"]:::code
        RESTDriver["RESTDriver.swift"]:::code
        ModelsClient["Models (Tutorial.swift, Database.swift)"]:::code
        ViewsClient["Leaf Templates (layout.leaf, error.leaf, Includes)"]:::code
        StaticClient["Static Assets (styles, images)"]:::code
        EntryClient["main.swift"]:::code
        PackageClient["Package.swift"]:::code
    end

    subgraph "API Server (api/)"
        subgraph "Configuration"
            A_C1["droplet.json"]:::config
            A_C2["fluent.json"]:::config
            A_C3["mysql.json"]:::config
            A_C4["server.json"]:::config
            A_C5["production/servers.json"]:::config
        end
        MiddlewareAPI["NotFound.swift"]:::code
        ControllerAPI["Tutorials.swift"]:::code
        ModelsAPI["Models & Migrations"]:::code
        MigrationAPI["AddVersion.swift"]:::code
        EntryAPI["main.swift"]:::code
        PackageAPI["Package.swift"]:::code
    end

    DB["MySQL Database"]:::db

    Browser -->|HTTP/HTML| EntryClient
    EntryClient -->|renders| ViewsClient
    EntryClient -->|serves| StaticClient
    EntryClient -->|fetch JSON| RESTDriver
    RESTDriver -->|HTTP/JSON| ControllerAPI
    ControllerAPI -->|uses| ModelsAPI
    ControllerAPI -->|runs| MigrationAPI
    ControllerAPI -->|SQL Queries| DB
    iOSApp -->|HTTP/JSON| ControllerAPI

    click C1 "https://github.com/vapor/university/blob/main/client/Config/droplet.json"
    click C2 "https://github.com/vapor/university/blob/main/client/Config/development/app.json"
    click C3 "https://github.com/vapor/university/blob/main/client/Config/production/app.json"
    click C4 "https://github.com/vapor/university/blob/main/client/Config/production/server.json"
    click MiddlewareClient "https://github.com/vapor/university/blob/main/client/Sources/Web/RequestFailedMiddleware.swift"
    click RESTDriver "https://github.com/vapor/university/blob/main/client/Sources/VaporUniversity/RESTDriver.swift"
    click ModelsClient "https://github.com/vapor/university/blob/main/client/Sources/VaporUniversity/Models/Tutorial.swift"
    click EntryClient "https://github.com/vapor/university/blob/main/client/Sources/Web/main.swift"
    click PackageClient "https://github.com/vapor/university/blob/main/client/Package.swift"
    click A_C1 "https://github.com/vapor/university/blob/main/api/Config/droplet.json"
    click A_C2 "https://github.com/vapor/university/blob/main/api/Config/fluent.json"
    click A_C3 "https://github.com/vapor/university/blob/main/api/Config/mysql.json"
    click A_C4 "https://github.com/vapor/university/blob/main/api/Config/server.json"
    click A_C5 "https://github.com/vapor/university/blob/main/api/Config/production/servers.json"
    click MiddlewareAPI "https://github.com/vapor/university/blob/main/api/Sources/App/Middleware/NotFound.swift"
    click ControllerAPI "https://github.com/vapor/university/blob/main/api/Sources/App/Controllers/Tutorials.swift"
    click ModelsAPI "https://github.com/vapor/university/blob/main/api/Sources/App/Models/Tutorial/Tutorial.swift"
    click MigrationAPI "https://github.com/vapor/university/blob/main/api/Sources/App/Migrations/AddVersion.swift"
    click EntryAPI "https://github.com/vapor/university/blob/main/api/Sources/App/main.swift"
    click PackageAPI "https://github.com/vapor/university/blob/main/api/Package.swift"

    classDef service fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef db fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef client fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef config fill:#E0E0E0,stroke:#333;
    classDef code fill:#F5F5F5,stroke:#333;
```
