-
Notifications
You must be signed in to change notification settings - Fork 0
1 polish the structure of the repo and add nextjs generated gui #2
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
Open
KoeppelSoftwareEngineer
wants to merge
41
commits into
main
Choose a base branch
from
1-polish-the-structure-of-the-repo-and-add-nextjs-generated-gui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
cfa3505
NO change in version.py
GorkiPower 4c3e908
add main.py; add model.py
GorkiPower 9cc70a9
add: from datetime import datetime
GorkiPower 8681ea8
add simple FARM-Stack
GorkiPower 621e3fd
Ready to start -> uvicorn backend.main:app --reload
GorkiPower 65b4a20
add
GorkiPower 6f58f29
frontend is working without 404 Not Found
GorkiPower efebed4
Add Next.js frontend
GorkiPower 4cf11e4
Starting Clean Backend Frontend NOT working together
GorkiPower ca11ef8
Server are NOT TALKING TO EACH OTHER
GorkiPower 4494a01
Server a running - Frontend and Backend are NOT communiating
GorkiPower 32f49ac
Update REAMDE
GorkiPower 1568c6d
Updated README
GorkiPower 8f057e1
ruff check .; ruff check . --fix; ruff format .; Add Ruff to pyprojec…
GorkiPower 6ebd4f7
Update pyproject.toml
GorkiPower e83a983
Update: backend/_version.py
GorkiPower 297ddf2
Apply Ruff formatting
GorkiPower f5dacc3
Update database.py, datamodel.py, main.py, model.py
GorkiPower 05c1ce3
Updated datamodel.py main.py model.py
GorkiPower dcbf01e
run ruff check . --fix and ruff format .
GorkiPower 1a728af
clean model.py
GorkiPower eb80f2f
bugs are fixed - ruff is happy
GorkiPower 5c597aa
Merging model.py and datamodel.py has led to challenges :D Works now …
GorkiPower be2ef20
Clean all the rubbish
GorkiPower 78a303e
delete model.py
GorkiPower fda8f59
Update: main before more verbose
GorkiPower db59966
It works fine
GorkiPower b8d2af9
BugFix: ruff check . --fix; ruff format .
GorkiPower 46c4338
Update main.py
GorkiPower 158dff2
feat: use jsonable_encoder with custom ObjectId encoder for clean RES…
GorkiPower 9a8e751
SchemaDefinition with Optional Fields
GorkiPower f977b81
Refactored main.py 🔑 id: str ~ improve clarity and prepare for future…
GorkiPower 93d86eb
Updated backend/datamodel.py
GorkiPower bc4e036
Refactored/CleanUp main.py: using list[dict[str, Any]] for Python(3.9+)
GorkiPower 3b17c4a
Cleanup datamodel.py
GorkiPower 9895288
Files cleaned up
GorkiPower bca088f
id: using hashlib implemented
GorkiPower ea934ef
Update datamodel.py, main.py - hashing is working
GorkiPower 47984cf
Implement schema editing for flat JSON
GorkiPower 3740f8d
Bugfix
GorkiPower 170b761
ruff format .
GorkiPower File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,287 @@ | ||
| # jsoned | ||
| A full-stack application to visualize and edit entities and their relations defined in JSON Schema. | ||
|
|
||
|
|
||
|
|
||
| *** | ||
|
|
||
| # JSONED — Full Teaching Guide | ||
|
|
||
| > **Goal:** Learn how to build and run a full-stack app to **visualize and edit JSON Schema entities** using **FastAPI** (backend) and **React** (frontend). Includes MongoDB integration as an advanced option. | ||
|
|
||
| *** | ||
|
|
||
| ## ✅ Quick Start | ||
|
|
||
| ### 1. Clone the repository | ||
|
|
||
| ```bash | ||
| jsoned> git clone https://github.com/BAMresearch/jsoned.git | ||
| jsoned> cd jsoned | ||
| jsoned> dir # Windows | ||
| jsoned> ls # Linux/macOS | ||
| ``` | ||
|
|
||
| *** | ||
|
|
||
| ### 2. Backend Setup (Terminal 1) | ||
|
|
||
| ```bash | ||
| jsoned> cd backend | ||
| backend> python -m venv venv | ||
| backend> source venv/bin/activate # Windows: venv\Scripts\activate | ||
|
|
||
| backend(venv)> pip install -r requirements.txt | ||
|
|
||
| backend(venv)> uvicorn main:app --reload | ||
| # or specify host/port | ||
| backend(venv)> uvicorn main:app --reload --host 127.0.0.1 --port 8000 | ||
| ``` | ||
|
|
||
| #### If using `pyproject.toml`: | ||
|
|
||
| ```bash | ||
| # using install -e . | ||
| pip install -e . | ||
| pip install -e .[dev] #when dev is defined | ||
|
|
||
| # Check which tool is used (Poetry or Pipenv) | ||
|
|
||
| # If Poetry: | ||
| backend> pip install poetry | ||
| backend> poetry install | ||
| backend> poetry shell | ||
|
|
||
| # If Pipenv: | ||
| backend> pip install pipenv | ||
| backend> pipenv install | ||
| backend> pipenv shell | ||
|
|
||
| # If standard PEP 621: | ||
| backend> pip install . | ||
| ``` | ||
|
|
||
| **Check:** Open `http://127.0.0.1:8000/docs` → FastAPI docs should appear. | ||
|
|
||
| *** | ||
|
|
||
| ### 3. Frontend Setup (Terminal 2) | ||
|
|
||
| **Create React app:** | ||
|
|
||
| ```bash | ||
| jsoned> npx create-react-app gui | ||
| jsoned> cd gui | ||
| gui> dir # Windows | ||
| gui> ls # Linux/macOS | ||
| ``` | ||
|
|
||
| **Install Axios for API calls:** | ||
|
|
||
| ```bash | ||
| gui> npm install axios | ||
| gui> npm audit #Run audit details | ||
| gui> npm audit fix #Fix automatically | ||
|
|
||
| ``` | ||
|
|
||
| **Run frontend:** | ||
|
|
||
| ```bash | ||
| gui> npm start # Standard start command | ||
|
|
||
| #OR | ||
| gui> npm run dev # Alias for developer mode | ||
|
|
||
| INFO:To npm run dev DO THE FOLLOWING: | ||
| in package.json add ->> "dev": "react-scripts start": | ||
|
|
||
| "scripts": { | ||
| "start": "react-scripts start", | ||
| "build": "react-scripts build", | ||
| "test": "react-scripts test", | ||
| "eject": "react-scripts eject", | ||
| "dev": "react-scripts start" | ||
| } | ||
|
|
||
| ``` | ||
|
|
||
| ✔ **Difference?** | ||
|
|
||
| * `npm start` → Runs the default development server. | ||
| * `npm run dev` → Custom alias (same behavior here). | ||
|
|
||
| 📂 **Where are App.js and App.css?** | ||
|
|
||
| * Located in `gui/src/`: | ||
| * `App.js` → Main React component | ||
| * `App.css` → Styling for App.js | ||
|
|
||
| ✅ **Check:** | ||
|
|
||
| * `http://localhost:3000` | ||
|
|
||
| *** | ||
|
|
||
| ## ✅ Architecture & Diagrams | ||
|
|
||
| ### **High-Level Architecture** | ||
|
|
||
| +-------------------+ HTTP API +-------------------+ MongoDB | ||
| | React Frontend | <--------------------> | FastAPI | <----> | Database | | ||
| | (Components/UI) | | (Routes/Models) | | Schemas | | ||
| +-------------------+ +-------------------+ +----------+ | ||
|
|
||
| *** | ||
|
|
||
| ### **Detailed Component Flow** | ||
|
|
||
| [User Action] --> [React Component] --> [Axios API Call] --> [FastAPI Endpoint] | ||
| | | | ||
| | v | ||
| | [MongoDB Query] | ||
| | | | ||
| v v | ||
| [Updated State] <-- [JSON Response] <-- [FastAPI Response] <-- [Database Result] | ||
|
|
||
| *** | ||
|
|
||
| ### **Backend Layer Diagram** | ||
|
|
||
| +-------------------+ | ||
| | main.py | -> Routes & Controllers | ||
| +-------------------+ | ||
| | models.py | -> Pydantic Schemas | ||
| +-------------------+ | ||
| | database.py | -> MongoDB Connection | ||
| +-------------------+ | ||
|
|
||
| *** | ||
|
|
||
| ### **Frontend Folder Structure** | ||
|
|
||
| gui/ | ||
| ├── public/ | ||
| ├── src/ | ||
| │ ├── App.js # Main React Component | ||
| │ ├── api.js # Axios API Calls | ||
| │ ├── components/ # UI Components | ||
| │ └── App.css # Styling | ||
|
|
||
| *** | ||
|
|
||
| ### **Request Lifecycle** | ||
|
|
||
| User Click -> React -> Axios -> FastAPI -> MongoDB -> Response -> React State Update | ||
|
|
||
| *** | ||
|
|
||
| ### **MVC Mapping** | ||
|
|
||
| Model -> Pydantic schemas (datamodel.py, model.py) | ||
| View -> React components (App.jsx) | ||
| Controller -> FastAPI routes (main.py) | ||
|
|
||
| *** | ||
|
|
||
| ### **Sequence Flow (Add Version)** | ||
|
|
||
| User -> React -> FastAPI -> In-memory DB | ||
| | | | | | ||
| | Click Add | | | ||
| |---------------> | | | ||
| | POST /version | | ||
| | -> Append SchemaDefinition | ||
|
|
||
| *** | ||
|
|
||
| ### **UML Class Diagram** | ||
|
|
||
| +-------------------------+ | ||
| | SchemaDefinition | | ||
| +-------------------------+ | ||
| | id: str | | ||
| | name: str | | ||
| | version: str | | ||
| | content: dict | | ||
| | updated_at: datetime | | ||
| +-------------------------+ | ||
|
|
||
| +-------------------------+ | ||
| | UpdateSchema | | ||
| +-------------------------+ | ||
| | name: str | None | | ||
| | version: str | None | | ||
| +-------------------------+ | ||
|
|
||
| *** | ||
|
|
||
| ### **MongoDB Integration Flow** | ||
|
|
||
| +-----------+ Axios HTTP +-----------+ PyMongo +-----------+ | ||
| | React | ---> POST /version -> | FastAPI | ---> Insert Doc -> | MongoDB | | ||
| | Frontend | GET /version | Backend | Query Docs | Database | | ||
| +-----------+ PATCH /version +-----------+ Return JSON +-----------+ | ||
|
|
||
| *** | ||
|
|
||
| ## ✅ MongoDB Atlas Setup (Optional Advanced) | ||
|
|
||
| 1. Create account at <https://www.mongodb.com/atlas> | ||
| 2. Create cluster and get connection string | ||
| 3. Add `.env` in `backend`: | ||
|
|
||
| <!----> | ||
|
|
||
| MONGO_URI="your-atlas-uri" | ||
|
|
||
| 4. Use `pymongo` in `database.py`: | ||
|
|
||
| ```python | ||
| from pymongo import MongoClient | ||
| from dotenv import load_dotenv | ||
| import os | ||
|
|
||
| load_dotenv() | ||
| client = MongoClient(os.getenv("MONGO_URI")) | ||
| db = client.jsoned_db | ||
| ``` | ||
|
|
||
| *** | ||
|
|
||
| ## ✅ API Endpoints | ||
|
|
||
| GET /version | ||
| POST /version | ||
| PUT /version/{id} | ||
| PATCH /version/{id} | ||
| DELETE /version/{id} | ||
|
|
||
| *** | ||
|
|
||
| ## ✅ Best Practices | ||
|
|
||
| * Use `.env` for secrets | ||
| * Enable CORS for frontend | ||
| * Keep code modular | ||
|
|
||
| *** | ||
|
|
||
| ## ✅ Troubleshooting | ||
|
|
||
| * **CORS errors**: Add `CORSMiddleware` | ||
| * **npm issues**: Delete `node_modules` → `npm install` | ||
| * **Port conflicts**: Change port in `uvicorn` or `npm run dev` | ||
|
|
||
| *** | ||
|
|
||
|
|
||
|
|
||
| ## ✅ Resources | ||
|
|
||
| * <https://fastapi.tiangolo.com/> | ||
| * <https://docs.pydantic.dev/> | ||
| * <https://react.dev/> | ||
| * <https://www.mongodb.com/docs/> | ||
|
|
||
| *** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from pymongo import MongoClient | ||
|
|
||
| client = MongoClient("mongodb://localhost:27017/") | ||
| db = client["jsoned_db"] | ||
| schemas_collection = db["schemas"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.