litebb/README.md

1# liteBB 2 3liteBB is a very tiny BBS/forum written in Node.js. 4 5It's goals are 6 7- To have **No frontend JavaScript**. Everything is server-side rendered. 8- To be small and fast. 9- To have a code-base that can be easily understood by newcomers to the 10 language. 11- To be easy to deploy. ie. less or no moving parts. 12 13**Note:** The choice of sequelize is that, if you, the user 14decide, you want a bigger database powering your community 15discussions, you can change it just like that, in the config. 16SQLite was chosen because its fits my 17needs perfectly. 18 19P.S the name `liteBB` comes from SQ`Lite` and oh! there's a live instance running 20on https://litebb.aktsbot.in/ 21 22## Installation 23 24``` 25$ git clone --depth=1 https://github.com/aktsbot/litebb litebb 26$ cd litebb 27$ npm i 28$ mkdir dbs 29$ NODE_ENV=production ./node_modules/.bin/sequelize db:migrate 30$ cp example.env .env 31$ # change the values in .env 32$ npm start 33``` 34 35## The idea and the first run 36 37### The idea / walkthrough 38 39- The forum has boards. 40- Boards have posts. 41- Posts have replies. 42- Every user has a unique `username`. 43- Only `admin` users can create Boards. 44- `regular` users can create posts and replies. 45- `admin`s have access to the Settings page. 46- From the settings page, one can control the world. 47 48### The first run 49 50- In the `.env` file, if there is a `FIRST_RUN=1` entry, 51 then users created while the app is running are `admin`s. 52- So ideally when you set the forum up, have `FIRST_RUN=1` in 53 the `.env` file. Then create your admin user. 54- Stop the server. Comment out `FIRST_RUN=1` or remove it and then 55 restart the server. 56- I understand, this isn't ideal, but the software will be improved on. 57 58## Hacking 59 600. SQLite is the star here. So have the `sqlite3` binary installed on our 61 machine. For a GUI tool, there's [sqlitebrowser](https://sqlitebrowser.org/). 62 If you're using the `sqlite3` binary, having the following in 63 `$HOME/.sqliterc` helps. 64 65 ``` 66 .header on 67 .mode column 68 ``` 69 701. We'll need node.js installed on our machine. This is a node 71 project after all. Also it helps, to install some tools like the 72 `sequelize` cli globally. 73 74 ``` 75 export NPM_PACKAGES=$HOME/.npm 76 export NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH" 77 export PATH=$NPM_PACKAGES/bin:$HOME/bin:$PATH 78 ``` 79 80 I don't like to `sudo npm i -g package`. With the above 3 lines in our `$HOME/.profile`, we could do the same without sudo. `$ npx sequelize` works too, but hey! 81 822. We make use of the `sequelize` cli, if one does not like installing packages 83 globally, just add an alias to our `$HOME/.bashrc`. This is what I have 84 85 ``` 86 alias sequelize="node_modules/.bin/sequelize" 87 ``` 88 893. To start the app in debug mode 90 91 ``` 92 $ DEBUG=litebb:* npm start 93 ``` 94 954. Sequelize cheatsheet, shamelessly ripped off from their [README](https://github.com/sequelize/cli#usage) 96 ``` 97 Commands: 98 sequelize db:migrate Run pending migrations 99 sequelize db:migrate:schema:timestamps:add Update migration table to have timestamps 100 sequelize db:migrate:status List the status of all migrations 101 sequelize db:migrate:undo Reverts a migration 102 sequelize db:migrate:undo:all Revert all migrations ran 103 sequelize db:seed Run specified seeder 104 sequelize db:seed:undo Deletes data from the database 105 sequelize db:seed:all Run every seeder 106 sequelize db:seed:undo:all Deletes data from the database 107 sequelize db:create Create database specified by configuration 108 sequelize db:drop Drop database specified by configuration 109 sequelize init Initializes project 110 sequelize init:config Initializes configuration 111 sequelize init:migrations Initializes migrations 112 sequelize init:models Initializes models 113 sequelize init:seeders Initializes seeders 114 sequelize migration:generate Generates a new migration file [aliases: migration:create] 115 sequelize model:generate Generates a model and its migration [aliases: model:create] 116 sequelize seed:generate Generates a new seed file [aliases: seed:create] 117 ``` 1185. The app and session databases will be generated in `./dbs`. 119 120## Models/Schema 121 122``` 123Boards 124------ 125id 126name 127description 128slug 129createdAt 130updatedAt 131 132 133Posts 134----- 135id 136name 137content 138renderedContent 139slug 140boardId 141createdByUser 142createdAt 143updatedAt 144 145 146Replies 147------- 148id 149postId 150content 151createdByUser 152createdAt 153updatedAt 154 155 156Users 157----- 158id 159username 160email 161passwordHash 162role 163resetPasswordToken 164createdAt 165updatedAt 166``` 167 168## Thanks 169 170- This software was influenced by writings of [Nikita Prokopov](https://tonsky.me/blog/disenchantment/) and [Matt Reyer](https://javascript.works-hub.com/learn/a-javascript-free-frontend-61275). Thank you both for the teachings. 171- The styling of the forum is borrowed from [Slimvoice](https://slimvoice.co/), with accents from [ubuntu](https://design.ubuntu.com/brand/colour-palette/). Without them, liteBB wouldn't exist. 172- This project was generated with the wonderful [express-generator](https://expressjs.com/en/starter/generator.html) cli. 173- The amazing wesbos for his [Learn-Node](https://github.com/wesbos/Learn-Node) repo. 174- https://handyman.dulare.com/session-management-in-express/ 175- https://github.com/sequelize/express-example 176- https://www.npmjs.com/package/connect-session-sequelize