|
| 1 | +# System Architecture |
| 2 | + |
| 3 | +## General |
| 4 | + |
| 5 | +Puter's system goals is to provide an internet operating system, providing (as brief): |
| 6 | + |
| 7 | +1. **User management:** (User) Account and session CrUD, Permissions... |
| 8 | +2. **Desktop environment use:** (User) Use apps in interactive mode through GUIs, CrUD symbolic links and icons... |
| 9 | +3. **System deployment:** (Developers) build a web app, or web service, on puter. |
| 10 | + |
| 11 | +and ensuring: |
| 12 | + |
| 13 | + 1. **Extensibility:** you should be able to create your own Kernel Modules, user-oriented applications, and so. |
| 14 | + 2. **Debuggability:** given this is opensource-driven, you'll find loggers and monitoring tools aiming to make development easier. |
| 15 | + 3. **Deployability:** you, and other users, should be able to deploy this system at least both self host and public hosting. |
| 16 | + 4. **Securability:** you, and other users, should be able to trust on puter as a personal cloud, a remote desktop for servers and workstations, and as a software development platform. |
| 17 | + |
| 18 | +In order to achieve those requirements, Puter is following (tl;dr): |
| 19 | + |
| 20 | +1. **A client-server style Architecture:** Allow user to interact with system GUI through a Web Browser (as an external system). |
| 21 | +2. **Micro-kernel pattern:** Allow backend (in which heavy processing occurs) to extend system's functionality, keeping the core of the system and the other additions decoupled each other. |
| 22 | + |
| 23 | +In in a nutshell: |
| 24 | +``` |
| 25 | + Puter is Puter, whatever you think it might be useful for |
| 26 | + you can use it for. You can think of it as a high-level |
| 27 | + operating system where the "hardware" is external services or |
| 28 | + resources provided by the host OS; if you develop apps on |
| 29 | + this platform you have higher-level primitives, like how |
| 30 | + using AI services is considered a "driver", or how Puter's |
| 31 | + filesystem can use a database to store the directory tree and |
| 32 | + file metadata. |
| 33 | +``` |
| 34 | + |
| 35 | +## Deployment |
| 36 | + |
| 37 | +### Local dev |
| 38 | + |
| 39 | +Get the [monorepo](https://github.com/HeyPuter/puter/), and then run `install` and `start` [npm scripts](https://github.com/HeyPuter/puter/blob/main/package.json) |
| 40 | + |
| 41 | +``` |
| 42 | +git clone https://github.com/HeyPuter/puter |
| 43 | +cd puter |
| 44 | +npm install |
| 45 | +npm start |
| 46 | +``` |
| 47 | + |
| 48 | +You get in error? then you can [check our first run issues checklist.](./deployment/first-run-issues.md) |
| 49 | + |
| 50 | +Also, if you get "Cannot write to path" error, it usually happens when /var/puter isn\'t chown\'d to the right UID. You can check the [issue number 645.](https://github.com/HeyPuter/puter/issues/645) |
| 51 | +### Docker |
| 52 | + |
| 53 | +On linux/macOS run: |
| 54 | + |
| 55 | +``` |
| 56 | +mkdir puter && cd puter && mkdir -p puter/config puter/data && sudo chown -R 1000:1000 puter && docker run --rm -p 4100:4100 -v `pwd`/puter/config:/etc/puter -v `pwd`/puter/data:/var/puter ghcr.io/heyputer/puter |
| 57 | +``` |
| 58 | + |
| 59 | +On Windows run: |
| 60 | + |
| 61 | +``` |
| 62 | +mkdir -p puter |
| 63 | +cd puter |
| 64 | +New-Item -Path "puter\config" -ItemType Directory -Force |
| 65 | +New-Item -Path "puter\data" -ItemType Directory -Force |
| 66 | +Invoke-WebRequest -Uri "https://raw.githubusercontent.com/HeyPuter/puter/main/docker-compose.yml" -OutFile "docker-compose.yml" |
| 67 | +docker compose up |
| 68 | +``` |
| 69 | + |
| 70 | +## Main modules traits |
| 71 | + |
| 72 | +### service |
| 73 | + |
| 74 | +- **Concern:** to extend core functionality. |
| 75 | +- **Class:** BaseService (extends concepts.Service) |
| 76 | +- **Public interface:** |
| 77 | + |
| 78 | +``` |
| 79 | +/** |
| 80 | +* Creates the service's data structures and initial values. |
| 81 | +* This method sets up logging and error handling, and calls a custom `_construct` method if defined. |
| 82 | +* |
| 83 | +* @returns {Promise<void>} A promise that resolves when construction is complete. |
| 84 | +*/ |
| 85 | +async construct () => void |
| 86 | +``` |
| 87 | + |
| 88 | +``` |
| 89 | +/** |
| 90 | +* Constructs service class using Service Resources list |
| 91 | +* Service Resources properties: services, config, my_config, name, args, context. |
| 92 | +*/ |
| 93 | +constructor (service_resources, ...a) |
| 94 | +``` |
| 95 | + |
| 96 | + |
| 97 | +``` |
| 98 | +/** |
| 99 | +* Performs service lifecycle's initialization phase |
| 100 | +*/ |
| 101 | +async init () => void |
| 102 | +``` |
| 103 | + |
| 104 | +### Kernel |
| 105 | + |
| 106 | + |
| 107 | +- **Concern:** To orchestrate core modules for system to load up, following [**Backend Boot Sequence**.](./deployment/backend_boot_sequence.md) |
| 108 | +- **Class:** Kernel (extends AdvancedBase) |
| 109 | +- **Public interface:** |
| 110 | + |
| 111 | +``` |
| 112 | +/** |
| 113 | +* Construct kernel module configuring its useapi and entry path |
| 114 | +*/ |
| 115 | +constructor (entry_path) => |
| 116 | +``` |
| 117 | + |
| 118 | + |
| 119 | +``` |
| 120 | +/** |
| 121 | +* Adds a module into kernel's modules list |
| 122 | +*/ |
| 123 | +add_module (module) => void |
| 124 | +``` |
| 125 | + |
| 126 | +``` |
| 127 | +/** |
| 128 | +* Boots backend |
| 129 | +*/ |
| 130 | +boot () => void |
| 131 | +``` |
| 132 | + |
| 133 | +## System entry points |
| 134 | + |
| 135 | +### Testing |
| 136 | +Mocha is being used for this. |
| 137 | +There are 2 main **test directories:** |
| 138 | +1. src/phoenix/test -> testing phoenix emulator. |
| 139 | +2. src/backend/tools/test -> a set of tools for backend testing. [Read more about backend tools.](./testing/backend_tools.md) |
| 140 | + |
| 141 | +### Use cases |
| 142 | +For **self hosting** deployment, there is a _tool_ called "run-selfhosted.js" which you can run with ```npm run start``` command. That tool is going to: |
| 143 | + |
| 144 | +1. Get all required _kernel modules_ from the **@heyputer/backend npm package** |
| 145 | +2. Configure kernel's entry path as the directory path of the current file (so, the run-selfhosted tool's directory). |
| 146 | +3. Add all required _kernel modules_ to kernel's modules list. |
| 147 | +4. Start kernel by its ```boots()``` public method. |
| 148 | + |
| 149 | +**Monitoring:** The ```SelfHostedModule``` is responsible for load 3 project's module watching tools (for GUI, TERMINAL, EMULATOR, GIT, PHOENIX, and PUTER-JS) |
| 150 | + |
| 151 | +--- |
| 152 | + |
| 153 | +If you find any bug or error in this documentation, do not hesitate to send your complaint to **[email protected]**, or **colaborate ** with the documentation yourself. |
0 commit comments