Skip to content

Adopt MVC-ish architecture with Tauri + FastAPI; prefer Svelte UI for performance (vs React's Obesity)Β #5

@KoeppelSoftwareEngineer

Description

πŸ“Œ Summary

πŸ“Œ Proposal: A Tauri desktop app. It uses a Svelte (or SvelteKit) frontend and a FastAPI backend.
🧩 The layout follows MVC principles for clear separation of concerns. This makes the app maintainable and scalable.
🚫 Svelte avoids React’s β€œwebsite obesity,” dependency bloat, and performance issues. It reduces security risks from third‑party library dependencies.
πŸ“¦ Tauri provides small bundle sizes and a secure native shell.


🧭 Recommended MVC-ish Layout (Option A)

my-farm-app/
β”œβ”€ src/                       # Tauri frontend (View: React/Vue/Svelte)
β”œβ”€ src-tauri/                 # Tauri shell, native config & helpers
β”‚  β”œβ”€ src/
β”‚  └─ tauri.conf.json
β”œβ”€ backend/                   # FastAPI (Controller + Model + Services)
β”‚  β”œβ”€ app/
β”‚  └─ alembic/                # Migrations (or migration notes for MongoDB)
└─ scripts/
   └─ run_fastapi.py          # Entrypoint Tauri can spawn

πŸ“ˆ Overview

+-----------------------------+             +------------------------------+
|         Tauri UI            |  HTTP/WS    |           FastAPI             |
|  SvelteKit (View)           +------------>+  Controllers (Routers)       |
|  State/Store (ViewModel*)   |             |  Services (Business Logic)    |
|                             |             |  Models (Pydantic)            |
+-----------------------------+             |  DB (SQLite/Postgres/MongoDB) |
               ^                             +------------------------------+
               |             IPC (process mgmt) via Tauri
               +------------------------------- start/stop backend

Component (Architecture) Diagram

+--------------------+         HTTP/JSON          +----------------------+       ODM       +-------------------+
|  Browser (Svelte)  |  --->  http://127.0.0.1:5173  |  FastAPI (Uvicorn)  |  <----->  Beanie  |   MongoDB Server  |
|  Vite dev:5174     |         CORS allowed        |  app.main / routers  |   (models)       |  movies_db        |
+--------------------+                              +----------+-----------+                 +---------+---------+
                                                            |                                       |
                                                            | (CRUD /movies)                        | (collection "movies")
                                                            v                                       v
                                                     Controllers (api/movies.py)             Collection: movies

Activity Diagram (Add Movie)

          +--------------------+
          | User enters title  |
          +---------+----------+
                    |
                    v
          +--------------------+
          | Click "Add"        |
          +---------+----------+
                    |
                    v
          +--------------------+
          | UI POST /movies    |
          | {title}            |
          +---------+----------+
                    |
                    v
          +-----------------------------+
          | FastAPI: validate payload   |
          | (MovieCreate via Pydantic)  |
          +---------+-------------------+
                    |
         [valid]    |    [invalid]
           |        |        |
           v        |        v
+------------------+|   +-------------------+
| Insert with       ||   | 400/422 response |
| Beanie -> MongoDB ||   +-------------------+
+---------+---------+|
          |          |
          v          |
+--------------------+      (invalid path ends)
| Return MovieRead   |
| {id, title}        |
+---------+----------+
          |
          v
+--------------------+
| UI updates list    |
+--------------------+

🧰 Useful Libraries

  • FastAPI: routers, DI, OpenAPI
  • Pydantic v2: schemas
  • Motor: async MongoDB driver
  • Alembic: migrations (for relational DBs; MongoDB uses manual migration scripts)
  • Uvicorn: ASGI server
  • Tauri: process management, secure FS APIs, updater, autostart
  • Frontend: SvelteKit (or React/Vue alternatives)

🧩 Why MVC? (Model–View–Controller)

  • Model: Data + business rules (Pydantic schemas, MongoDB collections or SQLAlchemy for relational DBs).
  • View: UI and presentation (SvelteKit in Tauri window).
  • Controller: FastAPI routers orchestrating requests and responses.

Benefits

  • Clear separation of concerns β†’ maintainable, testable, scalable.
  • Swap UI frameworks or DB backends (SQLite/Postgres ↔ MongoDB) without rewriting the whole app.
  • Keep frontend lean; backend handles heavy logic.

πŸ”§ Decision Proposal: Prefer SvelteKit for the View

  • Lightweight, fast, compiles to minimal JS, works perfectly with Tauri.
  • Alternatives: SolidJS, Vanilla JS, React (heavier).

🧱 Data & Backend Choices

  • Backend: FastAPI (Controllers + Services + Models).
  • Database:
    • Start with MongoDB for document-oriented flexibility.
    • SQLite/Postgres remain options for relational needs later.
  • Migrations: Alembic for relational DBs; manual scripts for MongoDB.

⚠️ Risks & Mitigations

  • Dependency bloat β†’ Prefer SvelteKit, audit packages.
  • Performance β†’ Keep bundle small, offload heavy logic to backend.
  • Security β†’ Pin versions, use Tauri secure APIs.
  • DB choice β†’ MongoDB for flexibility now; Postgres later if relational needs arise.

🎯 Acceptance Criteria

  • Tauri app launches and spawns/stops FastAPI backend.
  • SvelteKit UI loads and interacts with FastAPI endpoints.
  • MongoDB integration works for CRUD operations.
  • Clear MVC separation in codebase.

βœ… Next Steps

  1. Confirm frontend: SvelteKit.
  2. Confirm database: MongoDB now; Postgres optional later.
  3. Scaffold repo with Tauri + SvelteKit + FastAPI + MongoDB.
  4. Add CI and performance checks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions