Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate FastAPI with Website, Restructure Project, and Enhance Compatibility #386

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Rucha-Ambaliya
Copy link
Contributor

Related Issue

Partially Fixes #374

Description

This pull request focuses on integrating FastAPI with the existing website, restructuring the project for better maintainability, and ensuring seamless compatibility with MongoDB. The updates also include improved documentation and dependency management.

Key Updates

1. Dependency Management

  • Installed all required dependencies for the project.
  • Updated requirements.txt to include the latest dependencies, ensuring the project runs smoothly.

2. Enhanced Project Structure

  • Restructured the project directories and files to improve clarity and maintainability.
  • Updated PROJECT_STRUCTURE.md to reflect the new organization.

3. FastAPI Integration

  • Added routes in main.py in website folder to serve all HTML pages dynamically:
    @app.get("/", response_class=HTMLResponse)
    def read_root(request: Request):
        return templates.TemplateResponse("index.html", {"request": request})
    @app.get("/login", response_class=HTMLResponse)
     def documentation(request: Request):
      return templates.TemplateResponse("login.html", {"request": request})
    # other
    

4. Static File Routing:

  • Staged routes for static files for use across the website:
    app.mount("/static", StaticFiles(directory="../"), name="static")
    app.mount("/web_images", StaticFiles(directory="web_images"), name="web_images")
    app.mount("/styles", StaticFiles(directory="styles"), name="styles")
    app.mount("/scripts", StaticFiles(directory="scripts"), name="scripts")
    app.mount("/software", StaticFiles(directory="../software"), name="software")
    app.mount("/Documentation", StaticFiles(directory="../Documentation"), name="Documentation")

5. MongoDB Integration:

  • Successfully connected the application to MongoDB.
  • Tested the connection to ensure functionality.

6. Secure Environment Management:

  • Implemented .env file support to securely manage sensitive configurations like database URLs.

7. Documentation Improvements:

  • Updated README.md to include steps for running the website using FastAPI.

Testing

  • Verified that all static files and routes work as expected.
  • Confirmed MongoDB connection functionality.

Screenshots

Live website:

Recording.2025-01-17.202140.1.mp4

main.py in website

Recording.2025-01-17.233425.mp4

README.md

Screenshot 2025-01-17 231928

PROJECT_STRUCTURE.md

Screenshot 2025-01-17 232056

Please review the changes and share your feedback. If any additional enhancements or modifications are needed, let me know!

Type of change

  • New feature

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented on my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works

Copy link
Contributor

🎉 Thank you for your contribution! Your pull request has been submitted successfully. A maintainer from team will review it soon. We appreciate your support in making better.

Copy link

netlify bot commented Jan 17, 2025

Deploy Preview for multiverse-dataverse ready!

Name Link
🔨 Latest commit b462bf5
🔍 Latest deploy log https://app.netlify.com/sites/multiverse-dataverse/deploys/678c8b2b2e3f140008216c27
😎 Deploy Preview https://deploy-preview-386--multiverse-dataverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Rucha-Ambaliya
Copy link
Contributor Author

@Tejas-Gupta-7
Could you please review this? If no changes are needed, I’ll start working on fetching reviews from the form and inserting them into MongoDB.

Just a heads-up: since this PR changes the project structure, other PRs related to the website might not merge as expected due to incorrect file paths.

@multiverseweb
Copy link
Owner

Hi @Rucha-Ambaliya, I cloned the PR and tried to test it but I'm facing some issues.

  • Although I have installed all the modules listed in requirements.txt, this error is being thrown:
    image

  • I checked if uvicorn has been installed successfully on the command prompt, it said "requirement already satisfied" but version was not being displayed.
    image

  • Then I opened the directory where all these modules are stored, and uvicorn was present there.
    image

Do you know what the issue is?

PS: I've put some of the PRs and issues on hold so that this one can be merged without complex conflicts. As this one has some merge conflicts already, I think creating a PR with the complete solution to #374 would be a wiser approach.

I would appreciate hearing your thoughts on this.

Also as the issue #374 demands greater time and efforts, I've decided to merge a dummy PR to assign you appropriate points. So, it would be nice if you could create a blank PR and refer to this comment in it. 👍
Thank you.

@Rucha-Ambaliya
Copy link
Contributor Author

Changes Made

I have made two changes in requirements.txt:

  1. The matplotlib was not supporting the latest Python version, so I explicitly mentioned the range of supported versions matplotlib>=3.2,<3.11.
  2. Removed specified versions for every package: This will prevent conflicts with older versions that might have been set up previously.

After making these changes, I forked the branch feature/configure-fastAPI to my local system (in a different folder) and tested it thoroughly. It worked as expected.

Steps Followed

  1. Fork the branch: I made sure to fork the feature/configure-fastAPI branch and not the main branch.
    Path: tempDataverse\
    git clone --branch feature/configure-fastAPI --single-branch https://github.com/Rucha-Ambaliya/Dataverse.git
    
  2. Create and activate a virtual environment:
    python3 -m venv venv
    source venv/bin/activate
    
  3. Install dependencies:
    cd Dataverse
    pip install -r installation/requirements.txt
    
  4. a) To run the application:
python software\main.py
  1. b) To run the website:
cd website
uvicorn main:app --reload

Both the app and website are now running properly on my system.

Debugging the Issue

I faced the same issue where the modules were listed as installed, but I was still getting the "module not found" error. In my case, the issue was that I hadn't activated the virtual environment.

In your case, it seems like you installed the dependencies globally. Could you try the steps I mentioned above, ensuring the virtual environment is activated? This will help me compare and identify the issue more clearly.

Regarding the PR

Thank you for putting the other PRs on hold. This will help me avoid conflicts when merging.

The idea of completing the entire issue in a single PR and creating a dummy PR sounds good to me. This approach will help avoid any further conflicts and also give us an opportunity to properly test FastAPI functionality.

I’ll continue working on the changes related to the model in this same branch.

Thank you for your cooperation and patience @Tejas-Gupta-7!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[WEBSITE] Create backend to store feedbacks
2 participants