Skip to content

Commit

Permalink
Merge pull request #29 from radicalxdev/modify/emulator-setup
Browse files Browse the repository at this point in the history
Modify/emulator setup
  • Loading branch information
yunusj authored May 20, 2024
2 parents ef5513f + 2e91e82 commit 5f9fe91
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 39 deletions.
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,31 @@ To set up the project, follow these steps:
2. Create your firebase project on google firebase console
3. Create a firestore database instance
4. Get firebase config from firebase project settings in firebase console and save it to .env (create in root of this project, see sample.env for refrence)
5. Generate a new private key from the projects settings and save that to the .env file as well
6. Install Firebase CLI by running following in terminal: `npm install dev`
7. Login to firebase CLI by running following command: `firebase login`.
5. Install Firebase CLI by running the following in terminal: `npm install -g firebase-tools`
6. Login to firebase CLI by running the following command: `firebase login`.

### Backend
1. Navigate to back-end project directory: `cd functions`
2. Install dependencies: `npm install`
3. Run for local testing: `firebase serve --only functions`

### Frontend
1. Navigate to back-end project directory: `cd frontend`
1. Navigate to front-end project directory: `cd frontend`
2. Install dependencies: `npm install`
3. Run for local testing: `npm run dev`

### Local Emulator (Optional)
#### Setup
1. Start emulator `firebase emulators:start`
2. Run database seed `node functions/local_db_seed.js`
1. Open the terminal and to start the emulators, run the following command: `npm run emulators`
2. Open another terminal simultaneously and start the frontend project, run the following command: `npm run frontend:dev`

## Cloud Deployment
1. Clone the repository: `git clone https://github.com/radicalxdev/kai-platform`
2. Navigate to back-end project directory: `cd functions`
3. Install Frontend dependencies: `npm install`
4. Navigate to functions directory: `cd .. && cd frontend`
3. Install dependencies: `npm install`
4. Navigate to front-end directory: `cd ../frontend`
5. Install dependencies: `npm install`
5. Build frontend: `npm run build && npm run export`
7. Deploy: `firebase deploy` (this will deploy frontend and backend, if you only want to deploy frontend use firebase deploy --only hosting)
8. Run: `node functions/cloud_db_seed.js`
5. Navigate to the root directory and run deploy: `cd .. && npm run deploy`

## Contributing

Expand Down
32 changes: 32 additions & 0 deletions code-of-conduct.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Code of Conduct
We are committed to fostering a welcoming and inclusive environment for all contributors.

Our Pledge
We as contributors pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, level of experience, nationality, personal appearance, race, and religion.

Our Standards
Examples of behavior that contributes to creating a positive environment include:

Using welcoming and inclusive language
Being respectful of differing viewpoints and experiences
Gracefully accepting constructive criticism
Focusing on what is best for the community
Showing empathy towards other contributors
Examples of unacceptable behavior by participants include:

The use of sexual language or imagery
Personal attacks
Trolling or insulting/derogatory comments
Public or private harassment
Publishing someone's private information, such as a physical or electronic address, without explicit permission
Other conduct which could reasonably be considered inappropriate in a professional setting
Enforcement Responsibilities
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project maintainers at rex@radicalx.co. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project maintainers are obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

Attribution
This Code of Conduct is adapted from the Contributor Covenant, version 2.1, available at https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.

Contact info
If you have any further questions regarding this Code of Conduct, please contact us at rex@radicalx.co.
49 changes: 49 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Contribution Guidelines

Welcome to our repository! If you're looking to contribute, you're in the right place. This document provides a comprehensive guide on how to contribute to our project, including explanations of key concepts like Pull Requests (PRs) and code reviews, as well as a step-by-step process for making contributions.

## Understanding Pull Requests and Code Reviews

### What is a Pull Request (PR)?

A Pull Request is a method used in version control systems to introduce changes to the repository. After you make changes in a branch of your fork, you can issue a PR. This is essentially a request to the repository maintainers to pull your changes into the official project. PRs are a pivotal component of collaborative development, allowing for discussion and review of code before it integrates into the main codebase.

### What is a Code Review?

A code review is a part of the PR process where other contributors and maintainers review your code. This practice ensures quality and consistency in the codebase and is a perfect opportunity to get feedback on your coding decisions. Code reviews help catch bugs, ensure best practices, and maintain the overall health of the codebase.

## Contributing to the Project

Follow these steps to contribute to our project:

### Step 1: Fork the Repository

Start by forking the repository. This creates a copy of the repo under your GitHub account, which is your private workspace where you can make changes without affecting the original project.

### Step 2: Create a Feature Branch

