We also have a video version of this guide. It's easy to follow and relatively short.
Hello everyone! Thank you so much for your support in developing the Organized application. In this guide, we will guide you through the steps to set up the local environment to run the application locally. This video covers many steps, but by following along, you'll successfully set up everything and will be ready to start coding.
Let's start by looking at what you need to set up the environment. We'll begin completely from scratch to make it easy to understand how to install all the necessary dependencies.
The first dependency is Git, our version control system. You can download it from git-scm.com.
- Visit the Git website and select the version suitable for your operating system. For this guide, we'll demonstrate on Windows, but you can adapt the instructions for your OS.
- Now, download Git. Once the download is finished, we’re ready to install it.
Now, let’s proceed with the installation of Git.
- Navigate to the folder location and begin the installation process.
- Please wait while the installation completes.
- Excellent, Git is now installed.
There are two valid options for installing Node.js on your system. You can either use an application called Node Version Manager for Windows (NVM), or directly download Node.js, especially if you’re using Linux or macOS. Both methods are acceptable, so you can choose the one that suits you best.
- Download the NVM
- Install it using all the default options for the installation.
- Before installing, let’s check the current Long Term Support (LTS), version of Node.js on the official Node.js website. As of now, the LTS version is
20.11.0
. - Back in the Command Prompt, type
nvm install 20.11.0
(or the latest version avaible at the time you are reading this) to start downloading that version of Node.js from the official website. We will also install npm, the package manager for Node.js. - After installation, open Command Prompt and type
nvm use 20.11.0
to use the installed version. Make sure you have admin privileges for setup.
And that’s it! Node.js is now installed on our computer.
Next, we’ll move on to our code editor. We use Visual Studio Code, or VS Code, as Integrated Development Environment (IDE), but feel free to use any IDE you’re comfortable with.
- To download VS Code, visit the official VS Code website and select the installer that suits your needs.
- For this guide, we’ll be downloading the System Installer.
- Let’s install it. Please make sure to check the following "Open with Code" Additional Tasks to make it easier to open folders in the VS Code. But even without doing so, you will be able to open the folders directly from VS Code.
- Open the VS Code.
When you open VS Code for the first time, you'll be asked to personalize its appearance. The IDE will also offer helpful coding tips and suggestions. Feel free to check out these options and click "Mark as done" when you're done.
Finally, our last dependency for this initial setup is Java. We specifically need the OpenJDK version, as it’s required by the Firebase Emulators.
- Go to the OpenJDK download page and select the version you prefer. As of now, versions 21 and 17 are available. We'll choose version 21 in this guide, but version 17 will work equally well, as Firebase Emulators need at least version 11.
- Now, proceed to download OpenJDK, version 21.
- Let's go ahead with the installation using the default options.
Now, let’s do a quick check to confirm that everything has been installed correctly.
- Open a Command Prompt and type
java --version
. You should see the version you’ve just installed. If you see any errors, try reinstalling it by repeating the previous step once again. - We can perform similar checks for Node.js and npm. Type
node -v
to check the Node.js version, andnpm -v
to check the npm version. If everything is correct, you should see the exact versions you’ve installed.
With that, all our major dependencies are now installed.
Next, let's proceed to run the local backend API server. This server handles login, Firebase sync, end-to-end encryption, and some other essential features.
- First thing first, let’s create a new folder in your file system to store both the backend and frontend projects.
- Once you’ve created the folder, right-click within it and select ‘Open Git Bash’. You can also use Terminal or Command Prompt if you prefer.
- The next step is to clone each of these projects using the
git clone
command. Using the direct GitHub repository URL from the sws2apps organization, or you can also clone from your own fork if you already have one. - Let’s start by cloning the API project. This should be a quick process as the sws2apps-api repository is relatively small.
- With the API project cloned, let’s move on to the frontend project, the Organized app itself. Please note that this repository is quite large so the cloning process may take more time.
- Great! Both repositories have been successfully cloned.
- Next, open the sws2apps-API folder, right-click within it, and select Open with Code. This is a VS Code shortcut that we enabled during the VS Code installation.
When you open it for the first time, you'll need to trust yourself as the author of the files in this folder. There might be a prompt to install a Dev Containers extension, but it's not necessary for local development, so feel free to ignore it.
Some extensions can make development easier. Let's install them!
- The first extension is Prettier, a useful format that supports JavaScript, HTML, and TypeScript files. Wait for the installation to complete.
- The second extension we need is ESLint, a tool from Microsoft that helps us write error-free code. Prettier and ESLint work together to help us write better code for our applications.
Before booting up the API server, let’s prepare our environment.
- In VS Code, open a new Terminal by navigating to View and selecting Terminal. Wait for the Terminal window to load completely.
- With the terminal ready, let’s install the Firebase CLI using the command
npm i -g firebase-tools
. This command installs the Firebase CLI globally. - Once installed, you might receive a notice from npm about a new minor version being available. If so, let’s install that quickly.
- To check if the Firebase CLI was installed correctly, use the command
firebase --version
. It should display the version of Firebase you just installed. For now, it’s 14.2.1. - Next, let’s authenticate our Firebase Account with the CLI. Type
firebase login
, and you’ll be prompted to complete the authentication in your browser. Ensure that you’re logged into your Google Account and that you have an account on the Firebase Console website. - Once you’ve completed the authentication, the Firebase CLI will be connected to your account.
- In VS Code, switch to the
main-e2e
branch for the new Organized app using thegit checkout main-e2e
command.
Keep in mind that during the development of the next Organized app release, we still have the current Congregation Program for Everyone app with the
main
branch. After the Organized app release, we'll close the “Congregation Program for Everyone” version, resulting in only one main app and one main branch.
- After checking out the correct branch, install the dependencies using the
npm i
command. This will start the installation of all the project’s dependencies.
You need to create your own Firebase project on their website. This project will be needed during development.
- We don’t need Analytics for this project, but enabling it won’t cause any issues.
- Fill out all the necessary information to create the project and continue.
Once you have created the Firebase project, go to the Console. You should see your project in the list. If it’s not there, refresh the page. Once you see it, open it.
Now, take some more steps to prepare this project for use by the backend project:
- First, navigate to Project Settings and select Service Accounts. From here, we’ll generate a key that will allow our API to access this project.
- Click Generate new private key, which will export and download a new JSON file to your computer. We will need this file later, but for now, we can leave it as is.
- Next, navigate to Build and select Authentication, then click Get Started to enable Authentication for the project.
- Enable the Email/Password sign-in provider, which includes Passwordless sign-in. This sign-in method is necessary for our local environment.
- You can also enable the Google sign-in provider if you wish to use a Google Account during development. Feel free to choose the providers that best suit your development needs.
- Once you’ve made your selections, click Save.
Now, we have two providers ready for Authentication in the Firebase console. Remember, this is the only one Firebase Product that we’ll be using from the Firebase Console during development.
Now the installations of these dependencies are completed.
Firebase Emulators require a storage rule file to set up Firebase Storage locally.
- To get this file, use the command
cp storage.rules.example storage.rules
. That’s done! Now we have our own storage rules for Firebase. - Let’s also make a copy of the environment file example, using the command
cp .env.example .env
.
Now, let’s assign values to these variables:
- Starting with the USER_PARSER_API_KEY, go to userparser.com. This API helps us better authorize users by collecting the user agent data of their devices. Log in to your account if you already have one, or create a new one if you don’t. It’s completely free.
- After completing the authentication, navigate to Dashboard, where you should see the API key at the top of the page. Copy that API key to the USER_PARSER_API_KEY variable.
- Next, we have three environment variables: GMAIL_ADDRESS, GMAIL_APP_PASSWORD, and GMAIL_SENDER_NAME. We won’t use these during local development, so we can skip them for now.
- Let’s move on to the Firebase environment variables. For FIREBASE_APP_NAME, use organized-api, which is the name we created in the Firebase Console.
- We’ll come back to the value of GOOGLE_CONFIG_BASE64 later.
- But first, let’s get our Crowdin environment variables, as these are also required for the API to work. Go to crowdin.com, log in to your account if you already have one, or create a new free account.
- After completing the authentication, under your user profile icon, navigate to Settings. Open API, and click New token.
- We only need the Project permission, as well as the Source files and strings, and Translations. Give a name for that token and click Create.
- Copy the access token that was generated to the CROWDIN_API_KEY environment variable.
- Now we need to create a Crowdin project. Click Create a new project from the sidebar on the left navigation menu.
- Give a name for the project. Let’s make it public, and choose one target language. Then click Save.
- To get the project name, you can get it from the URL. It should be the same as the one that you just wrote when creating the project. Alternatively, you can go to Settings, then General, and find the Project name.
- That’s our Crowdin project name, let’s paste it to the CROWDIN_PROJECT_NAME variable.
- And now for the GOOGLE_CONFIG_BASE64, there are many approaches to get this base64 string of the private key. We’re just showing one way of getting it.
- In this example, we’ll use Node directly in the Terminal window by typing
node
. - Let’s create a variable to store our private key JSON contents. Open the JSON file we downloaded earlier and copy its contents. Then, type
const firebaseConfig =
and right after this paste all the JSON content into the Terminal. Press Enter. Remember, it’s just the JSON data saved in this newly defined variable. - To convert it to a base64 string, we use the command
Buffer.from(JSON.stringify(firebaseConfig)).toString('base64')
. Please, note that we recommend using the local converting command rather than online base64 converter tools, because of security reasons. Then, press Enter. - You should now have the base64 encoded string of your Firebase private key. Copy that text to the GOOGLE_CONFIG_BASE64 variable.
- Additionally, you have to go to the firebase rc file and update the Firebase project name from the default dev-sws2apps one to ‘organized-api’ or the name of your Firebase project.
- Type
npm run setup:emulators
. This is the command we use to set up the emulators. Let’s wait for this to start. It may take a few seconds, especially the first time you install all these dependencies. - The CLI will ask if we’re ready to proceed with initializing the emulators. Type
Y
to proceed with the setup to initialize the emulators. - When you’re asked “Which Firebase emulators do you want to set up”, just hit Enter, because all the emulators that we need are already defined.
- Then we are asked if we want to download the emulators. Enter
Y
to agree and proceed.
Once the download is complete, and the initialization is also complete, we can finally proceed to the next step – starting emulators.
- To do this, type
npm run start:emulators
, and wait for it to start. - Awesome, the Firebase Emulators are now running perfectly.
- Next, open a new Terminal in the same VS Code project. On this new Terminal, we’ll start the API project itself. Remember, the first Terminal still has the Firebase Emulators running. These both terminals should be running simultaneously.
- Start the dev server by typing
npm run dev
.
Great, the dev server is now running without errors, indicating it has successfully connected to the Firebase Emulators.
That completes the setup of the backend project for the local environment. The API is now ready to be used.
- Open the frontend project folder in VS Code and open a new Terminal.
- Switch to the
main-next
branch using thegit checkout main-next
command. This branch contains the new Organized application. - After checking out the correct branch, install the dependencies by typing
npm i
. - After a while, installation is complete.
Now, let’s add the required environment variables for the frontend application.
- Create an
.env
file for this frontend project. - Write all the required variables. We need the VITE_FIREBASE_APIKEY, VITE_FIREBASE_AUTHDOMAIN, VITE_FIREBASE_PROJECTID, VITE_FIREBASE_APPID, and VITE_FIREBASE_MEASUREMENTID.
- To get these values, go back to the Firebase Console and open your project.
- Navigate to Project Settings. Find “Your apps” or “Add an app” area and hit the “Web” button. Then create and register a new Web App.
- Give a nickname for the web app. For example, ‘Organized web app’.
- We don’t need to set up Firebase Hosting for this app, so continue.
- In this section, we get all the required values for our environment variables like apiKey, authDomain, projectId, appId, and measurementId. Copy these values from the Firebase console to our
.env
file.
All the dependencies were installed, and the environment variables are all ready. We can now start the frontend application.
- Type
npm run dev
to start the frontend application. - Well done! The dev server for the frontend application is now ready. Let’s open it in the browser.
Good. The frontend app is working. Let’s test a few functions to ensure that the frontend can communicate properly with the backend API. We’ll see if it can connect to the local backend API that we set up earlier.
Let’s proceed on this journey as if we were a new user:
- On this page, we’ll select the option for ‘Baptized brother’ and accept the agreements.
- Next, we’ll continue with our authentication. Enter any email (there’s no verification if the email is real or not). Choose your preferred method, then click ‘Send link’. Please note that the email won’t be sent to a real email address. Instead, simply click a link displayed on the page, simulating the process of clicking a link from an email to complete your authentication. Now, let’s click ‘Log in’.
- Great, the authentication for your account is now complete.
- Now, let’s create a congregation. Enter a fictitious first and last name.
- Let’s select a country for our testing. Then, find a congregation using a congregation name or number and click ‘Create congregation’.
- Now, you’ll be prompted to create an encryption code. Remember, in this new version, the encryption code is required after creating your congregation account. This feature doesn’t exist in the older ‘Congregation Program for Everyone’ version, but in ‘Organized’, it’s an important step to start using the app.
- Once this is set, you’ll be directed to the Dashboard page of the Organized app.
This is the ‘Organized’ Dashboard page. From this page, you can access various features of the app as they are developed by our team.
If you have more questions or face any problems not covered in this guide, head to our GitHub repository Discussions to ask! Your contributions and support for the Organized app are highly appreciated!