mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-01 23:06:52 +01:00
Page:
src backend contributors coding_style
Pages
AI
Home
README
api README
api concepts share_link
api drivers
api group
api notifications
api share
api type_tagged
api types app_share
api types file_share
backend Kernel
backend README
backend contributors boot_sequence
backend contributors modules
backend contributors structure
backend features protected_apps
backend features service_scripts
backend howto_make_driver
backend lists_of_things list_of_permissions
backend lists_of_things list_of_tto_types
backend modules puterai requests
backend modules test_drivers requests
backend notes 2024_10_03_email_in_use_checks
contributors comment_prefixes
contributors email_testing
contributors extensions README
contributors extensions definitions
contributors extensions events
contributors extensions
contributors structure
contributors vscode
devmeta track_comments
docmeta
gui webpack_attempts
phoenix missing_posix
phoenix parser
planning alternatives_to_$
planning micro_modules
prod
scratch
self_hosters config
self_hosters config_values
self_hosters credit_context
self_hosters domains
self_hosters first_run_issues
self_hosters instructions
self_hosters support
src backend A&A auth
src backend A&A permission
src backend A_and_A auth
src backend A_and_A permission
src backend Kernel
src backend README
src backend contributors boot_sequence
src backend contributors coding_style
src backend contributors modules
src backend contributors structure
src backend features batch_and_symlinks
src backend features metered_services
src backend features protected_apps
src backend features service_scripts
src backend howto_make_driver
src backend lists_of_things list_of_permissions
src backend lists_of_things list_of_tto_types
src backend modules puterai README
src backend notes 2024_10_03_email_in_use_checks
src backend services config
src backend services log
src backend src modules puterai README
src backend src modules puterai ai_services_config
src backend src modules puterai api_examples
src backend src modules puterai config
src backend src modules puterai contributors ai_usage_testing
src backend src modules puterai requests
src backend src modules test_drivers requests
src gui el()
src gui webpack_attempts
src phoenix missing_posix
src phoenix parser
testing_with_email
tools api_tester cartesian
uncategorized README
uncategorized es6_note
uncategorized puter_mods
No results
1
src backend contributors coding_style
KernelDeimos edited this page 2025-05-14 16:42:09 -04:00
Backend Style
File Structure
Copyright Notice
All files should begin with the standard copyright notice:
/*
* Copyright (C) 2025-present Puter Technologies Inc.
*
* This file is part of Puter.
*
* Puter is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Imports
const express = require('express');
const passport = require('passport');
const { get_user } = require("../../helpers");
const BaseService = require("../../services/BaseService");
const config = require("../../config");
const path = require('path');
const fs = require('fs');
Import order is generally:
- Third party dependencies. Having these occur first makes it easy to quickly determine what this source file is likely to be responsible for.
- Files within the module.
- Standard library, "builtins"
Code Formatting
Indentation and Spacing
const fn = async () => {
const a = 5; // Spaces between operators
// Note: "=" in for loop initializer does not require space around
// Note: operators in condition part have space around
for ( let i=0; i < 10; i++ ) {
console.log('hello');
}
// Control structures have space inside parenthesis
for ( const thing of stuff ) {
// NOOP
}
// Function calls do not have space inside parenthesis
await something(1, 2);
}
- Use 4 spaces for indentation.
- Use spaces around operators (
=,+, etc.); not required in for loop initializer. - Use a space after keywords like
if,for,while, etc.return [1,2,3]; // Sure return[1,2,4]; // Definitely not - Use spaces between parenthesis in control structures unless
parenthesis are empty.
if ( a === b ) { return null; } - No trailing whitespace at the end of lines
- Use a space after commas in arrays and objects
- Empty blocks should have the comment
// NOOPwithin braces
Line Length
- Try to keep lines under 100 characters for better readability
- Try to keep them under 80, but this is not always practical
- For long function calls or objects, break them into multiple lines
Trailing Commas
// This is great
{
"apple",
"banana",
"cactus", // <-- Good!
}
// This is also fine
[
1, 2, 3,
4, 5, 6,
7, 8, 9,
]
[
something(),
another_thing(),
the_last_thing() // <-- Nope, please add trailing comma!
]
We use trailing commas where applicable because it's easier to re-order lines, especially when using vim motions.
Braces and Blocks
- Single statement blocks must either be on the same line as
the corresponding control structure, or surrounding by braces:
if ( a === b ) return null; // Sure if ( a === b ) return null; // Please no 🤮 if ( a === b ) { return null; // Nice } - Opening braces go on the same line as the statement
- Put a space before the opening brace
Naming Conventions
Variables
- Variables are generally in camelCase
- Variables might have a prefix_beforeThem
const svc_systemData = this.services.get('system-data');
const svc_su = this.services.get('su');
effective_policy = await svc_su.sudo(async () => {
return await svc_systemData.interpret(effective_policy.data);
});
In the example above we see the svc_ prefix is used to indicate a
reference to a backend service. The name of the service is system-data
which is not a valid identifier, so we use svc_systemData for our
variable name.
Classes
- Use PascalCase for class names
- Use snake_case for class methods
- Instance variables are often
snake_casebecause it's easier to read.camelCaseis acceptable too. - Instance variables only used internally should have a
trailing_underscore_even if incamelCase_. We avoid using#privatePropertiesbecause it unnecessarily inhibits debugging and patching.
File Names
- Use PascalCase for class files (e.g.,
UserService.js) - Use kebab-case for non-class files (e.g.,
auth-helper.js)
Documentation
JSDoc Comments
- Backend services (classes extending
BaseService) should have JSDoc comments - Public methods of backend services should have JSDoc comments
- Include parameter descriptions, return values, and examples where appropriate
/**
* @class UserService
* @description Service for managing user operations
*/
/**
* Get a user by their ID
* @param {string} id - The user ID
* @returns {Promise<Object>} The user object
* @throws {Error} If user not found
*/
async function getUserById(id) {
// ...
}
Inline Comments
- Use inline comments to explain complex logic
- Prefix comments with tags like
track:to indicate specific purposes
// track: slice a prefix
const uid = uid_part.slice('uid#'.length);
General
API
- Index (README.md)
- api drivers
- Group Endpoints
- Notification Endpoints
- Share Endpoints
- Type-Tagged Objects
Concepts
Types
For Contributors
- Comment Prefixes
- contributors vscode
- Local Email Testing
- Puter Extensions
- Repository Structure and Tooling
Extensions
Devmeta
Planning
- Micro Modules
- [planning alternatives_to_
](planning-alternatives_to_)
Self_hosters
- Configuring Domains for Self-Hosted Puter
- Configuring Puter
- First Run Issues
- self_hosters config_values
- self_hosters support
- Self-Hosting Puter
Src
Backend
A_and_A
For Contributors
- Backend Style
- Puter Backend - Directory Structure
- Puter Backend Boot Sequence
- Puter Kernel Moduels and Services
Features
- Batch and Symlinks
- Metered Services and Cost Management
- Protected Apps and Subdomains
- Service Scripts
Lists_of_things
Modules
Puterai
Notes
Services
Src
Modules
Puterai
- Index (README.md)
- Configuring AI Services
- PuterAI API Request Examples
- src backend src modules puterai config
####### For Contributors
Test_drivers
Gui
Phoenix
Tools
Api_tester
Uncategorized
This wiki is generated from the repository. Do not edit files the wiki.
You are reading documentation for Puter, an open-source high-level operating system.
Getting started with Puter on localhost is as simple as:
git clone https://github.com/HeyPuter/puter.git
npm install
npm run start