# hfiref0x/lightftp architecture

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

- Interactive diagram: https://gitdiagram.com/hfiref0x/lightftp
- Repository: https://github.com/hfiref0x/lightftp

## Overview

LightFTP is a small FTP server. Its main workflow is startup and configuration, client command handling and authentication, then directory and file operations over FTP data connections. The server source is organized here by its documented runtime responsibilities; shared helpers and configuration parsing form the internal layer. The excerpts do not expose every command handler, so some documented capabilities are represented within the server component rather than as independently verified call paths.

Main entry points: [`src/ftpserv.c`](https://github.com/hfiref0x/lightftp/blob/master/src/ftpserv.c) (Control Sessions and Dispatch), [`src/main.c`](https://github.com/hfiref0x/lightftp/blob/master/src/main.c) (Startup and TLS Setup), [`src/cfgparse.c`](https://github.com/hfiref0x/lightftp/blob/master/src/cfgparse.c) (Configuration Parser), [`src/fspathtools.c`](https://github.com/hfiref0x/lightftp/blob/master/src/fspathtools.c) (Path and Symlink Safety)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Startup and Configuration"]
  node_config["Server Configuration<br/>[fftp.conf]"]
  node_entry["Startup and TLS Setup<br/>[main.c]"]
  node_config_parser["Configuration Parser<br/>[cfgparse.c]"]
end

subgraph group_protocol["FTP Protocol"]
  node_server_loop["Control Sessions and Dispatch<br/>[ftpserv.c]"]
  node_authentication["User Authentication<br/>[ftpserv.c]"]
  node_data_connections["FTP Data Connections<br/>[ftpserv.c]"]
  node_tls["TLS Support<br/>[main.c]"]
  node_logging["Server Logging<br/>[ftpserv.c]"]
end

subgraph group_files["File Operations"]
  node_directory_commands["Directory Commands<br/>[ftpserv.c]"]
  node_file_transfers["File Transfers<br/>[ftpserv.c]"]
end

subgraph group_internals["Internal Support"]
  node_password_hashing["Password Hashing<br/>[fcrypt.c]"]
  node_filesystem_paths["Path and Symlink Safety<br/>[fspathtools.c]"]
  node_ftp_constants["FTP Replies and Features<br/>[ftpconst.c]"]
  node_memory_helpers["Memory Allocation Helper<br/>[x_malloc.h]"]
end

node_operator(("Server Operator"))
node_ftp_client(("FTP Client"))
node_filesystem["Server Filesystem"]

node_operator -->|"starts server"| node_entry
node_operator -->|"configures"| node_config
node_entry -->|"parses settings"| node_config_parser
node_entry -->|"starts thread"| node_server_loop
node_ftp_client -->|"sends commands"| node_server_loop
node_server_loop -->|"dispatches commands"| node_authentication
node_authentication -->|"checks passwords"| node_password_hashing
node_server_loop -->|"manages transfers"| node_data_connections
node_server_loop -->|"dispatches commands"| node_directory_commands
node_server_loop -->|"dispatches commands"| node_file_transfers
node_directory_commands -->|"resolves paths"| node_filesystem_paths
node_file_transfers -->|"resolves paths"| node_filesystem_paths
node_directory_commands -->|"accesses directories"| node_filesystem
node_file_transfers -->|"reads and writes"| node_filesystem
node_entry -->|"initializes TLS"| node_tls
node_server_loop -->|"writes session logs"| node_logging
node_server_loop -->|"uses replies"| node_ftp_constants
node_entry -->|"allocates buffers"| node_memory_helpers
node_config_parser -->|"allocates config"| node_memory_helpers

click node_config "https://github.com/hfiref0x/lightftp/blob/master/data/fftp.conf"
click node_entry "https://github.com/hfiref0x/lightftp/blob/master/src/main.c"
click node_config_parser "https://github.com/hfiref0x/lightftp/blob/master/src/cfgparse.c"
click node_server_loop "https://github.com/hfiref0x/lightftp/blob/master/src/ftpserv.c"
click node_authentication "https://github.com/hfiref0x/lightftp/blob/master/src/ftpserv.c"
click node_password_hashing "https://github.com/hfiref0x/lightftp/blob/master/src/fcrypt.c"
click node_data_connections "https://github.com/hfiref0x/lightftp/blob/master/src/ftpserv.c"
click node_tls "https://github.com/hfiref0x/lightftp/blob/master/src/main.c"
click node_directory_commands "https://github.com/hfiref0x/lightftp/blob/master/src/ftpserv.c"
click node_file_transfers "https://github.com/hfiref0x/lightftp/blob/master/src/ftpserv.c"
click node_filesystem_paths "https://github.com/hfiref0x/lightftp/blob/master/src/fspathtools.c"
click node_logging "https://github.com/hfiref0x/lightftp/blob/master/src/ftpserv.c"
click node_ftp_constants "https://github.com/hfiref0x/lightftp/blob/master/src/ftpconst.c"
click node_memory_helpers "https://github.com/hfiref0x/lightftp/blob/master/src/inc/x_malloc.h"

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_config,node_entry,node_config_parser,node_ftp_client toneBlue
class node_server_loop,node_authentication,node_data_connections,node_tls,node_logging toneAmber
class node_directory_commands,node_file_transfers,node_operator,node_filesystem toneMint
class node_password_hashing,node_filesystem_paths,node_ftp_constants,node_memory_helpers toneRose
```

## Components

### Startup and Configuration

- [Server Configuration](https://github.com/hfiref0x/lightftp/blob/master/data/fftp.conf): `data/fftp.conf`
- [Startup and TLS Setup](https://github.com/hfiref0x/lightftp/blob/master/src/main.c): `src/main.c`
- [Configuration Parser](https://github.com/hfiref0x/lightftp/blob/master/src/cfgparse.c): `src/cfgparse.c`

### FTP Protocol

- [Control Sessions and Dispatch](https://github.com/hfiref0x/lightftp/blob/master/src/ftpserv.c): `src/ftpserv.c`
- [User Authentication](https://github.com/hfiref0x/lightftp/blob/master/src/ftpserv.c): `src/ftpserv.c`
- [FTP Data Connections](https://github.com/hfiref0x/lightftp/blob/master/src/ftpserv.c): `src/ftpserv.c`
- [TLS Support](https://github.com/hfiref0x/lightftp/blob/master/src/main.c): `src/main.c`
- [Server Logging](https://github.com/hfiref0x/lightftp/blob/master/src/ftpserv.c): `src/ftpserv.c`

### File Operations

- [Directory Commands](https://github.com/hfiref0x/lightftp/blob/master/src/ftpserv.c): `src/ftpserv.c`
- [File Transfers](https://github.com/hfiref0x/lightftp/blob/master/src/ftpserv.c): `src/ftpserv.c`

### Internal Support

- [Password Hashing](https://github.com/hfiref0x/lightftp/blob/master/src/fcrypt.c): `src/fcrypt.c`
- [Path and Symlink Safety](https://github.com/hfiref0x/lightftp/blob/master/src/fspathtools.c): `src/fspathtools.c`
- [FTP Replies and Features](https://github.com/hfiref0x/lightftp/blob/master/src/ftpconst.c): `src/ftpconst.c`
- [Memory Allocation Helper](https://github.com/hfiref0x/lightftp/blob/master/src/inc/x_malloc.h): `src/inc/x_malloc.h`

### Other components

- **Server Operator**
- **FTP Client**
- **Server Filesystem**

## Connections

- Server Operator → Startup and TLS Setup: starts server (evidence: `README.md`)
- Server Operator → Server Configuration: configures (evidence: `README.md`)
- Startup and TLS Setup → Configuration Parser: parses settings (evidence: `src/main.c`)
- Startup and TLS Setup → Control Sessions and Dispatch: starts thread (evidence: `src/main.c`)
- FTP Client → Control Sessions and Dispatch: sends commands (evidence: `README.md`)
- Control Sessions and Dispatch → User Authentication: dispatches commands (evidence: `src/ftpserv.c`)
- User Authentication → Password Hashing: checks passwords (evidence: `src/ftpserv.c`)
- Control Sessions and Dispatch → FTP Data Connections: manages transfers (evidence: `src/ftpserv.c`)
- Control Sessions and Dispatch → Directory Commands: dispatches commands (evidence: `src/ftpserv.c`)
- Control Sessions and Dispatch → File Transfers: dispatches commands (evidence: `src/ftpserv.c`)
- Directory Commands → Path and Symlink Safety: resolves paths (evidence: `src/ftpserv.c`)
- File Transfers → Path and Symlink Safety: resolves paths (evidence: `src/ftpserv.c`)
- Directory Commands → Server Filesystem: accesses directories (evidence: `README.md`)
- File Transfers → Server Filesystem: reads and writes (evidence: `README.md`)
- Startup and TLS Setup → TLS Support: initializes TLS (evidence: `src/main.c`)
- Control Sessions and Dispatch → Server Logging: writes session logs (evidence: `src/ftpserv.c`)
- Control Sessions and Dispatch → FTP Replies and Features: uses replies (evidence: `src/ftpserv.c`)
- Startup and TLS Setup → Memory Allocation Helper: allocates buffers (evidence: `src/main.c`)
- Configuration Parser → Memory Allocation Helper: allocates config (evidence: `src/cfgparse.c`)
