unoffical wafrn mirror
wafrn.net
atproto
social-network
activitypub
1# Developing wafrn
2
3## Project Structure
4
5Wafrn is split between an [Angular](https://angular.dev) frontend and a [NodeJS](https://nodejs.org/en) backend.
6
7```text
8packages/
9├── frontend/
10│ ├── routes/
11│ ├── util/
12│ ├── README.md
13│ └── ...
14└── backend/
15 ├── src/
16 │ ├── app/
17 │ ├── assets/
18 │ └── ...
19 ├── README.md
20 └── ...
21```
22
23(Tree made with [tree.nathanfriend.io](https://tree.nathanfriend.io/))
24
25## Contributing
26
27If you would like to help develop the Frontend or Backend, read the README.md of the respective package.
28
29- [Frontend - README.md](../packages/frontend/README.md)
30- [Backend - README.md](../packages/backend/README.md)
31
32## Local setup pointing to the production frontend
33
34If you want to do development on the frontend and what you do does not require doing something like posting a lot or spaming an external account, you can simply:
35
361. Clone the repo
372. Install node 24 or use the provided Nix shell script
383. Run `npm install` at the root of the project
394. Run `npm run frontend:develop:prod`
40
41If you want to point to a different backend or see additional information on the nix shells script, see the Frontend README file.
42
43## Local setup with a local dummy instance
44
45If you want to develop Wafrn frontend but require to do more "noisy" stuff, you can point it at a working instance. See [Frontend - README.md](../packages/frontend/README.md) for more details
46
47If you want to setup both the backend and frontend locally there are a couple of helper scripts that can help you set up a local environment:
48
491. Run `./install/env_local_setup.sh`. This will setup the backend and frontend environment files to point to each other locally.
50
512. Run `docker compose up`. This will start up the required services: PostgreSQL, Redis and Caddy
52
53> **Note:** If you're not a fan of docker, or you already have these services running, you can also install PostgreSQL, Redis and Caddy manually.
54
55> **Note:** If you are running Caddy manually, or you are not using Docker Desktop but a more native docker installation, you will need to edit `packages/frontend/Caddyfile` and replace `host.docker.internal` with `localhost` for it to work properly.
56
573. Set up the the backend:
58
59```sh
60cd packages/backend
61npm i
62npm run db:migrate
63```
64
654. Set up the frontend:
66
67```sh
68cd packages/frontend
69npm i
70npm run prebuild
71npm exec -- ng build --configuration=devlocal
72```
73
745. Start backend & frontend
75
76```sh
77cd packages/backend
78NODE_TLS_REJECT_UNAUTHORIZED=0 npm start
79```
80
81```sh
82cd packages/frontend
83npm run prebuild
84npm exec -- ng serve --host 0.0.0.0 --configuration=devlocal
85```
86
876. If all is well go to `https://localhost` to see your app
88
89The default username/password for local installation is: `admin@example.com` / `Password1!`
90
91> **Note:** You can run `caddy trust` to install Caddy's root certificates, to the system store. This will remove the security warnings from your browser. You can also do `caddy untrust` once you're finished with the development.
92
93> **Warning:** Due to how the Fediverse and Bluesky operates not all features will be accessible when developing the backend locally. You might [want to host your own Wafrn instance](./deployment.md) as a staging server if you wish to develop features that require proper access to the Fediverse and/or Bluesky
94
95## Fullstack development with debugger
96
97Ok so you definetively need to do some backend stuff! As long as you do not need to do fedi stuff and bluesky stuff, it's easy!
98
991. Clone the repo
1002. Install docker and node 24
1013. Do this command on the root of the project `npm install`
1024. Copy the docker compose for local development `cp docker-compose.localBackendDebuggerDev.yml docker-compose.yml`
1035. Copy the development environment file for backend `cp packages/backend/environment.dev.ts packages/backend/environment.ts`
1046. Start the services required for wafrn to work: redis, postgres, and a db admin tool on https://localhost:8080 (type postgres, user and pass: root, db: wafrn) `docker compose up -d`
1057. Check that you can connect to the database in your browser in https://localhost:8080 . If you have problem here, contact the dev team
1068. Edit the environment file. Replace adminEmail and adminUser with your desired email, user and password. Use this file as a template, check for the EDIT HERE comments:
107
108```import { Environment } from './interfaces/environment.js'
109
110export const baseEnvironment: Environment = {
111 prod: false,
112 // this makes the logs really heavy, but might be useful for queries
113 logSQLQueries: true,
114 workers: {
115 // if you set this to true, workers will start in the main thread. no need for starting the utils/workers.ts in other tmux tab
116 mainThread: true,
117 low: 5,
118 medium: 10,
119 high: 100
120 },
121 // this was a dev thing. leave to true unless you are doing stuff in local or your media url is yourinstance/uploads (not recomended)
122 removeFolderNameFromFileUploads: true,
123 // we use now postgresql.
124 databaseConnectionString: 'postgresql://root:root@localhost:5432/wafrn',
125 // PROD
126 // databaseConnectionString: 'postgresql://wafrn:Skied-Obscurity6-Tightwad@localhost:1111/wafrn',
127
128 listenIp: '0.0.0.0',
129 port: 3002,
130 // In the case of you wantint to put fedi petitions in another thread, use a different port here. You will have to update your apache config
131 fediPort: 3002,
132 // If you want to run the cache routes in another port, same thing!
133 cachePort: 3002,
134 saltRounds: 14,
135 // for jwt secret you should use something like https://www.grc.com/passwords.htm please this is SUPER DUPER SECRET.
136 jwtSecret: Buffer.from('secret', 'base64'),
137 // https://app.wafrn.net
138 // EDIT HERE if you are gona do fedi stuff like ssh -R 192.168.100.100:3002:localhost:3002 192.168.100.100
139 frontendUrl: 'https://instance3.dev.wafrn.net',
140 // app.wafrn.net
141 // EDIT HERE (optional)
142 instanceUrl: 'instance3.dev.wafrn.net',
143 // https://media.wafrn.net
144 mediaUrl: 'https://local.dev.wafrn.net/api/uploads',
145 // You should run also this project github.com/gabboman/fediversemediacacher. In my case, https://cache.wafrn.net/?media= The cache is there because at some point in the past I configured it to precache images. No need for it to be honest
146 externalCacheurl: 'https://local.dev.wafrn.net/api/cache?media=',
147 // If main cache fails due to IP limits you can install additional proxies, and use them here. The cache will try these as well before failing.
148 // You can deploy https://github.com/sztupy/did-decoder-lambda this project to Netlify or Vercel as a backup for example
149 externalCacheBackups: [],
150 // after the first run, create the admin user. and a deleted user. You will have to edit the user url in db so it starts with an @
151 adminUser: 'admin',
152 // admin email wich you will recive things like "someone registred and you need to review this"
153 // EDIT HERE
154 adminEmail: 'YOUREMAILGOESHERE',
155 adminPassword: 'ADMINPASSWORD',
156 // after creating the deleted_user we advice to also set the user to BANNED
157 deletedUser: '@DELETEDUSER',
158 // in MB. Please make sure you have the same in the frontend
159 uploadLimit: 250,
160 // 20 is a good number. With the new query we could investigate a higher number but no need to do it
161 postsPerPage: 20,
162 // trace is extreme logging. debug is ok for now
163 logLevel: 'debug',
164 // There is a script that loads the file from this url and blocks the servers
165 blocklistUrl: '',
166 // In some cases we serve the frontend with the backend with a small preprocessing. We need the location of the frontend
167 // EDIT HERE: put a location with a build of the frontend. or an index file. you may need this
168 frontedLocation: '/Users/gabriel/workspace/wafrn/packages/frontend/dist/wafrn/browser',
169 // oh yes, you need TWO redis connections, one for queues other for cache
170 bullmqConnection: {
171 host: 'localhost',
172 port: 6379,
173 db: 0
174 },
175 // second database used for cache
176 redisioConnection: {
177 host: 'localhost',
178 port: 6379,
179 db: 1
180 },
181 // this will create a backendlog.log file on the folder superior to this one.
182 pinoTransportOptions: {
183 targets: [
184 {
185 target: 'pino/file',
186 level: 'trace',
187 options: {
188 destination: 1
189 }
190 }
191 ]
192 },
193 // you can try with gmail but we actually use sendinblue for this. bear in mind that this might require some fiddling in your gmail account too
194 // you might need to enable https://myaccount.google.com/lesssecureapps
195 // https://miracleio.me/snippets/use-gmail-with-nodemailer/
196 emailConfig: {
197 host: 'mail.wafrn.net',
198 port: 587,
199 auth: {
200 user: 'info@wafrn.net',
201 pass: 'didYouThoughtIwouldLeaveThisOneHere?',
202 from: 'info@wafrn.net'
203 }
204 },
205 // you dont have an smtp server and you want to do a single user instance? set this to true!
206 disableRequireSendEmail: true,
207 // if someone is trying to scrap your place you can send a funny message in some petitions (attacks to the frontend)
208 blockedIps: [] as string[],
209 // do you want to manually review registrations or have them open? We advice to leave this one to true
210 reviewRegistrations: true,
211 // if the blocklist youre using turns out to be biased you can tell the script that loads the block host to do not block these hosts
212 ignoreBlockHosts: [] as string[],
213 // default SEO data that will be used when trying to load server data
214 defaultSEOData: {
215 title: 'localhost',
216 description: 'localhost, a wafrn instance',
217 img: 'https://localhost/assets/logo.png'
218 },
219 // EDIT HERE if you have a PDS that you want to connect
220 enableBsky: false,
221 bskyPds: 'at.app.wafrn.net',
222 bskyPdsJwtSecret: 'SECRET1',
223 bskyPdsAdminPassword: 'SECRET2',
224 // to generate these keys use the following command: `npx web-push generate-vapid-keys`.
225 webpushPrivateKey: 'CDUUngHrbAUOBg_1-jXZJFj3IOGMTAbR5zhJupKzMOE', // dont worry these ones are local
226 webpushPublicKey: 'BIWrO9knKAnPj2TFfU7pIxo0QkO_b2-PZCqYwAPArJdHTQ3Xsvf-E_WXaKGFB531fBOxCE92SZ6R_vHTVM1yTNw',
227 // this is a email that will be sent to the distribution services in the users devices in case the owner of the distribution service wants to contact the server that is sending the notifications
228 webpushEmail: 'mailto:info@wafrn.net',
229 frontendEnvironment: {
230 logo: '/assets/logo.png',
231 frontUrl: 'http://localhost:4200',
232 baseUrl: 'http://localhost:4200/api',
233 baseMediaUrl: '/api/uploads',
234 externalCacheurl: '/api/cache?media=',
235 shortenPosts: 3,
236 disablePWA: false,
237 maintenance: false
238 }
239}
240```
241
2429. Do this command to initialize the database `cd packages/backend && npm run db:migrate`
24310. On the root directory, do this command to start the backend server: `npm run backend:develop`
24411. Do this command to start the frontend `npm run frontend:develop:prod`
24512. Enjoy!
246
247### Fullstack development with fedi and bluesky access and debugger access
248
249This part of the guide needs to be written properly, BUTT, the QUICK AND DIRTY explanation for this is:
250
251Execute the steps of "Fullstack development with debugger"
252
253You will require a VPS with caddy and a bluesky PDS and a domain
254
255Update the config on environment.ts:
256You will need to update: frontendUrl, instanceUrl, mediaUrl, externalCacheurl, email things too probably (optional), and if you want buesky too: enableBsky, bskyPds, bskyPdsJwtSecret, bskyPdsAdminPassword
257
258Once you do that and have stuff runing, to listen to the bluesky pds you will also need to start the atproto listener
259
260`npm run backend:atproto`
261
262Regarding fedi, you will need to create a reverse proxy with the url of the instance pointing to your machine. What I do is that i use the vps as a jump like this:
263
264`ssh -R 3002:localhost:3002 USER@YOURVPS`
265
266This will "mirror" your port 3002 to the internal port 3002 of your vps. You can reverse proxy that one.