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 23 and 21 are available. We'll choose version 23 in this guide, but version 21 will work equally well, as Firebase Emulators need at least version 11.
- Now, proceed to download OpenJDK, version 23.
- 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 13.12.0. - 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.
- Now open the
organized-app
(frontend) repo and install the dependencies using thenpm 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:
- Let’s move on to the Firebase environment variables. For FIREBASE_APP_NAME, use the project id assigned to your firebase project. You can get it from the URL (ie:
organized-app-47c7u
fromhttps://console.firebase.google.com/u/1/project/organized-app-47c7u/overview
). Alternatively, you can go to Settings, then General, and find theProject ID
. - 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.
- The three environment variables: MAIL_ADDRESS, MAIL_PASSWORD, and MAIL_SENDER_NAME. are not used during local development, so we can skip them for now.
- Additionally, create .firebaserc file with
cp .firebaserc.example .firebaserc
command and update the default field your-organized-project-id with your Firebase project ID.
- 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 (
organized-app
repo) in VS Code and open a new Terminal. - 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. You can do it starting from the example filecp .env.example .env
. - Write all the required variables. We need the VITE_FIREBASE_APIKEY, VITE_FIREBASE_AUTHDOMAIN, VITE_FIREBASE_PROJECTID, and VITE_FIREBASE_APPID. 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, and appId. 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.
- 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!