Auto Email Generation is a project that utilizes FastAPI for the backend and a React frontend to automatically generate emails based on user input using the OpenAI API.
Directory | Purpose |
---|---|
Root | Essential project files and configurations (e.g., .env, docker-compose.yml, README.md) |
.github | GitHub workflow configurations for automated tasks (e.g., testing, deployment) |
.vscode | Visual Studio Code IDE settings and configurations |
backend | Backend service code, configurations, and dependencies |
Organized structure with folders for different components (config, models, routes) | |
frontend | Frontend service's React application code |
Organized in a typical React project structure (public, src) | |
test-events-lambda | Test event data for local Lambda function testing |
-
Node.js Environment (Frontend):
- Make sure you have Node.js and npm (Node Package Manager) installed on your system.
- You can download Node.js from the official website: nodejs.org
- To install frontend packages run the below command:
cd frontend npm ci
-
Python Environment (Backend):
It's recommended to use a virtual environment for Python to manage dependencies.
A. Using
venv
- Create a virtual environment in the
backend
directory:cd backend python -m venv email_gen
- Activate the virtual environment:
- On Windows:
email_gen\Scripts\activate
- On macOS and Linux:
source email_gen/bin/activate
- On Windows:
- Install the required Python packages:
pip install -r requirements.txt
B. Using
Conda
To set up a Conda environment using a requirements file, you can follow these steps:
-
Create a Conda Environment: Open your terminal and run the following command to create a new Conda environment (replace
myenv
with the desired environment name):conda create --name email_gen
-
Activate the Environment: Activate the newly created environment using the following command:
conda activate email_gen
-
Install Packages from a Requirements File: You can use the
conda install
command to install packages from a requirements file. If your requirements file is namedrequirements.txt
, run the following command:conda install --file requirements.txt
Replace
requirements.txt
with the actual path to your requirements file if it's located in a different directory. -
Verify Installed Packages: After installing the packages, you can use the
conda list
command to verify that the required packages have been installed:conda list
-
Deactivate the Environment: When you're done working in the environment, you can deactivate it using the following command:
conda deactivate
- Create a virtual environment in the
-
Setting up the environment variables
- Navigate to the root directory of your project.
- Create a new file named
.env
in the root directory.
Inside the
.env
file, add the following lines with your actual values for the environment variables:OPENAI_ORGANIZATION=your-organization-id OPENAI_API_KEY=your-api-key
Replace
your-organization-id
with your actual OpenAI organization ID andyour-api-key
with your actual OpenAI API key.Make sure not to include any quotes around the values. The
.env
file is used to store sensitive information, so keep it private and do not share it publicly. -
Further Configuration: Adjust any other configurations as necessary in the respective files and directories.
-
Start FastAPI Server (Backend):
cd backend uvicorn app.main:app --host 127.0.0.1 --port 8000 --reload
This command starts the FastAPI server on
http://127.0.0.1:8000
. -
Start Frontend Server:
cd frontend npm start
In a separate terminal, run this command to start the React frontend server. This will typically start on
http://localhost:3000
.
- Test Lambda Function:
Use
python-lambda-local
to test your Lambda function locally. Run the following command:cd backend python-lambda-local -f handler app/main.py ../test-events-lambda/test_event.json
-
Build/Start Containers:
- Open a terminal in your project's root directory.
- Run the following command to build and start the containers defined in the
docker-compose.yml
file:docker-compose up
- To build image and container from scratch, use the following command:
docker-compose up --build
- This command will start both the backend and frontend containers, pulling necessary images if they don't exist locally.
-
Access Frontend and Backend:
- Once the containers are up and running, you can access the frontend by opening your browser and navigating to
http://localhost:3000
. - The backend's FastAPI server will be accessible at
http://localhost:8000
.
- Once the containers are up and running, you can access the frontend by opening your browser and navigating to
-
Modify Code:
- Make changes to your frontend or backend code as needed.
- Docker Compose will automatically reload the containers when changes are detected in the project directories mapped into the containers.
-
Stop Containers:
- When you're finished, you can stop the containers by pressing
Ctrl+C
in the terminal wheredocker-compose up
is running.
- When you're finished, you can stop the containers by pressing
-
Cleaning Up:
- To stop and remove the containers, as well as their associated networks and volumes, run:
docker-compose down --rmi all
- To stop and remove the containers, as well as their associated networks and volumes, run:
-
Login to Amazon ECR Registry:
Use this command to authenticate Docker to your Amazon Elastic Container Registry (ECR) account for the specified region. Replace
<account-id>
and<region>
with your actual account ID and region.aws ecr get-login-password --region us-west-1 | docker login --username AWS --password-stdin <account-id>.dkr.ecr.<region>.amazonaws.com/email-gen-lambda:latest
This command fetches an authentication token and logs Docker into your ECR registry.
-
Get AWS Account Identity:
Use this command to verify the AWS account identity you're currently using.
aws sts get-caller-identity
This command provides information about your AWS account, such as the account ID, user ID, and ARN.
-
Build Docker Image for Lambda:
Navigate to the
backend
directory and build the Docker image for your Lambda function using the specified Dockerfile.cd backend docker build -t email-gen-lambda ./ -f ./Dockerfile.lambda.dev
This command builds the Docker image based on the specified Dockerfile (
Dockerfile.lambda.dev
) in thebackend
directory. -
Tag Docker Image:
After building the Docker image, tag it with the ECR repository's URI.
docker tag email-gen-lambda:latest <account-id>.dkr.ecr.<region>.amazonaws.com/email-gen-lambda:latest
This command assigns a new tag to the Docker image, indicating the ECR repository location.
-
Push Docker Image to ECR:
Push the tagged Docker image to your ECR repository.
docker push <account-id>.dkr.ecr.<region>.amazonaws.com/email-gen-lambda:latest
This command uploads the Docker image to your ECR repository for future use.
Welcome to our project! We appreciate your interest in contributing. By following these guidelines, you can help us maintain a productive and collaborative development environment. Please take a moment to review the guidelines before getting started.
-
Fork the Repository: Start by forking this repository to your GitHub account. This will create a copy of the project under your account that you can work on.
-
Clone the Repository: Clone the forked repository to your local machine using the following command:
git clone https://github.com/your-username/email-generation.git
-
Create a New Branch: Before making any changes, create a new branch for your feature, bug fix, or improvement. Use a descriptive and relevant name for your branch.
git checkout -b feature/new-feature
-
Coding Standards: Follow the existing coding style and standards used in the project. This includes formatting, naming conventions, and code organization.
-
Testing: Ensure that your code changes do not break existing tests, and if applicable, write new tests to cover the changes you've made.
-
Documentation: Update the project's documentation to reflect any changes you've made. This includes README files, code comments, and docstrings.
-
Commit Changes: Once your changes are ready, commit them with clear and concise commit messages. Use the present tense and provide context for the change.
git commit -m "Add new feature: XYZ"
-
Push to Your Fork: Push the changes to your forked repository on GitHub.
git push origin feature/new-feature
-
Create a Pull Request (PR): Open a pull request from your branch to the main repository's
main
branch. Provide a detailed description of the changes, why they are necessary, and any relevant information.
-
Review Process: Your pull request will be reviewed by project maintainers. Be prepared for feedback and possible discussions about your changes.
-
Addressing Feedback: If changes are requested, address them by making additional commits. Keep the pull request updated with the latest changes.
-
Merge Approval: Once the changes are approved by a maintainer, your pull request will be merged into the main repository.
- Respect the project's code of conduct and community guidelines at all times.
- Be patient and respectful when interacting with other contributors and maintainers.
- Happy coding and thank you for contributing to our project!
This project is licensed under the BSD 3-Clause
License. See the LICENSE file for details.
Note: This README provides a basic setup guide. Additional setup and configuration might be needed depending on your environment and requirements.