1. Clone your fork to your local machine:
```bash
git clone https://github.com/your-username/repository-name.git
2. Navigate into the cloned directory::
```bash
cd repository-name
3. Create a new branch for your feature::
```bash
git checkout -b feature-branch-name

### Step 3: Make Changes
Make the required changes in your feature branch. If you have your development environment setup properly, eslint will run and ensure your code passes all rules before your commits are accepted.

### Step 4: Push Changes and Create a Pull Request
1. Push your changes to your fork::
```bash
git push origin feature-branch-name
2. Go to your fork on GitHub and click "New Pull Request".
3. Set the base repository's sandbox branch as the base branch and your feature branch as the compare branch.
4. Fill in the details of the pull request and submit it.
# Final Steps
Once your PR is submitted, it will be reviewed by our Team. Participate in the discussion and make any required changes. Once your PR is approved, it will be merged into the sandbox branch for further integration testing before it becomes part of the main project.
Thank you for contributing to our project! Your efforts help us build and refine a product that meets the needs of our community.
13 changes: 12 additions & 1 deletion firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"database": {
"port": 9000
},
"storage": {
"port": 9199,
"rules": "storage.rules"
},
"ui": {
"enabled": true
},
Expand All @@ -34,12 +38,19 @@
},
"hosting": {
"public": "frontend/out",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "/api/tool",
"function": "tool"
}
]
},
"storage": {
"rules": "storage.rules"
}
}
16 changes: 8 additions & 8 deletions frontend/firebase/config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// paste your firebase config object here
const firebaseConfig = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_CLIENT_API_KEY,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_CLIENT_AUTH_DOMAIN,
projectId: process.env.NEXT_PUBLIC_FIREBASE_CLIENT_PROJECT_ID,
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_CLIENT_STORAGE_BUCKET,
appId: process.env.NEXT_PUBLIC_FIREBASE_CLIENT_APP_ID,
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
apiKey: process.env.NEXT_PUBLIC_FIREBASE_CLIENT_API_KEY,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_CLIENT_AUTH_DOMAIN,
projectId: process.env.NEXT_PUBLIC_FIREBASE_CLIENT_PROJECT_ID,
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_CLIENT_STORAGE_BUCKET,
appId: process.env.NEXT_PUBLIC_FIREBASE_CLIENT_APP_ID,
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
};

// stop editing below this
export default firebaseConfig;
export default firebaseConfig;
19 changes: 11 additions & 8 deletions frontend/redux/store.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { configureStore } from '@reduxjs/toolkit';

import { initializeApp } from 'firebase/app';
import { getAuth, connectAuthEmulator } from 'firebase/auth';
import { getFirestore, connectFirestoreEmulator } from 'firebase/firestore';
import { getFunctions, connectFunctionsEmulator } from 'firebase/functions';
import { connectAuthEmulator, getAuth } from 'firebase/auth';
import { connectFirestoreEmulator, getFirestore } from 'firebase/firestore';
import { connectFunctionsEmulator, getFunctions } from 'firebase/functions';

import authReducer from './slices/authSlice';
import chatReducer from './slices/chatSlice';
Expand All @@ -19,10 +19,13 @@ const firestore = getFirestore(app);
const functions = getFunctions(app);

// Connect to Firebase Emulators if running locally
if (typeof window !== 'undefined' && window.location.hostname === "localhost") {
connectAuthEmulator(auth, "http://localhost:9099");
connectFirestoreEmulator(firestore, "localhost", 8080);
connectFunctionsEmulator(functions, "localhost", 5001);
if (
typeof window !== 'undefined' &&
['localhost', '127.0.0.1'].includes(window.location.hostname)
) {
connectAuthEmulator(auth, 'http://127.0.0.1:9099');
connectFirestoreEmulator(firestore, '127.0.0.1', 8080);
connectFunctionsEmulator(functions, '127.0.0.1', 5001);
}

const store = configureStore({
Expand All @@ -35,4 +38,4 @@ const store = configureStore({
});

export { auth, firestore, functions };
export default store;
export default store;
21 changes: 12 additions & 9 deletions frontend/services/tools/submitPrompt.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import axios from 'axios';

import firebaseConfig from '@/firebase/config';

const submitPrompt = async (payload, files) => {
try {
const formData = new FormData();
Expand All @@ -14,15 +16,16 @@ const submitPrompt = async (payload, files) => {
});
}

const response = await axios.post(
'/api/tool',
formData,
{
headers: {
'Content-Type': 'multipart/form-data',
},
}
);
const endpoint =
process.env.NODE_ENV === 'development'
? `http://127.0.0.1:5001/${firebaseConfig?.projectId}/us-central1/api/tool`
: '/api/tool';

const response = await axios.post(endpoint, formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});

return response.data?.data;
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions functions/seed_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"0": {
"backgroundImgURL": "https://firebasestorage.googleapis.com/v0/b/kai-ai-f63c8.appspot.com/o/Quizify.png?alt=media&token=d1255f27-b1a1-444e-b96a-4a3ac559237d",
"description": "Create a multiple choice quiz based on any topic, standard(s), and pdf files!",
"id": 0,
"id": "0",
"inputs": [
{
"label": "Topic",
Expand All @@ -28,7 +28,7 @@
"1": {
"backgroundImgURL": "https://firebasestorage.googleapis.com/v0/b/kai-ai-f63c8.appspot.com/o/Dynamo.png?alt=media&token=db14183f-a294-49b2-a9de-0818b007c080",
"description": "Creates flash cards from a youtube video.",
"id": 1,
"id": "1",
"inputs": [
{
"label": "Youtube Video URL",
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"build:next": "cd frontend && npm run build && npm run export",
"serve:frontend": "firebase serve --only hosting",
"deploy": "npm run build:next && firebase deploy",
"emulators": "firebase emulators:start",
"frontend:dev": "cd frontend && npm run dev",
"serve": "npm run build:next && firebase serve",
"lint": "cd frontend && npm run lint && cd ../functions && npm run lint",
"lint:fix": "cd frontend && npm run lint:fix && cd ../functions && npm run lint:fix"
Expand Down
12 changes: 12 additions & 0 deletions storage.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
rules_version = '2';

// Craft rules based on data in your Firestore database
// allow write: if firestore.get(
// /databases/(default)/documents/users/$(request.auth.uid)).data.isAdmin;
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if false;
}
}
}

0 comments on commit 5f9fe91

Please sign in to comment.