# builderbook
**Repository Path**: wiysy/builderbook
## Basic Information
- **Project Name**: builderbook
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2025-12-08
- **Last Updated**: 2025-12-08
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README

Support Ukraine: [link](https://bank.gov.ua/en/news/all/natsionalniy-bank-vidkriv-spetsrahunok-dlya-zboru-koshtiv-na-potrebi-armiyi)
## Builder Book
Open source web app to self-publish and sell books or other online content.
If you want to learn how to build this project from scratch, check out our book: https://builderbook.org.
The open source project is located in the `builderbook` folder. If you purchased our book, codebases for each of the book's chapters are located in the `book` folder.
We've used this `builderbook` project to build:
- [Builder Book](https://builderbook.org) - learn how to build full-stack web apps from scratch
- [SaaS Boilerplate](https://github.com/async-labs/saas) - open source web app to build your own SaaS product
- [Work in biotech](https://workinbiotech.com) - job board for biotech startup companies
- [AI-cruiter](https://workinbiotech.com/ai-cruiter) - browser extension is built for recruiters managing a high volume of job applicants. AI-cruiter uses LLMs - like ChatGPT and PaLM 2 - to generate succinct and relevant summaries of your job applicants' resumes
- [Async](https://async-await.com) - open source urgent vs non-urgent team communication tool for small teams
- [Async Labs](https://async-labs.com) - many custom dev projects
## Live app:
https://builderbook.org/books/builder-book/introduction
## Sponsors
[](https://aws.amazon.com/activate/)

[](https://1password.com/)
## Showcase
Check out projects built with the help of this open source app. Feel free to add your own project by creating a pull request.
- [Retaino](https://retaino.com) by [Earl Lee](https://github.com/earllee): Save, annotate, review, and share great web content. Receive smart email digests to retain key information.
- [michaelstromer.nyc](https://michaelstromer.nyc) by [Michael Stromer](https://github.com/Maelstroms38): Books and articles by Michael Stromer.
- [SaaS Boilerplate](https://github.com/async-labs/saas): Open source web app to build your own SaaS product.
- [Work in biotech](https://workinbiotech.com): Job board for small and young biotech companies
- [Async](https://async-await.com): Open source web app for team communication, separate urgent vs. non-urgent conversations.
- [Async Labs](https://async-labs.com): We build custom SaaS web applications.
## Contents
- [What can I learn from this project?](#what-can-i-learn-from-this-project)
- [Run locally](#run-locally)
- [Add a new book](#add-a-new-book)
- [Add your own styles](#add-your-own-styles)
- [Deploy to Heroku](#deploy-to-heroku)
- [Scaling](#scaling)
- [Docker](#docker)
- [Screenshots](#screenshots)
- [Built with](#built-with)
- [Core stack](#core-stack)
- [Third party APIs](#third-party-apis)
- [Contributing](#contributing)
- [Team](#team)
- [License](#license)
- [Project structure](#project-structure)
## What can I learn from this project?
You will learn how to structure your project and build many internal and external API infrastructures.
On the browser, the main technologies you will learn are: Next.js, React.js, Material-UI.
On the server, the main technologies you will learn are: Next.js, Node.js, Express.js, Mongoose.js, MongoDB database.
In addition to the above technologies, you can learn how to integrate your web application with the following external API services:
- [Google OAuth API](https://developers.google.com/identity/protocols/oauth2)
- [Github API](https://docs.github.com/en/rest/guides/basics-of-authentication)
- [Stripe API](https://stripe.com/docs/keys)
- [AWS SES API](https://docs.aws.amazon.com/STS/latest/APIReference/API_GetAccessKeyInfo.html)
- [Mailchimp API](https://mailchimp.com/developer/marketing/api/root/)
Plus, you can learn many concepts such as `session` and `cookie`, headers, HTTP request-response, Express middleware, `Promise`, `async/await`, and more. You have to know these concepts to be a confident web developer, no matter what language you use.
The main use cases for this project, besides learning, are:
- To write and host free documentation with Github being a source of truth for content.
- To sell online content, such as books.
- To extend it (see our second book, SaaS Boilerplate Book) to start software business.
## Creating a Google OAuth Client
This guide will walk you through the steps to create a Google OAuth client for your application.
#### Prerequisites
Before you begin, make sure you have the following:
- A Google account
- Access to the [Google Cloud Console](https://console.cloud.google.com/)
1. **Sign in to Google Cloud Console:**
- Go to the [Google Cloud Console](https://console.cloud.google.com/).
- Sign in with your Google account or create one if you don't have it.
2. **Create a New Project:**
- Click on the project dropdown in the top navigation bar.
- Click on "New Project."
- Give your project a name and click "Create."
3. **Enable the Google+ API (if required):**
- If you plan to use Google+ Sign-In for authentication, enable the "Google+ API" for your project.
- In the Cloud Console, go to the API & Services > Library.
- Search for "Google+ API" and enable it.
4. **Create OAuth Client ID:**
- In the Cloud Console, navigate to the API & Services > Credentials page.
- Click on "Create Credentials" and then select "OAuth client ID."
- Select the application type, typically "Web application" for a website or web application.
- Fill out the necessary information, such as the name of the OAuth client and authorized redirect URIs (where Google should redirect the user after authentication). You can use `http://localhost` as a redirect URI for development.
- Click "Create" to generate your OAuth client credentials. It will provide you with a client ID and client secret.
## Creating a GitHub Client ID and Client Secret
To create a GitHub Client ID and Client Secret, follow these steps:
1. **Sign in to your GitHub Account:**
If you don't have a GitHub account, [create one](https://github.com/join).
2. **Go to Developer Settings:**
Click on your profile picture in the top right corner of GitHub and select "Settings." In the left sidebar, under "Developer settings," click on "OAuth Apps."
3. **Create a New OAuth App:**
Click on the "Register a new application" button.
4. **Fill in the Application Details:**
You'll be prompted to fill in details about your application:
- **Application Name:** The name of your application.
- **Homepage URL:** The URL to your application's website.
- **Application Description:** A brief description of your application.
- **Authorization callback URL:** This is the URL to which GitHub will redirect users after they authorize your application. For testing purposes, you can use `http://localhost` if you're developing locally.
5. **Generate Your Client ID and Client Secret:**
After you've filled in the details, click the "Register application" button. GitHub will generate a Client ID and Client Secret for your application.
## Run locally
- Clone the project and run `yarn` to add packages.
- Before you start the app, create a `.env` file at the app's root. This file must have values for some env variables specified below.
- To get `MONGO_URL_TEST`, we recommend a [free MongoDB at MongoDB Atlas](https://docs.mongodb.com/manual/tutorial/atlas-free-tier-setup/) (to be updated soon with MongoDB Atlas, see [issue](https://github.com/async-labs/builderbook/issues/138)).
- Get `GOOGLE_CLIENTID` and `GOOGLE_CLIENTSECRET` by following [official OAuth tutorial](https://developers.google.com/identity/sign-in/web/sign-in#before_you_begin).
Important: For Google OAuth app, callback URL is: http://localhost:8000/oauth2callback
Important: You have to enable Google+ API in your Google Cloud Platform account.
- Specify your own secret key for Express session `SESSION_SECRET`: https://github.com/expressjs/session#secret
- To use all features and third-party integrations (such as Stripe, Google OAuth, Mailchimp), create a `.env` file and add values for all variables as shown below. These variables are also listed in [`.env.example`](https://github.com/async-labs/builderbook/blob/master/builderbook/.env.example), which you can use as a template to create your own `.env` file.
`.env` :
```
# Used in server/server.js
MONGO_URL=
MONGO_URL_TEST=
SESSION_SECRET=
# Used in lib/getRootUrl.js
NEXT_PUBLIC_URL_APP=
NEXT_PUBLIC_PRODUCTION_URL_APP="https://heroku.builderbook.org"
# Used in server/google.js
GOOGLE_CLIENTID=
GOOGLE_CLIENTSECRET=
# Used in server/aws.js
AWS_ACCESSKEYID=
AWS_SECRETACCESSKEY=
AWS_REGION=
# Used in server/models/User.js
EMAIL_ADDRESS_FROM=
----------
# All environmental variables above this line are required for successful sign up
# Used in server/github.js
GITHUB_TEST_CLIENTID=
GITHUB_LIVE_CLIENTID=
GITHUB_TEST_SECRETKEY=
GITHUB_LIVE_SECRETKEY=
# Used in server/stripe.js
NEXT_PUBLIC_STRIPE_TEST_PUBLISHABLEKEY=
NEXT_PUBLIC_STRIPE_LIVE_PUBLISHABLEKEY=
STRIPE_TEST_SECRETKEY=
STRIPE_LIVE_SECRETKEY=
STRIPE_TEST_DEMO_BOOK_PRICE_ID=
STRIPE_LIVE_DEMO_BOOK_PRICE_ID=
STRIPE_TEST_SECOND_BOOK_PRICE_ID=
STRIPE_LIVE_SECOND_BOOK_PRICE_ID=
# Used in server/mailchimp.js
MAILCHIMP_API_KEY=
MAILCHIMP_REGION=
MAILCHIMP_PURCHASED_LIST_ID=
MAILCHIMP_SIGNEDUP_LIST_ID=
# Used in pages/_document.js and pages/_app.js
NEXT_PUBLIC_GA_MEASUREMENT_ID=
COOKIE_DOMAIN=".builderbook.org"
```
- IMPORTANT: do not publish your actual values for environmentable variables in `.env.example`; this file is public and only meant to show you how your `.env` file should look.
- Add your value (domain that you own) for `COOKIE_DOMAIN` and `NEXT_PUBLIC_PRODUCTION_URL_APP`.
- Start the app with `yarn dev`.
- To get `NEXT_PUBLIC_GA_MEASUREMENT_ID`, set up Google Analytics and follow [these instructions](https://support.google.com/analytics/answer/1008080?hl=en) to find your tracking ID.
- To get Stripe-related API keys, set up or log into your Stripe account and find your key [here](https://dashboard.stripe.com/account/apikeys).
- Env keys `NEXT_PUBLIC_GA_MEASUREMENT_ID` and `NEXT_PUBLIC_STRIPE_TEST_PUBLISHABLEKEY`/`NEXT_PUBLIC_STRIPE_LIVE_PUBLISHABLEKEY` are universally available (client and server). Env keys inside `.env` file are used in server code only unless they have `NEXT_PUBLIC_` prepended to their name. In that case, they are universally available.
- To make user a book's owner, set `"isAdmin": true` on corresponding MongoDB document in your database (default value is `false` for any new user).
**Important: if you don't add values for environmental variables to `.env` file, corresponding functionality will not work. For example, login with Google account, purchasing book, getting repo information via GitHub API and other third-party API infrastructures.**
## Add a new book
- Create a new Github repo (public or private).
- In that repo, create an `introduction.md` file and write some content.
- At the top of your `introduction.md` file, add metadata in the format shown below. See [this file](https://github.com/builderbook/demo-book/blob/master/introduction.md) as an example.
```
---
title: Introduction
seoTitle: title for search engines
seoDescription: description for search engines
isFree: true
---
```
- Go to the app, click "Connect Github".
- Click "Add Book". Enter details and select the Github repo you created.
- Click "Save".
When you add new `.md` files or update content, go to the `BookDetail` page of your app and click `Sync with Github`.
Important: All `.md` files in your Github repo _must_ have metadata in the format shown above.
Important: All `.md` files in your Github repo _must_ have name `introduction.md` or `chapter-N.md`.
To make the content of a `.md` file _private_ (meaning a person must purchase the content to see it), remove `isFree:true` and add `excerpt:""`. Add some excerpt content - this content is public and serves as a free preview.
## Add your own styles
To change the color scheme of this app, modify the `primary` and `secondary` theme colors inside `lib/context.js`. Select any colors from Material UI's official [color palette](https://material-ui-next.com/style/color/#color).
Recommended ways to add your own styles to this app:
1. [Inline style for a single element](#inline-style-for-a-single-element)
2. [Reusable style for multiple elements within single page or component](#reusable-style-for-multiple-elements-within-single-page-or-component)
3. [Reusable/importable style for multiple pages or components](#reusableimportable-style-for-multiple-pages-or-components)
4. [Global style for all pages in application](#global-style-for-all-pages-in-application)
### Inline style for a single element
USE CASE: apply a style to _one element_ on a single page/component
For example, in our `book` page, we wrote this single inline style:
```
...
``` [See usage](https://github.com/async-labs/builderbook/blob/49116676e0894fcf00c33d208a284359b30f12bb/pages/book.js#L48) ### Reusable style for multiple elements within single page or component USE CASE: apply the same style to _multiple elements_ on a single page/component.` element within the page: ``` const styleExcerpt = { margin: '0px 20px', opacity: '0.75', fontSize: '13px', };
...
``` [See usage](https://github.com/async-labs/builderbook/blob/49116676e0894fcf00c33d208a284359b30f12bb/pages/tutorials.js#L14) ### Reusable/importable style for multiple pages or components USE CASE: apply the same style to elements on _multiple pages/components_.sudo snap install --classic herokuTo confirm a successful installation, run:
heroku --versionAs example, my output that confirms successful installation, looks like:
heroku/7.22.7 linux-x64 node-v11.10.12. [Sign up](https://signup.heroku.com/) for Heroku, go to your Heroku dashboard and click purple New button on the right:
heroku loginFollow instructions to log in to Heroku CLI. After successful login, terminal will print:
Logged in as email@domain.comWhere `email@domain.com` is an email address that you used to create your Heroku account. To see logs, in your terminal run:
heroku logs --app builderbook-8-end --tailIn your terminal, you will see your most recent logs and be able to see a real-time logs. You can output certain number of lines (N) for retrieved logs by adding `--num N` to the `heroku logs` command. You can print only app's logs by adding `--source app` or system's logs by adding `--source heroku`. 7. Time to add a custom domain. The Heroku app that we created is deployed on `free dyno`. Free dyno plan does not let you to add a custom domain to your app. To add custom domain, go to `Resources` tab and click purple Change Dyno Type button: