humblFINANCE / humblFINANCE-frontend

the official codebase for the humblFINANCE web app
https://humbl-finance-frontend.vercel.app
Other
2 stars 1 forks source link

[FEAT]: Setup basic FASTAPI server in `/api` #30

Closed jjfantini closed 3 months ago

jjfantini commented 3 months ago

Main Goal

Just as the project is set up in my test repo, I need to integrate a FastAPI route proxy in the

Tasks

Notes

If it becomes difficult to integrate humblDATA as a requirement, consider moving to a serperate repo for FastAPI server that is hosted on Vercel serverless functions. Then the app can take on a larger more complex strucutre and use poetry for package management. GIven how few functions should be required to map from humblDATA, the /api ROUTE method should suffice. There shouldn't be database interactions using FastAPI becuase I think itll be faster using JS and supabase

Initial thoughts surrounding how to process and save historical Mandelbrot Channel are to use .parquet files. This file type is read/wrote v. quickly via Polars (the main data analytics engine in humblDATA). So when manipulations are done via Python and humblDATA, the data will be sent back to JS as a .parquet file, with the filename a unique hash of the command arguments, so that if those areguments are passed again, that file will be retireived and the latest date will be extracted so the calculation only runs from the latest date. I am not opposed to the FastAPI server reading/writing from the supabase databasse directly if it does not add too much complexity to the overall FastAPI server, and if the speed is comparable to using JS.

Resources

next.config.js

/** @type {import('next').NextConfig} */
const nextConfig = {
  rewrites: async () => {
    return [
      {
        source: "/api/:path*",
        destination:
          process.env.NODE_ENV === "development"
            ? "http://127.0.0.1:8000/api/:path*"
            : "/api/",
      },
      {
        source: "/docs",
        destination:
          process.env.NODE_ENV === "development"
            ? "http://127.0.0.1:8000/docs"
            : "/api/docs",
      },
      {
        source: "/openapi.json",
        destination:
          process.env.NODE_ENV === "development"
            ? "http://127.0.0.1:8000/openapi.json"
            : "/api/openapi.json",
      },
    ];
  },
};

module.exports = nextConfig;

package.json

  "scripts": {
    "fastapi-dev": "pip3 install -r requirements.txt && python3 -m uvicorn api.index:app --reload",
    "next-dev": "next dev",
    "dev": "concurrently \"npm run next-dev\" \"npm run fastapi-dev\"",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },