]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - support/doc/development/server/code.md
Bumped to version v1.3.0-rc.1
[github/Chocobozzz/PeerTube.git] / support / doc / development / server / code.md
1 # Server code documentation
2
3 The server is a web server developed with [TypeScript](https://www.typescriptlang.org/)/[Express](http://expressjs.com).
4
5
6 ## Technologies
7
8 * [TypeScript](https://www.typescriptlang.org/) -> Language
9 * [PostgreSQL](https://www.postgresql.org/) -> Database
10 * [Redis](https://redis.io/) -> Job queue/cache
11 * [Express](http://expressjs.com) -> Web server framework
12 * [Sequelize](http://docs.sequelizejs.com/en/v3/) -> SQL ORM
13 * [WebTorrent](https://webtorrent.io/) -> BitTorrent tracker and torrent creation
14 * [Mocha](https://mochajs.org/) -> Test framework
15
16
17 ## Files
18
19 The server main file is [server.ts](/server.ts).
20 The server modules description are in the [package.json](/package.json) at the project root.
21 All other server files are in the [server](/server) directory:
22
23 server.ts -> app initialization, main routes configuration (static routes...)
24 config -> server YAML configurations (for tests, production...)
25 scripts -> Scripts files for npm run
26 server
27 |__ controllers -> API routes/controllers files
28 |__ helpers -> functions used by different part of the project (logger, utils...)
29 |__ initializers -> functions used at the server startup (installer, database, constants...)
30 |__ lib -> library function (WebTorrent, OAuth2, ActivityPub...)
31 |__ middlewares -> middlewares for controllers (requests validators, requests pagination...)
32 |__ models -> Sequelize models for each SQL tables (videos, users, accounts...)
33 |__ tests -> API tests and real world simulations (to test the decentralized feature...)
34
35
36 ## Conventions
37
38 Uses [JavaScript Standard Style](http://standardjs.com/).
39
40 ## Architecture
41
42 The server is composed by:
43
44 * a REST API (relying on the Express framework) documented on http://docs.joinpeertube.org/api.html
45 * a WebTorrent Tracker (slightly custom version of [webtorrent/bittorrent-tracker](https://github.com/webtorrent/bittorrent-tracker#server))
46
47 A video is seeded by the server with the [WebSeed](http://www.bittorrent.org/beps/bep_0019.html) protocol (HTTP).
48
49 ![Architecture scheme](/support/doc/development/server/upload-video.png)
50
51 When a user uploads a video, the REST API creates the torrent file and then adds it to its database.
52
53 If a user wants to watch the video, the tracker will indicate all other users that are watching the video + the HTTP url for the WebSeed.
54
55 ## Newcomers
56
57 The server entrypoint is [server.ts](/server.ts). Looking at this file is a good start.
58 Then you can try to understand the [controllers](/server/controllers): they are the entrypoints of each API request.