Welcome to the CodeFuse project! This repository is used for mobile React Native development, inspired by platforms like bolt.new. This README will guide you through the steps to get started, including setting up the environment, building the Docker image, installing dependencies, and running services.
- Clone the Repository
- Build the Docker Image
- Install Bun
- Initialize PostgreSQL
- Initialize .env
- Running the Application
Start by cloning the repository to your local machine. Use the following command to clone the repository from GitHub:
git clone https://github.com/your-username/codefuse.git
cd codefuseUpon cloning the repository, you will see the following folder structure:
hkirat/
hkirat/
Prod/
ae8620c/
.github/
workflows/
expo-base-app/
ext/
localhost/
framework-serializer/
mobile-magic/
nextjs-base-app/
ops/
react-base-app/
.gitignore
In order to build the Docker image for the project, navigate to the docker folder and build the Docker image using the following command:
docker build -f Dockerfile.code-server -t code-server-update .This will create a Docker image named code-server-update.
Once the Docker image is built, you can run the Docker container with the following command:
docker run -p 8080:8080 code-server-updateThis will start the application on port 8080. You can access the application by opening your browser and navigating to http://localhost:8080.
Bun is a fast JavaScript runtime, and it's required for this project.
For Arch-based Linux systems, you can install Bun using yay. First, install yay if you haven't already:
sudo pacman -S yayThen, install Bun:
yay -S bunFor macOS and Windows users, download and install Bun from the official website: https://bun.sh.
Once Bun is installed, proceed to the next step.
We are using PostgreSQL as the database for the application. To initialize PostgreSQL, use the following Docker command:
docker run -e POSTGRES_PASSWORD=mypassword -p 5432:5432 postgresThis will run PostgreSQL inside a Docker container with the password mypassword.
If you want to run PostgreSQL in the background (detached mode), use the following command:
docker run -d -e POSTGRES_PASSWORD=mypassword -p 5432:5432 postgresThis will run PostgreSQL in the background, and you can interact with it via port 5432.
Before starting the application, ensure you have the .env file configured correctly. You can use the .env.example file as a template for creating your .env file. To do this, simply copy the .env.example file to .env:
cp .env.example .envThen, open .env and adjust any environment variables as needed for your setup.
Once the environment is set up, and PostgreSQL is running, you can start the application.
Make sure all the necessary dependencies are installed by running:
bun installSure! Here’s the continuation of your README.md file, including the new steps you mentioned:
To migrate the Prisma database, navigate to the packages/db folder and run the following command:
cd packages/db
npx prisma migrate devThis will apply the migrations to the PostgreSQL database and sync it with the schema defined in your Prisma setup.
To start the frontend application, go to the apps/frontend directory and run the following command to start the development server using Bun:
cd apps/frontend
bun devThis will start the frontend application and make it available for local development.
To start the backend server, navigate to the apps/primary-backend directory and run the following command to start the backend:
cd apps/primary-backend
bun index.tsThis will start the backend server, and it should now be running and ready to handle requests.
Make sure to configure all necessary API keys in your .env file. You can reference the .env.example file to see which keys need to be added.
To copy the example .env file to your actual .env file, use the following command:
cp .env.example .envThen, open the .env file and add all the required API keys and environment-specific variables.
Finally, to start the LLM (Large Language Model) backend, go to the apps/worker directory and run the following command:
cd apps/worker
bun index.tsHere is the continuation of the README with the steps to sign in to Clerk, update the JWT key, and set the Clerk-related environment variables (NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY and CLERK_SECRET_KEY) as per the .env.example file:
Clerk is used for authentication and managing user sessions in the application. To integrate Clerk into your project, you'll need to sign in to Clerk and configure the required keys.
- Go to the Clerk dashboard and sign up for an account or log in if you already have one.
- Once logged in, go to the API Keys section in the Clerk dashboard.
- Obtain the following keys:
- Publishable Key (
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY) - Secret Key (
CLERK_SECRET_KEY)
- Publishable Key (
After obtaining the Clerk keys, you'll need to update your .env file with the values for NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY and CLERK_SECRET_KEY.
- Copy the keys from your Clerk dashboard.
- Open the
.envfile in the root of your project. - Update the environment variables with the following:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your-clerk-publishable-key
CLERK_SECRET_KEY=your-clerk-secret-keyMake sure to replace your-clerk-publishable-key and your-clerk-secret-key with the actual keys from Clerk.
You may also need to update the JWT key in your .env file, depending on your Clerk configuration. For example:
JWT_KEY=your-jwt-secret-keyEnsure that all keys are correctly updated and saved.
After updating the environment variables, restart all services (frontend, backend, and worker) to apply the changes.
-
Restart the frontend:
cd apps/frontend bun dev -
Restart the backend:
cd apps/primary-backend bun index.ts -
Restart the LLM worker:
cd apps/worker bun dev
To run all the services in the apps folder, follow these steps:
-
Frontend Service: Go to the
apps/frontenddirectory and run the development server using Bun:cd apps/frontend bun dev -
Backend Service: Next, navigate to the
apps/primary-backenddirectory and start the backend server:cd apps/primary-backend bun index.ts -
Worker Service: Lastly, navigate to the
apps/workerdirectory and start the worker service:cd apps/worker bun dev
If you'd prefer to run all services in parallel, you can either use a tool like concurrently or manually open separate terminal tabs for each service. Here's an example of using concurrently:
-
Install
concurrently:bun add concurrently
-
Create a new script in your
package.jsonto run all services:"scripts": { "start:all": "concurrently \"bun dev --cwd apps/frontend\" \"bun index.ts --cwd apps/primary-backend\" \"bun dev --cwd apps/worker\"" }
-
Then, run the command:
bun start:all
This will run the frontend, backend, and worker services simultaneously in your terminal.
Here are some common errors you may encounter and their resolutions:
You might encounter the following error when interacting with Kubernetes resources:
error: HTTP-Code: 404
Message: Unknown API Status Code!
Body: "Not found."This error typically indicates that the Kubernetes resource you're trying to access doesn't exist or the API server is not reachable. Here’s how to resolve it:
-
Verify Kubernetes Cluster Connection: Ensure your Kubernetes cluster is running and accessible. You can check the connection by running the following command:
kubectl get pods --all-namespaces
If you see an error, check your Kubernetes configuration and ensure it's pointing to the correct cluster.
-
Check Resource Existence: The resource you're trying to access may not exist, such as a specific namespace or pod. Use the following commands to verify the existence of resources like namespaces:
kubectl get namespaces
If the namespace doesn’t exist, create it:
kubectl create namespace user-apps
-
Check the Correct API Endpoint: Ensure the correct API path is being used in your code. If you're trying to create or list resources in a specific namespace, ensure that the namespace exists and is correctly referenced.
When running the command to view the Kubernetes configuration, you might see the following error:
error: current-context must exist in order to minifyThis indicates that there is no current context set in your Kubernetes configuration, which is necessary to interact with the cluster. To resolve this:
-
Check Kubernetes Configuration: Ensure your
kubectlcontext is properly set. Run:kubectl config get-contexts
Then, set the correct context:
kubectl config use-context <your-context-name>
Replace
<your-context-name>with the appropriate context. -
Verify Context Configuration: If no contexts are set, you might need to authenticate with your Kubernetes provider (e.g., AWS EKS, GKE, etc.) to set the context correctly.
When building and running Docker images, you might encounter errors. Some potential issues include:
-
Docker Not Found: Ensure Docker is installed on your system. If it isn't, install Docker using the official instructions for your operating system:
-
Permission Denied Errors: You might encounter permission issues when trying to build or run Docker containers. Make sure you have the necessary permissions or try running the commands with
sudo:sudo docker build -f Dockerfile.code-server -t code-server-update . sudo docker run -p 8080:8080 code-server-update
-
.env Configuration: Ensure your
.envfile is correctly configured with all required keys and variables for API integrations, database connections, and authentication. Use.env.exampleas a template and replace placeholders with actual values. -
Database Initialization: If you encounter issues with the database, ensure that PostgreSQL is properly initialized and the environment variables for database connections are correctly set in your
.envfile.You can initialize PostgreSQL via Docker with the following command:
docker run -e POSTGRES_PASSWORD=mypassword -p 5432:5432 postgres
Or, for detached mode:
docker run -d -e POSTGRES_PASSWORD=mypassword -p 5432:5432 postgres
-
API Keys and External Services: For any external services like Clerk, ensure that your API keys are correctly configured in the
.envfile. Refer to the Clerk section of the README for specific instructions on setting up Clerk.