c0sogi / LLMChat

A full-stack Webui implementation of Large Language model, such as ChatGPT or LLaMA.
MIT License
257 stars 45 forks source link

Separate container for web #31

Closed Torhamilton closed 1 year ago

Torhamilton commented 1 year ago

Advice needed. I am trying to move web into a separate container and leave only fastAPI in api.

c0sogi commented 1 year ago

Do you mean you want to create an independent server that serves only html? If so, Ngnix can be used to serve static files. You can do this by creating a Ngnix container and setting the volume to ./app/web:/static in the volumes section. Of course, this also requires Traefik routing, and since Traefik's Host rule overlaps with the value used by the existing Fastapi server, you can move the hostrules to a different domain, so you can prevent access to FastAPI container.

Torhamilton commented 1 year ago

The plan is to use a single shared instances of mysql, qdrant, redis and if possible fastAPI. then the frontend is independent per domain. I am also investigation simply symlinking the app/ folder. Avoiding duplicated code base for multiple domains on same server. using Nginx and traefik on same deployment can lead to nightmares. Lets take our time on this one. No rush

c0sogi commented 1 year ago

So you're saying that if you're running multiple domains, you want to set up the backend instance on a single server, and only assign the frontend to each domain.

I guess you want to replace the existing monolithic architecture with microservices. Is this correct?

Torhamilton commented 1 year ago

Yes and no. More like make fastAPI a headless backend by decoupling web. Here is a simplified version: `services: core: image: fastapi_core_image environment:

Pool configurations for each domain

  POOL_1: "mysql+mysqlconnector://user1:password1@db:3306/db1"
  POOL_2: "mysql+mysqlconnector://user2:password2@db:3306/db2"
  REDIS_1: "redis://:password1@cache:6379/0"
  REDIS_2: "redis://:password2@cache:6379/1"
  QDRANT_1: "qdrant_collection_1"
  QDRANT_2: "qdrant_collection_2"

domain1: image: flutter_app environment: DOMAIN_ID: "1" BACKEND_URL: "http://core:8000"

domain2: image: flutter_app environment: DOMAIN_ID: "2" BACKEND_URL: "http://core:8000" ` This allows customization of frontend. Also it is a lighter architecture, web containers are thin clients.

For more complex systems, FastApi can stored the connection pool in a db instead of environment variables. This may be easier to implement and my preferred option. The db can be prepopulated with 20 connections or so. And a bash script runs the docker-compose instantiation.

Your thought?

c0sogi commented 1 year ago

Clients will send API requests to the real domain rather than hitting the BACKEND_URL set to http://core:8000. Because it is the client's browser, not flutter_app, that sends the actual API request. So while it is possible to mediate APIs using internal service names, it seems unlikely that you will be able to completely separate backend and frontend.

Torhamilton commented 1 year ago

Okay for now I will symlink the code base among instances