# 9fans/plan9port architecture

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

- Interactive diagram: https://gitdiagram.com/9fans/plan9port
- Repository: https://github.com/9fans/plan9port

## Overview

#### Purpose and entry points
Plan 9 from User Space (plan9port) ports Plan 9 libraries, commands, protocols, and desktop tools to Unix hosts. Installation starts at `./INSTALL`, with top-level build orchestration in `Makefile` and `configure`; it first bootstraps the Plan 9-style `mk` build tool, then builds the rest. User-facing launchers and compatibility commands are installed from `bin/`.

#### Build and portability layer
The repository supports Unix-family platforms through per-OS make fragments and C adaptation layers. The native Unix build path is represented by `unix/make/Makefile.all`, `unix/make/Makefile.CMD`, and OS files such as `unix/make/Make.Linux`. The internal `mk` implementation is a primary bootstrap/runtime dependency: `src/cmd/mk/main.c`, `src/cmd/mk/graph.c`, `src/cmd/mk/job.c`. Project-specific source-build scripts are centralized under `src/mkfile`, `src/mkmk.sh`, and `src/mkcommon`.

#### Core compatibility libraries
Most programs target Plan 9 interfaces rather than direct Unix APIs. `src/lib9/` supplies the base runtime—process, filesystem, networking, error, formatting, and UTF behavior—anchored by `src/lib9/mkfile`, `src/lib9/main.c`, and `src/lib9/rfork.c`. Common API contracts are exposed through `include/libc.h`, `include/u.h`, and `include/utf.h`. Higher-level reusable libraries provide buffered I/O (`src/libbio/`), cooperative threading (`src/libthread/`), regular expressions (`src/libregexp/`), cryptography (`src/libsec/`), and IP utilities (`src/libip/`).

#### 9P namespace and service boundary
9P is the central remote-filesystem/service protocol boundary. Server-side primitives live in `src/lib9p/srv.c`, `src/lib9p/fid.c`, and `src/lib9p/req.c`; client-side filesystem operations live in `src/lib9pclient/fs.c`, `src/lib9pclient/walk.c`, and `src/lib9pclient/auth.c`. Commands such as `src/cmd/9p.c`, `src/cmd/9pserve.c`, and `src/cmd/9pfuse/main.c` expose, inspect, or bridge 9P services to Unix/FUSE environments.

#### Graphics, windows, and interactive tools
The draw stack separates client graphics APIs from host display backends. `src/libdraw/drawclient.c`, `src/libdraw/window.c`, and `src/libmemdraw/draw.c` implement drawing and in-memory rendering; `src/cmd/devdraw/devdraw.c` bridges to macOS/X11 backends. Interactive applications build above this boundary: the Rio window system (`src/cmd/rio/main.c`, `src/cmd/rio/manage.c`), Acme editor (`src/cmd/acme/acme.c`, `src/cmd/acme/fsys.c`), Sam editor (`src/cmd/sam/sam.c`), and `9term` terminal (`src/cmd/9term/9term.c`).

#### System services and persistent storage
Several substantial service implementations run as Unix processes while presenting Plan 9 interfaces. Fossil is a 9P archival filesystem with disk/cache logic (`src/cmd/fossil/fossil.c`, `src/cmd/fossil/9p.c`, `src/cmd/fossil/fs.c`). Venti is content-addressed block storage, split between client library (`src/libventi/client.c`, `src/libventi/rpc.c`) and server arena/index management (`src/cmd/venti/srv/venti.c`, `src/cmd/venti/srv/arena.c`, `src/cmd/venti/srv/index.c`). VAC and backup tools connect filesystem snapshots to Venti (`src/cmd/vac/vac.c`, `src/cmd/vbackup/vbackup.c`).

#### Network, authentication, and messaging
The distribution includes network-facing Unix services and clients: DNS/NDB (`src/cmd/ndb/dnserver.c`, `src/libndb/dnsquery.c`), authentication/key-agent functionality (`src/cmd/auth/factotum/main.c`, `src/libauth/auth_rpc.c`), and UPAS mail transport/storage (`src/cmd/upas/smtp/smtpd.c`, `src/cmd/upas/send/main.c`, `src/cmd/upas/fs/fs.c`). These components use external network services such as DNS, SMTP/IMAP/POP, SSH-compatible authentication, and 9P peers.

#### Distribution assets and command ecosystem
`src/cmd/` is the broad command suite: Unix/Plan 9 shell and text tools, compilers/interpreters, document processing, image conversion, networking, and service daemons. Runtime resources are shipped beside binaries: fonts in `font/`, troff definitions in `troff/` and `postscript/`, plumbing rules in `plumb/`, namespace/network data in `ndb/`, and executable wrappers in `bin/`. Man pages in `man/` describe the installed interface; packaging/release assembly is under `dist/`.

Main entry points: [`Makefile`](https://github.com/9fans/plan9port/blob/master/Makefile) (Top-level build), [`src/lib9pclient/fs.c`](https://github.com/9fans/plan9port/blob/master/src/lib9pclient/fs.c) (9P client library), [`src/libdraw/drawclient.c`](https://github.com/9fans/plan9port/blob/master/src/libdraw/drawclient.c) (Draw stack), [`unix/make/Makefile.all`](https://github.com/9fans/plan9port/blob/master/unix/make/Makefile.all) (Unix build rules)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build &amp; Portability"]
  node_install["Installation<br/>entrypoint"]
  node_top_build["Top-level build<br/>build orchestration"]
  node_unix_build["Unix build rules<br/>OS build layer<br/>[Makefile.all]"]
  node_mk{{"mk<br/>Plan 9 build tool<br/>[main.c]"}}
  node_source_rules["Source build scripts<br/>mk rules"]
end

subgraph group_runtime["Compatibility Runtime"]
  node_headers["Plan 9 API headers<br/>API contracts<br/>[libc.h]"]
  node_lib9["lib9<br/>compatibility runtime"]
  node_support_libs["Support libraries<br/>reusable libraries"]
end

subgraph group_services["Protocol &amp; Services"]
  node_ninep_server["9P server library<br/>service primitives<br/>[srv.c]"]
  node_ninep_client["9P client library<br/>filesystem client<br/>[fs.c]"]
  node_ninep_tools{{"9P commands &amp; FUSE<br/>protocol bridge<br/>[main.c]"}}
  node_fossil[("Fossil<br/>9P archival filesystem<br/>[fossil.c]")]
  node_venti[("Venti<br/>content-addressed storage<br/>[venti.c]")]
  node_vac_backup["VAC &amp; backup<br/>snapshot tools<br/>[vac.c]"]
  node_network_services["Network services<br/>DNS, auth, mail<br/>[dnserver.c]"]
end

subgraph group_desktop["Desktop Stack"]
  node_draw["Draw stack<br/>graphics runtime<br/>[drawclient.c]"]
  node_devdraw{{"devdraw<br/>host display bridge<br/>[devdraw.c]"}}
  node_interactive_apps["Interactive applications<br/>Rio, Acme, Sam, 9term<br/>[main.c]"]
end

subgraph group_distribution["Distribution"]
  node_command_suite["Command suite"]
  node_launchers["Installed launchers<br/>user command wrappers"]
  node_runtime_assets["Runtime assets<br/>fonts, rules, data"]
  node_manpages["Manual interface<br/>documentation"]
  node_packages["Release assembly<br/>packaging"]
end

node_external_peers(("External peers<br/>network and host services"))

node_install -->|"starts"| node_top_build
node_top_build -->|"bootstraps"| node_mk
node_top_build -->|"uses"| node_unix_build
node_mk -->|"executes"| node_source_rules
node_source_rules -->|"builds"| node_command_suite
node_unix_build -->|"builds for host"| node_lib9
node_headers -->|"defines APIs"| node_lib9
node_lib9 -->|"underpins"| node_support_libs
node_support_libs -->|"supports"| node_ninep_server
node_support_libs -->|"supports"| node_ninep_client
node_ninep_client -->|"used by"| node_ninep_tools
node_ninep_server -->|"serves through"| node_fossil
node_ninep_client -->|"accesses"| node_fossil
node_vac_backup -->|"stores snapshots in"| node_venti
node_command_suite -->|"includes"| node_network_services
node_network_services -->|"connects to"| node_external_peers
node_draw -->|"renders through"| node_devdraw
node_devdraw -->|"uses display backend"| node_external_peers
node_draw -->|"renders"| node_interactive_apps
node_command_suite -->|"includes"| node_interactive_apps
node_command_suite -->|"installed via"| node_launchers
node_runtime_assets -->|"runtime resources"| node_command_suite
node_packages -->|"assembles"| node_launchers
node_manpages -.->|"documents"| node_launchers

click node_top_build "https://github.com/9fans/plan9port/blob/master/Makefile"
click node_unix_build "https://github.com/9fans/plan9port/blob/master/unix/make/Makefile.all"
click node_mk "https://github.com/9fans/plan9port/blob/master/src/cmd/mk/main.c"
click node_source_rules "https://github.com/9fans/plan9port/blob/master/src/mkfile"
click node_headers "https://github.com/9fans/plan9port/blob/master/include/libc.h"
click node_ninep_server "https://github.com/9fans/plan9port/blob/master/src/lib9p/srv.c"
click node_ninep_client "https://github.com/9fans/plan9port/blob/master/src/lib9pclient/fs.c"
click node_ninep_tools "https://github.com/9fans/plan9port/blob/master/src/cmd/9pfuse/main.c"
click node_fossil "https://github.com/9fans/plan9port/blob/master/src/cmd/fossil/fossil.c"
click node_venti "https://github.com/9fans/plan9port/blob/master/src/cmd/venti/srv/venti.c"
click node_vac_backup "https://github.com/9fans/plan9port/blob/master/src/cmd/vac/vac.c"
click node_network_services "https://github.com/9fans/plan9port/blob/master/src/cmd/ndb/dnserver.c"
click node_draw "https://github.com/9fans/plan9port/blob/master/src/libdraw/drawclient.c"
click node_devdraw "https://github.com/9fans/plan9port/blob/master/src/cmd/devdraw/devdraw.c"
click node_interactive_apps "https://github.com/9fans/plan9port/blob/master/src/cmd/rio/main.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_install,node_top_build,node_unix_build,node_mk,node_source_rules toneBlue
class node_headers,node_lib9,node_support_libs toneAmber
class node_ninep_server,node_ninep_client,node_ninep_tools,node_fossil,node_venti,node_vac_backup,node_network_services toneMint
class node_draw,node_devdraw,node_interactive_apps toneRose
class node_command_suite,node_launchers,node_runtime_assets,node_manpages,node_packages toneIndigo
class node_external_peers toneNeutral
```

## Components

### Build & Portability

- **Installation**: entrypoint · Bootstraps mk before building the distribution.
- [Top-level build](https://github.com/9fans/plan9port/blob/master/Makefile): build orchestration · `Makefile`
- [Unix build rules](https://github.com/9fans/plan9port/blob/master/unix/make/Makefile.all): OS build layer · Selects per-OS compilation and command build rules. · `unix/make/Makefile.all`
- [mk](https://github.com/9fans/plan9port/blob/master/src/cmd/mk/main.c): Plan 9 build tool · Bootstrapped build executor used for project sources. · `src/cmd/mk/main.c`
- [Source build scripts](https://github.com/9fans/plan9port/blob/master/src/mkfile): mk rules · `src/mkfile`

### Compatibility Runtime

- [Plan 9 API headers](https://github.com/9fans/plan9port/blob/master/include/libc.h): API contracts · `include/libc.h`
- **lib9**: compatibility runtime · Adapts Plan 9 process, filesystem, network, error, and UTF interfaces to Unix.
- **Support libraries**: reusable libraries · Buffered I/O, threads, regex, crypto, and IP utilities.

### Protocol & Services

- [9P server library](https://github.com/9fans/plan9port/blob/master/src/lib9p/srv.c): service primitives · `src/lib9p/srv.c`
- [9P client library](https://github.com/9fans/plan9port/blob/master/src/lib9pclient/fs.c): filesystem client · `src/lib9pclient/fs.c`
- [9P commands & FUSE](https://github.com/9fans/plan9port/blob/master/src/cmd/9pfuse/main.c): protocol bridge · Exposes, inspects, and mounts 9P services on Unix. · `src/cmd/9pfuse/main.c`
- [Fossil](https://github.com/9fans/plan9port/blob/master/src/cmd/fossil/fossil.c): 9P archival filesystem · Persistent filesystem with disk and cache management. · `src/cmd/fossil/fossil.c`
- [Venti](https://github.com/9fans/plan9port/blob/master/src/cmd/venti/srv/venti.c): content-addressed storage · Block storage server with arena and index management. · `src/cmd/venti/srv/venti.c`
- [VAC & backup](https://github.com/9fans/plan9port/blob/master/src/cmd/vac/vac.c): snapshot tools · `src/cmd/vac/vac.c`
- [Network services](https://github.com/9fans/plan9port/blob/master/src/cmd/ndb/dnserver.c): DNS, auth, mail · DNS/NDB, factotum authentication, and UPAS mail services. · `src/cmd/ndb/dnserver.c`

### Desktop Stack

- [Draw stack](https://github.com/9fans/plan9port/blob/master/src/libdraw/drawclient.c): graphics runtime · Client drawing APIs and in-memory rendering. · `src/libdraw/drawclient.c`
- [devdraw](https://github.com/9fans/plan9port/blob/master/src/cmd/devdraw/devdraw.c): host display bridge · Connects draw clients to macOS and X11 backends. · `src/cmd/devdraw/devdraw.c`
- [Interactive applications](https://github.com/9fans/plan9port/blob/master/src/cmd/rio/main.c): Rio, Acme, Sam, 9term · `src/cmd/rio/main.c`

### Distribution

- **Command suite**: Unix and Plan 9 commands · Broad collection of shell, text, compiler, document, image, network, and daemon tools.
- **Installed launchers**: user command wrappers
- **Runtime assets**: fonts, rules, data · Fonts, troff resources, plumbing rules, and namespace/network data.
- **Manual interface**: documentation
- **Release assembly**: packaging

### Other components

- **External peers**: network and host services · Unix display systems plus DNS, mail, authentication, and 9P endpoints.

## Connections

- Installation → Top-level build: starts
- Top-level build → mk: bootstraps
- Top-level build → Unix build rules: uses
- mk → Source build scripts: executes
- Source build scripts → Command suite: builds
- Unix build rules → lib9: builds for host
- Plan 9 API headers → lib9: defines APIs
- lib9 → Support libraries: underpins
- Support libraries → 9P server library: supports
- Support libraries → 9P client library: supports
- 9P client library → 9P commands & FUSE: used by
- 9P server library → Fossil: serves through
- 9P client library → Fossil: accesses
- VAC & backup → Venti: stores snapshots in
- Command suite → Network services: includes
- Network services → External peers: connects to
- Draw stack → devdraw: renders through
- devdraw → External peers: uses display backend
- Draw stack → Interactive applications: renders
- Command suite → Interactive applications: includes
- Command suite → Installed launchers: installed via
- Runtime assets → Command suite: runtime resources
- Release assembly → Installed launchers: assembles
- Manual interface → Installed launchers: documents
