diff --git a/.gitignore b/.gitignore index a99879d..14290b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,11 @@ */__pycache__/ __pycache__/ *.pyc + +# Runtime data belongs outside this repository. +/database/ +/backend/*.db +*.db-journal +*.db-shm +*.db-wal +/mxpic_EDA_database/ diff --git a/README.md b/README.md index 79af408..840fa1f 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,25 @@ PDK component assets and `technology.yml` manifests are loaded from the same role-scoped PDK roots. Normal users and developers use `MXPIC_PDK_PUBLIC_ROOT` or `../opt_pdk_public/foundries`; managers use `MXPIC_PDK_ATLAS_ROOT` or `../opt_pdk_atlas/foundries`. + +## Runtime Database Root + +Runtime data is not stored inside this repository. Move the existing `database` +folder beside `mxpic_EDA` and rename it: + +```text +mxpic_EDA_database +``` + +Default runtime data path: + +```text +../mxpic_EDA_database +``` + +The app fails fast if this folder is missing so debugging cannot silently create +or modify tracked database files. For nonstandard deployments, set: + +```text +MXPIC_DATABASE_ROOT= +``` diff --git a/backend/__pycache__/database.cpython-311.pyc b/backend/__pycache__/database.cpython-311.pyc deleted file mode 100644 index 7e1cc63..0000000 Binary files a/backend/__pycache__/database.cpython-311.pyc and /dev/null differ diff --git a/backend/__pycache__/database.cpython-39.pyc b/backend/__pycache__/database.cpython-39.pyc deleted file mode 100644 index 8379e13..0000000 Binary files a/backend/__pycache__/database.cpython-39.pyc and /dev/null differ diff --git a/backend/__pycache__/gds_builder.cpython-311.pyc b/backend/__pycache__/gds_builder.cpython-311.pyc deleted file mode 100644 index 0debd9a..0000000 Binary files a/backend/__pycache__/gds_builder.cpython-311.pyc and /dev/null differ diff --git a/backend/__pycache__/gds_builder.cpython-39.pyc b/backend/__pycache__/gds_builder.cpython-39.pyc deleted file mode 100644 index 88a94ad..0000000 Binary files a/backend/__pycache__/gds_builder.cpython-39.pyc and /dev/null differ diff --git a/backend/__pycache__/layout_preview.cpython-39.pyc b/backend/__pycache__/layout_preview.cpython-39.pyc deleted file mode 100644 index 36e98cb..0000000 Binary files a/backend/__pycache__/layout_preview.cpython-39.pyc and /dev/null differ diff --git a/backend/__pycache__/pdk_access.cpython-311.pyc b/backend/__pycache__/pdk_access.cpython-311.pyc deleted file mode 100644 index 989f490..0000000 Binary files a/backend/__pycache__/pdk_access.cpython-311.pyc and /dev/null differ diff --git a/backend/__pycache__/pdk_access.cpython-39.pyc b/backend/__pycache__/pdk_access.cpython-39.pyc deleted file mode 100644 index 4e34003..0000000 Binary files a/backend/__pycache__/pdk_access.cpython-39.pyc and /dev/null differ diff --git a/backend/__pycache__/pdk_registry.cpython-39.pyc b/backend/__pycache__/pdk_registry.cpython-39.pyc deleted file mode 100644 index 9a90baf..0000000 Binary files a/backend/__pycache__/pdk_registry.cpython-39.pyc and /dev/null differ diff --git a/backend/__pycache__/routed_layout_preview.cpython-311.pyc b/backend/__pycache__/routed_layout_preview.cpython-311.pyc deleted file mode 100644 index cf5e986..0000000 Binary files a/backend/__pycache__/routed_layout_preview.cpython-311.pyc and /dev/null differ diff --git a/backend/__pycache__/routed_layout_preview.cpython-39.pyc b/backend/__pycache__/routed_layout_preview.cpython-39.pyc deleted file mode 100644 index 53d3582..0000000 Binary files a/backend/__pycache__/routed_layout_preview.cpython-39.pyc and /dev/null differ diff --git a/backend/__pycache__/router_dependency.cpython-311.pyc b/backend/__pycache__/router_dependency.cpython-311.pyc deleted file mode 100644 index 801b363..0000000 Binary files a/backend/__pycache__/router_dependency.cpython-311.pyc and /dev/null differ diff --git a/backend/__pycache__/router_dependency.cpython-39.pyc b/backend/__pycache__/router_dependency.cpython-39.pyc deleted file mode 100644 index 348bbbf..0000000 Binary files a/backend/__pycache__/router_dependency.cpython-39.pyc and /dev/null differ diff --git a/backend/__pycache__/technology_manifest.cpython-311.pyc b/backend/__pycache__/technology_manifest.cpython-311.pyc deleted file mode 100644 index 7179b5e..0000000 Binary files a/backend/__pycache__/technology_manifest.cpython-311.pyc and /dev/null differ diff --git a/backend/__pycache__/technology_manifest.cpython-39.pyc b/backend/__pycache__/technology_manifest.cpython-39.pyc deleted file mode 100644 index e3d2424..0000000 Binary files a/backend/__pycache__/technology_manifest.cpython-39.pyc and /dev/null differ diff --git a/backend/database.py b/backend/database.py index 1ca96f8..9712e76 100644 --- a/backend/database.py +++ b/backend/database.py @@ -10,9 +10,7 @@ import os from werkzeug.security import generate_password_hash from datetime import datetime -# Store application data in the shared database folder so all backend modules -# use the same SQLite file regardless of their import path. -DB_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "database", "mxpic_data.db")) +from storage_paths import DB_FILE def connect_db(): """Open a SQLite connection with row-style access for application data queries.""" diff --git a/backend/mxpic_data.db b/backend/mxpic_data.db deleted file mode 100644 index c2a697c..0000000 Binary files a/backend/mxpic_data.db and /dev/null differ diff --git a/backend/server.py b/backend/server.py index 7b3d2f9..0b8c3be 100644 --- a/backend/server.py +++ b/backend/server.py @@ -26,6 +26,7 @@ from pdk_access import ( ) from router_dependency import RouterStackUnavailable from routed_layout_preview import create_routed_layout_svg +from storage_paths import DATABASE_ROOT, EXPORT_ROOT from technology_manifest import TechnologyManifestError, read_technology_manifest # --- Path Configurations --- @@ -38,11 +39,6 @@ REPO_ROOT = os.path.abspath(os.path.join(BASE_DIR, '..', '..')) # Component/category icons are served from backend/icons for the library panel. ICONS_DIR = os.path.join(BASE_DIR, 'icons') -# Saved project YAML, generated previews, and temporary exports live under the -# database folder so each user can have isolated project storage. -DATABASE_ROOT = os.path.abspath(os.path.join(BASE_DIR, '..', 'database')) -EXPORT_ROOT = os.path.abspath(os.path.join(DATABASE_ROOT, '_exports')) - # Flask serves the HTML/CSS/JS frontend and exposes JSON APIs for persistence, # PDK lookup, preview generation, and GDS export. @@ -586,7 +582,7 @@ def user_logs(): @app.route('/api/projects', methods=['GET']) @login_required_json def list_projects(): - """List projects stored under database//layout.""" + """List projects stored under the external runtime database root.""" root = user_layout_root() os.makedirs(root, exist_ok=True) @@ -676,7 +672,7 @@ def get_project(project_name): @app.route('/api/projects/', methods=['DELETE']) @login_required_json def delete_project(project_name): - """Delete a user's project folder under database//layout.""" + """Delete a user's project folder under the external runtime database root.""" root = project_root(project_name) layout_root = os.path.abspath(user_layout_root()) target = os.path.abspath(root) diff --git a/backend/storage_paths.py b/backend/storage_paths.py new file mode 100644 index 0000000..2034aba --- /dev/null +++ b/backend/storage_paths.py @@ -0,0 +1,49 @@ +# ----------------------------------------------------------------------------- +# Description: Runtime storage path resolution for SQLite data, saved layouts, and temporary exports. +# Inside functions: resolve_database_root +# Developer : Qin Yue @ 2026 +# Organization : OptiHK Limited +# ----------------------------------------------------------------------------- +import os + + +BACKEND_DIR = os.path.dirname(os.path.abspath(__file__)) +REPO_ROOT = os.path.abspath(os.path.join(BACKEND_DIR, "..")) +DEFAULT_DATABASE_ROOT = os.path.abspath(os.path.join(REPO_ROOT, "..", "mxpic_EDA_database")) + + +def _is_inside_repo(path: str) -> bool: + """Return True when a candidate runtime data folder lives inside this repo.""" + repo_root = os.path.normcase(REPO_ROOT) + candidate = os.path.normcase(os.path.abspath(path)) + try: + return os.path.commonpath([repo_root, candidate]) == repo_root + except ValueError: + return False + + +def resolve_database_root() -> str: + """Resolve and validate the external runtime database root.""" + configured_root = os.environ.get("MXPIC_DATABASE_ROOT", "").strip() + database_root = os.path.abspath(configured_root or DEFAULT_DATABASE_ROOT) + + if _is_inside_repo(database_root): + raise RuntimeError( + "Runtime database root must live outside the mxpic_EDA repository. " + f"Resolved path: {database_root}. Move the database beside the repo as " + "mxpic_EDA_database or set MXPIC_DATABASE_ROOT to an external path." + ) + + if not os.path.isdir(database_root): + raise RuntimeError( + "Runtime database root is missing. Move the existing database folder " + f"beside mxpic_EDA and rename it to mxpic_EDA_database, or set " + f"MXPIC_DATABASE_ROOT to the moved folder. Expected path: {database_root}" + ) + + return database_root + + +DATABASE_ROOT = resolve_database_root() +DB_FILE = os.path.join(DATABASE_ROOT, "mxpic_data.db") +EXPORT_ROOT = os.path.join(DATABASE_ROOT, "_exports") diff --git a/database/_exports/009d30aca3e44bc6bdf43b0584e549fe/mxpic_project_1.gds b/database/_exports/009d30aca3e44bc6bdf43b0584e549fe/mxpic_project_1.gds deleted file mode 100644 index bc8998c..0000000 Binary files a/database/_exports/009d30aca3e44bc6bdf43b0584e549fe/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/29af00af64d84428b19f37ddc03eec46/mxpic_project_1.gds b/database/_exports/29af00af64d84428b19f37ddc03eec46/mxpic_project_1.gds deleted file mode 100644 index d3a1188..0000000 Binary files a/database/_exports/29af00af64d84428b19f37ddc03eec46/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/2a2617c458a6447294fd56502bfb85f9/mxpic_project_1.gds b/database/_exports/2a2617c458a6447294fd56502bfb85f9/mxpic_project_1.gds deleted file mode 100644 index 3016058..0000000 Binary files a/database/_exports/2a2617c458a6447294fd56502bfb85f9/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/2c153dd7b8da4479881e75b3b1cb98a9/mxpic_project_1.gds b/database/_exports/2c153dd7b8da4479881e75b3b1cb98a9/mxpic_project_1.gds deleted file mode 100644 index e07f9ec..0000000 Binary files a/database/_exports/2c153dd7b8da4479881e75b3b1cb98a9/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/2c8f8cfc00964701ab5efb3f25e63323/mxpic_project_1.gds b/database/_exports/2c8f8cfc00964701ab5efb3f25e63323/mxpic_project_1.gds deleted file mode 100644 index e96a96f..0000000 Binary files a/database/_exports/2c8f8cfc00964701ab5efb3f25e63323/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/30072f5d25b84836bb1ca80544508ded/mxpic_project_1.gds b/database/_exports/30072f5d25b84836bb1ca80544508ded/mxpic_project_1.gds deleted file mode 100644 index de0eb3e..0000000 Binary files a/database/_exports/30072f5d25b84836bb1ca80544508ded/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/3ff6e2b43f0d43dab8e169a0b8d6c3d0/mxpic_project_1.gds b/database/_exports/3ff6e2b43f0d43dab8e169a0b8d6c3d0/mxpic_project_1.gds deleted file mode 100644 index ad6500b..0000000 Binary files a/database/_exports/3ff6e2b43f0d43dab8e169a0b8d6c3d0/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/449a329fa1d14dea85e034c9de012e09/mxpic_project_1.gds b/database/_exports/449a329fa1d14dea85e034c9de012e09/mxpic_project_1.gds deleted file mode 100644 index 6af7506..0000000 Binary files a/database/_exports/449a329fa1d14dea85e034c9de012e09/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/5ed74e6f5cb54b1eb7e1a3277bfb9834/mxpic_project_1.gds b/database/_exports/5ed74e6f5cb54b1eb7e1a3277bfb9834/mxpic_project_1.gds deleted file mode 100644 index 2ff2bf2..0000000 Binary files a/database/_exports/5ed74e6f5cb54b1eb7e1a3277bfb9834/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/5ef2a587264f41f6a8b76bdefec48d62/mxpic_project_1.gds b/database/_exports/5ef2a587264f41f6a8b76bdefec48d62/mxpic_project_1.gds deleted file mode 100644 index 9262106..0000000 Binary files a/database/_exports/5ef2a587264f41f6a8b76bdefec48d62/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/68783ecf8c704642ba4623366c49402f/mxpic_project_1.gds b/database/_exports/68783ecf8c704642ba4623366c49402f/mxpic_project_1.gds deleted file mode 100644 index 4de0fe6..0000000 Binary files a/database/_exports/68783ecf8c704642ba4623366c49402f/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/6cc901a2613e4efdad749b2eb16f121f/mxpic_project_1.gds b/database/_exports/6cc901a2613e4efdad749b2eb16f121f/mxpic_project_1.gds deleted file mode 100644 index bd92f93..0000000 Binary files a/database/_exports/6cc901a2613e4efdad749b2eb16f121f/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/6d77e66abe114ceabca364153d44ff89/mxpic_project_1.gds b/database/_exports/6d77e66abe114ceabca364153d44ff89/mxpic_project_1.gds deleted file mode 100644 index b146e61..0000000 Binary files a/database/_exports/6d77e66abe114ceabca364153d44ff89/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/6d9241698e134d6f8cd58bcc9a18ef63/mxpic_project_1.gds b/database/_exports/6d9241698e134d6f8cd58bcc9a18ef63/mxpic_project_1.gds deleted file mode 100644 index dbc5d26..0000000 Binary files a/database/_exports/6d9241698e134d6f8cd58bcc9a18ef63/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/6eef05775fa44443bcd6fe0cafc0720f/mxpic_project_1.gds b/database/_exports/6eef05775fa44443bcd6fe0cafc0720f/mxpic_project_1.gds deleted file mode 100644 index 6f61183..0000000 Binary files a/database/_exports/6eef05775fa44443bcd6fe0cafc0720f/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/741a0bab3cd24a8f9073814b57d4217e/mxpic_project_1.gds b/database/_exports/741a0bab3cd24a8f9073814b57d4217e/mxpic_project_1.gds deleted file mode 100644 index e5408f9..0000000 Binary files a/database/_exports/741a0bab3cd24a8f9073814b57d4217e/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/752665558896485a9f1def48bd481041/mxpic_project_1.gds b/database/_exports/752665558896485a9f1def48bd481041/mxpic_project_1.gds deleted file mode 100644 index 91d7f32..0000000 Binary files a/database/_exports/752665558896485a9f1def48bd481041/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/b384ef2ad08a44e8a8eec397082b360a/mxpic_project_1.gds b/database/_exports/b384ef2ad08a44e8a8eec397082b360a/mxpic_project_1.gds deleted file mode 100644 index db2f8b4..0000000 Binary files a/database/_exports/b384ef2ad08a44e8a8eec397082b360a/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/b73ed3f3e158431cb6f496c2d3a0d1af/mxpic_project_1.gds b/database/_exports/b73ed3f3e158431cb6f496c2d3a0d1af/mxpic_project_1.gds deleted file mode 100644 index 2927e40..0000000 Binary files a/database/_exports/b73ed3f3e158431cb6f496c2d3a0d1af/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/ba459cd32b6b492f82fba88d429062b2/mxpic_project_1.gds b/database/_exports/ba459cd32b6b492f82fba88d429062b2/mxpic_project_1.gds deleted file mode 100644 index b2b1294..0000000 Binary files a/database/_exports/ba459cd32b6b492f82fba88d429062b2/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/c66d1207b54d467b902797c509bdad39/mxpic_project_1.gds b/database/_exports/c66d1207b54d467b902797c509bdad39/mxpic_project_1.gds deleted file mode 100644 index 4c8d337..0000000 Binary files a/database/_exports/c66d1207b54d467b902797c509bdad39/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/c951f0317ebf4c9b903025b481290f8f/mxpic_project_1.gds b/database/_exports/c951f0317ebf4c9b903025b481290f8f/mxpic_project_1.gds deleted file mode 100644 index 2cce5b5..0000000 Binary files a/database/_exports/c951f0317ebf4c9b903025b481290f8f/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/d61ec6d8ecd74bd790e512e1196f4515/mxpic_project_1.gds b/database/_exports/d61ec6d8ecd74bd790e512e1196f4515/mxpic_project_1.gds deleted file mode 100644 index f45ea97..0000000 Binary files a/database/_exports/d61ec6d8ecd74bd790e512e1196f4515/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/e648ffaf59e343d49782770690607c60/mxpic_project_1.gds b/database/_exports/e648ffaf59e343d49782770690607c60/mxpic_project_1.gds deleted file mode 100644 index b53f9a2..0000000 Binary files a/database/_exports/e648ffaf59e343d49782770690607c60/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/e7c67c80bc78400e897ce22c2bcb178c/mxpic_project_1.gds b/database/_exports/e7c67c80bc78400e897ce22c2bcb178c/mxpic_project_1.gds deleted file mode 100644 index 41be835..0000000 Binary files a/database/_exports/e7c67c80bc78400e897ce22c2bcb178c/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/e8f94d1099c94ef7b8b3444d7577f10a/mxpic_project_1.gds b/database/_exports/e8f94d1099c94ef7b8b3444d7577f10a/mxpic_project_1.gds deleted file mode 100644 index aa4c470..0000000 Binary files a/database/_exports/e8f94d1099c94ef7b8b3444d7577f10a/mxpic_project_1.gds and /dev/null differ diff --git a/database/_exports/f4a64d4f87684b0897157fde62cb85be/mxpic_project_1.gds b/database/_exports/f4a64d4f87684b0897157fde62cb85be/mxpic_project_1.gds deleted file mode 100644 index c79fa56..0000000 Binary files a/database/_exports/f4a64d4f87684b0897157fde62cb85be/mxpic_project_1.gds and /dev/null differ diff --git a/database/admin/layout/mxpic_project_1/.project.json b/database/admin/layout/mxpic_project_1/.project.json deleted file mode 100644 index 4f868b9..0000000 --- a/database/admin/layout/mxpic_project_1/.project.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "mxpic_project_1", - "technology": "Silterra/EMO1_2ML_CU_Al_RDL" -} \ No newline at end of file diff --git a/database/admin/layout/mxpic_project_1/canvas_1.svg b/database/admin/layout/mxpic_project_1/canvas_1.svg deleted file mode 100644 index a416194..0000000 --- a/database/admin/layout/mxpic_project_1/canvas_1.svg +++ /dev/null @@ -1,293 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/database/admin/layout/mxpic_project_1/canvas_1.yml b/database/admin/layout/mxpic_project_1/canvas_1.yml deleted file mode 100644 index 17d83e6..0000000 --- a/database/admin/layout/mxpic_project_1/canvas_1.yml +++ /dev/null @@ -1,211 +0,0 @@ -# ============================================= -# mxPIC Cell/Project Definition File -# ============================================= -schema_version: "2.0.0" -kind: cell -coordinate_system: gds_y_up -canvas_size: - width: 500 - height: 600 -project: mxpic_project_1 -name: canvas_1 -type: composite -version: "1.0.0" - -# 1. External Ports (How this cell connects to the outside world) -pins: -- name: port_io1 - layer: WG_CORE - element: port - pin: io1 - x: 40.0 - y: -90.0 - angle: 180.0 - width: 0.5 -- name: port_1_io1 - layer: WG_CORE - element: port_1 - pin: io1 - x: 410.0 - y: -35.0 - angle: 0.0 - width: 0.5 -- name: port_1_io2 - layer: WG_CORE - element: port_1 - pin: io2 - x: 410.0 - y: -25.0 - angle: 0.0 - width: 0.5 -- name: port_2_io1 - layer: WG_CORE - element: port_2 - pin: io1 - x: 390.0 - y: -215.0 - angle: 0.0 - width: 0.5 -- name: port_2_io2 - layer: WG_CORE - element: port_2 - pin: io2 - x: 390.0 - y: -205.0 - angle: 0.0 - width: 0.5 - -# 2. Instances (The sub-components dropped onto this canvas) -instances: - MMI_1: - component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/multimode_interferometers/1x2MMI_1310nm_TE_Silterra_202603_ZKY_v2 - x: 130.0 - y: -90.0 - rotation: 0.0 - flip: 0 - flop: 0 - mirror: false - settings: - length: - - MMI_2: - component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/multimode_interferometers/1x2MMI_1310nm_TE_Silterra_202603_ZKY_v2 - x: 280.0 - y: -30.0 - rotation: 0.0 - flip: 0 - flop: 0 - mirror: false - settings: - length: - - MMI_3: - component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/multimode_interferometers/1x2MMI_1310nm_TE_Silterra_202603_ZKY_v2 - x: 320.1 - y: -144.7 - rotation: 0.0 - flip: 0 - flop: 0 - mirror: false - settings: - length: - -elements: - port: - type: port - x: 40.0 - y: -90.0 - angle: 180.0 - pin_number: 1 - pitch: 10 - layer: WG_CORE - width: 0.5 - description: "" - pins: - - name: port_io1 - role: io1 - port: - type: port - x: 40.0 - y: -90.0 - angle: 0.0 - pin_number: 1 - pitch: 10 - layer: WG_CORE - width: 0.5 - description: "" - pins: - - name: port_io1 - role: io1 - port_1: - type: port - x: 410.0 - y: -30.0 - angle: 180.0 - pin_number: 2 - pitch: 10 - layer: WG_CORE - width: 0.5 - description: "" - pins: - - name: port_1_io1 - role: io1 - - name: port_1_io2 - role: io2 - port_2: - type: port - x: 390.0 - y: -210.0 - angle: 180.0 - pin_number: 2 - pitch: 10 - layer: WG_CORE - width: 0.5 - description: "" - pins: - - name: port_2_io1 - role: io1 - - name: port_2_io2 - role: io2 - -# 3. Bundles (Grouped links for multi-bus/parallel routing) -bundles: - output_bus: - routing_type: euler_bend - links: - - from: MMI_1:a1 - to: port:port_io1 - xsection: strip - family: optical - width: 0.45 - radius: 10 - routing_type: euler_bend - - from: MMI_2:a1 - to: MMI_1:b1 - xsection: strip - family: optical - width: 0.45 - radius: 10 - routing_type: euler_bend - - from: MMI_3:a1 - to: MMI_1:b2 - xsection: strip - family: optical - width: 0.45 - radius: 10 - routing_type: euler_bend - - from: MMI_2:b1 - to: port_1:port_1_io1 - xsection: strip - family: optical - width: 0.45 - radius: 10 - routing_type: euler_bend - - from: MMI_2:b1 - to: port_1:port_1_io2 - xsection: strip - family: optical - width: 0.45 - radius: 10 - routing_type: euler_bend - - from: MMI_2:b2 - to: port_1:port_1_io1 - xsection: strip - family: optical - width: 0.45 - radius: 10 - routing_type: euler_bend - - from: MMI_3:b1 - to: port_2:port_2_io2 - xsection: strip - family: optical - width: 0.45 - radius: 10 - routing_type: euler_bend - - from: MMI_3:b2 - to: port_2:port_2_io1 - xsection: strip - family: optical - width: 0.45 - radius: 10 - routing_type: euler_bend \ No newline at end of file diff --git a/database/admin/layout/mxpic_project_1/mxpic_project_1.svg b/database/admin/layout/mxpic_project_1/mxpic_project_1.svg deleted file mode 100644 index 0bac00e..0000000 --- a/database/admin/layout/mxpic_project_1/mxpic_project_1.svg +++ /dev/null @@ -1,619 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Parameters: -x = 0.0 -y = 4.475 -a = 180.0 -width = 0.7 -name = a1 -Parameters: -x = 0.0 -y = -4.475 -a = 180.0 -width = 0.7 -name = a2 -Parameters: -x = 1660.0 -y = 4.475 -a = 360.0 -width = 0.7 -name = b1 -Parameters: -x = 1660.0 -y = -4.475 -a = 360.0 -width = 0.7 -name = b2 -Parameters: -x = 1660.0 -y = 25.0 -a = 0.0 -width = 5 -name = pin_p -Parameters: -x = 1660.0 -y = 55.0 -a = 0.0 -width = 5 -name = pin_n -Parameters: -x = 1660.0 -y = -25.0 -a = 0.0 -width = 5 -name = ht_s -Parameters: -x = 1660.0 -y = -55.0 -a = 0.0 -width = 5 -name = ht_g - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/database/admin/layout/mxpic_project_1/mxpic_project_1.yml b/database/admin/layout/mxpic_project_1/mxpic_project_1.yml deleted file mode 100644 index 0607770..0000000 --- a/database/admin/layout/mxpic_project_1/mxpic_project_1.yml +++ /dev/null @@ -1,58 +0,0 @@ -# ============================================= -# mxPIC Cell/Project Definition File -# ============================================= -schema_version: "2.0.0" -kind: cell -coordinate_system: gds_y_up -canvas_size: - width: 5000 - height: 5000 -project: mxpic_project_1 -name: mxpic_project_1 -type: project -version: "1.0.0" - -# 1. External Ports (How this cell connects to the outside world) -pins: -- name: port_io1 - layer: WG_CORE - element: port - pin: io1 - x: 50.0 - y: -150.0 - angle: 180.0 - width: 0.5 - -# 2. Instances (The sub-components dropped onto this canvas) -instances: - MZM_1: - component: Silterra/EMO1_2ML_CU_Al_RDL/composites/Mach_Zender_modulators/MZI_SiN400_Si220_PIN_mod_1310_L1300_QY_202603 - x: 222.2 - y: -473.8 - rotation: 0.0 - flip: 0 - flop: 0 - mirror: false - settings: - length: - -elements: - port: - type: port - x: 50.0 - y: -150.0 - angle: 0.0 - pin_number: 1 - pitch: 10 - layer: WG_CORE - width: 0.5 - description: "" - pins: - - name: port_io1 - role: io1 - -# 3. Bundles (Grouped links for multi-bus/parallel routing) -bundles: - output_bus: - routing_type: euler_bend - links: diff --git a/database/engineer/layout/mxpic_project_1/.project.json b/database/engineer/layout/mxpic_project_1/.project.json deleted file mode 100644 index 4f868b9..0000000 --- a/database/engineer/layout/mxpic_project_1/.project.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "mxpic_project_1", - "technology": "Silterra/EMO1_2ML_CU_Al_RDL" -} \ No newline at end of file diff --git a/database/engineer/layout/mxpic_project_1/canvas_1.svg b/database/engineer/layout/mxpic_project_1/canvas_1.svg deleted file mode 100644 index da409e3..0000000 --- a/database/engineer/layout/mxpic_project_1/canvas_1.svg +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/database/engineer/layout/mxpic_project_1/canvas_1.yml b/database/engineer/layout/mxpic_project_1/canvas_1.yml deleted file mode 100644 index f890271..0000000 --- a/database/engineer/layout/mxpic_project_1/canvas_1.yml +++ /dev/null @@ -1,100 +0,0 @@ -# ============================================= -# mxPIC Cell/Project Definition File -# ============================================= -schema_version: "2.0.0" -kind: cell -coordinate_system: gds_y_up -canvas_size: - width: 5000 - height: 5000 -project: mxpic_project_1 -name: canvas_1 -type: composite -version: "1.0.0" - -# 1. External Ports (How this cell connects to the outside world) -pins: -- name: port_io1 - layer: WG_CORE - element: port - pin: io1 - x: 50.0 - y: -150.0 - angle: 180.0 - width: 0.5 - -# 2. Instances (The sub-components dropped onto this canvas) -instances: - waveguide_1: - component: waveguide - x: 686.5 - y: -1027.9 - rotation: 0.0 - flip: 0 - flop: 0 - mirror: false - settings: - length: 100 - width: 0.5 - xsection: "strip" - - circle_1: - component: circle - x: 877.2 - y: -1093.7 - rotation: 0.0 - flip: 0 - flop: 0 - mirror: false - settings: - radius: 10 - width: 0.5 - xsection: "strip" - - waveguide_2: - component: waveguide - x: 858.0 - y: -1029.6 - rotation: 0.0 - flip: 0 - flop: 0 - mirror: false - settings: - length: 100 - width: 0.5 - xsection: "strip" - -elements: - port: - type: port - x: 50.0 - y: -150.0 - angle: 0.0 - pin_number: 1 - pitch: 10 - layer: WG_CORE - width: 0.5 - description: "" - pins: - - name: port_io1 - role: io1 - -# 3. Bundles (Grouped links for multi-bus/parallel routing) -bundles: - output_bus: - routing_type: euler_bend - links: - - from: waveguide_1:b1 - to: waveguide_2:a1 - xsection: strip - family: optical - width: 0.5 - radius: 10 - routing_type: euler_bend - - from: waveguide_2:b1 - to: circle_1:a1 - xsection: strip - family: optical - width: 0.5 - radius: 10 - routing_type: euler_bend \ No newline at end of file diff --git a/database/engineer/layout/mxpic_project_1/canvas_2.svg b/database/engineer/layout/mxpic_project_1/canvas_2.svg deleted file mode 100644 index 30ca134..0000000 --- a/database/engineer/layout/mxpic_project_1/canvas_2.svg +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/database/engineer/layout/mxpic_project_1/canvas_2.yml b/database/engineer/layout/mxpic_project_1/canvas_2.yml deleted file mode 100644 index 6d415b5..0000000 --- a/database/engineer/layout/mxpic_project_1/canvas_2.yml +++ /dev/null @@ -1,136 +0,0 @@ -# ============================================= -# mxPIC Cell/Project Definition File -# ============================================= -schema_version: "2.0.0" -kind: cell -coordinate_system: gds_y_up -canvas_size: - width: 5000 - height: 5000 -project: mxpic_project_1 -name: canvas_2 -type: composite -version: "1.0.0" - -# 1. External Ports (How this cell connects to the outside world) -pins: -- name: port_io1 - layer: WG_CORE - element: port - pin: io1 - x: 50.0 - y: -150.0 - angle: 0.0 - width: 0.5 -- name: port_2_io1 - layer: WG_CORE - element: port_2 - pin: io1 - x: 1442.1 - y: -1470.0 - angle: 180.0 - width: 10 -- name: port_3_io1 - layer: WG_CORE - element: port_3 - pin: io1 - x: 2024.3 - y: -1609.0 - angle: 180.0 - width: 0.5 - -# 2. Instances (The sub-components dropped onto this canvas) -instances: - waveguide_3: - component: waveguide - x: 1581.0 - y: -1633.5 - rotation: 0.0 - flip: 0 - flop: 0 - mirror: false - settings: - length: 100 - width: 15 - xsection: "strip" - -elements: - port: - type: port - x: 50.0 - y: -150.0 - angle: 0.0 - pin_number: 1 - pitch: 10 - layer: WG_CORE - width: 0.5 - description: "" - pins: - - name: port_io1 - role: io1 - port: - type: port - x: 50.0 - y: -150.0 - angle: 180.0 - pin_number: 1 - pitch: 10 - layer: WG_CORE - width: 0.5 - description: "" - pins: - - name: port_io1 - role: io1 - port_2: - type: port - x: 1442.1 - y: -1470.0 - angle: 0.0 - pin_number: 1 - pitch: 10 - layer: WG_CORE - width: 10 - description: "" - pins: - - name: port_2_io1 - role: io1 - port_3: - type: port - x: 2024.3 - y: -1609.0 - angle: 0.0 - pin_number: 1 - pitch: 10 - layer: WG_CORE - width: 0.5 - description: "" - pins: - - name: port_3_io1 - role: io1 - -# 3. Bundles (Grouped links for multi-bus/parallel routing) -bundles: - output_bus: - routing_type: euler_bend - links: - - from: waveguide_3:a1 - to: port_2:port_2_io1 - xsection: strip - family: optical - width: 15 - radius: 10 - routing_type: euler_bend - - from: waveguide_3:b1 - to: port_2:port_2_io1 - xsection: strip - family: optical - width: 15 - radius: 10 - routing_type: euler_bend - - from: port_3:port_3_io1 - to: port_2:port_2_io1 - xsection: strip - family: optical - width: 0.5 - radius: 10 - routing_type: euler_bend \ No newline at end of file diff --git a/database/engineer/layout/mxpic_project_1/mxpic_project_1.svg b/database/engineer/layout/mxpic_project_1/mxpic_project_1.svg deleted file mode 100644 index ddcf788..0000000 --- a/database/engineer/layout/mxpic_project_1/mxpic_project_1.svg +++ /dev/null @@ -1,158 +0,0 @@ - -<<<<<<< HEAD - - - - - - - - -a1 -b1 -b2 -a0 -b0 - - - - - - -a1 -b1 -b2 -a0 -b0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -======= - - - - - - - - - - - - - -a1 -a2 -b1 -b2 -pin_p -pin_n -ht_s -ht_g -a0 -b0 - - - - - - - -a0 -b0 -a1 -b1 - - - - - -a1 -b1 -a0 -b0 - - - - - - -a1 -b1 -b2 -a0 -b0 - - - - - - - - - ->>>>>>> jingwen_main - - \ No newline at end of file diff --git a/database/engineer/layout/mxpic_project_1/mxpic_project_1.yml b/database/engineer/layout/mxpic_project_1/mxpic_project_1.yml deleted file mode 100644 index 6b6986a..0000000 --- a/database/engineer/layout/mxpic_project_1/mxpic_project_1.yml +++ /dev/null @@ -1,169 +0,0 @@ -# ============================================= -# mxPIC Cell/Project Definition File -# ============================================= -schema_version: "2.0.0" -kind: cell -coordinate_system: gds_y_up -canvas_size: - width: 5000 - height: 5000 -project: mxpic_project_1 -name: mxpic_project_1 -type: project -version: "1.0.0" - -# 1. External Ports (How this cell connects to the outside world) -<<<<<<< HEAD -ports: [] - -# 2. Instances (The sub-components dropped onto this canvas) -instances: - MMI_1: - component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/multimode_interferometers/1x2MMI_1310nm_TE_Silterra_202603_ZKY_v2 - x: 1511.5 - y: -2531.5 -======= -pins: -- name: port_1_io1 - layer: WG_CORE - element: port_1 - pin: io1 - x: 1699.6 - y: -1844.2 - angle: 180.0 - width: 0.5 - -# 2. Instances (The sub-components dropped onto this canvas) -instances: - circle_1: - component: circle - x: 1877.6 - y: -1816.7 - rotation: 90.0 - flip: 0 - flop: 0 - mirror: false - settings: - radius: 10 - width: 0.5 - xsection: "strip" - - BD_1: - component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/bendings/SiN_EUB_1310_H400_w2500_L45_QY_202604 - x: 1926.2 - y: -1813.9 - rotation: 90.0 - flip: 0 - flop: 0 - mirror: false - settings: - length: - - DC_1: - component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/directional_couplers/DC_SiN400_99_1_1310_jyh_quantex_202603 - x: 1766.5 - y: -1945.3 - rotation: 0.0 - flip: 0 - flop: 0 - mirror: false - settings: - length: - - MZM_1: - component: Silterra/EMO1_2ML_CU_Al_RDL/composites/Mach_Zender_modulators/MZI_SiN400_Si220_PIN_mod_1310_L1300_QY_202603 - x: 1341.6 - y: -2103.8 - rotation: 0.0 - flip: 0 - flop: 0 - mirror: false - settings: - length: - - phase_shifter_1: - component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/phase_shifters/HT_150R_SiPPP_L500_100OHM_DUMMY_QY_202604 - x: 2695.0 - y: -2275.0 - rotation: 90.0 - flip: 0 - flop: 0 - mirror: false - settings: - length: - - MMI_1: - component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/multimode_interferometers/1x2MMI_1310nm_TE_Silterra_202603_ZKY_v2 - x: 2849.0 - y: -1988.6 ->>>>>>> jingwen_main - rotation: 0.0 - flip: 0 - flop: 0 - mirror: false - settings: - length: - -<<<<<<< HEAD - MMI_2: - component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/multimode_interferometers/1x2MMI_1310nm_TE_Silterra_202603_ZKY_v2 - x: 1716.4 - y: -2293.8 -======= - DC_2: - component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/directional_couplers/DC_SiN400_99_1_1310_jyh_quantex_202603 - x: 2656.9 - y: -1992.8 ->>>>>>> jingwen_main - rotation: 0.0 - flip: 0 - flop: 0 - mirror: false - settings: - length: - -<<<<<<< HEAD -elements: {} -======= - PD_1: - component: Silterra/EMO1_2ML_CU_Al_RDL/primitives/photodetectors/PD_1310_Monitor_Si220_Ge500_NPN_XHN_202604 - x: 3151.7 - y: -2032.1 - rotation: 0.0 - flip: 0 - flop: 0 - mirror: false - settings: - length: - -elements: - port_1: - type: port - x: 1699.6 - y: -1844.2 - angle: 0.0 - pin_number: 1 - pitch: 10 - layer: WG_CORE - width: 0.5 - description: "" - pins: - - name: port_1_io1 - role: io1 ->>>>>>> jingwen_main - -# 3. Bundles (Grouped links for multi-bus/parallel routing) -bundles: - output_bus: - routing_type: euler_bend - links: -<<<<<<< HEAD - - from: MMI_2:a1 - to: MMI_1:b2 - xsection: strip - family: optical - width: 0.45 - radius: 10 - routing_type: euler_bend -======= ->>>>>>> jingwen_main diff --git a/database/mxpic_data.db b/database/mxpic_data.db deleted file mode 100644 index d2b26c6..0000000 Binary files a/database/mxpic_data.db and /dev/null differ diff --git a/develop_plan/findings.md b/develop_plan/findings.md new file mode 100644 index 0000000..c5a5b25 --- /dev/null +++ b/develop_plan/findings.md @@ -0,0 +1,108 @@ +# Project Findings + +## Repository Inventory +- Static/frontend files are under `frontend/`: `login.html`, `dashboard.html`, `canvas.html`, and `canvas-helpers.js`. +- Backend files are under `backend/`: `server.py`, `database.py`, `pdk_access.py`, `technology_manifest.py`, `gds_builder.py`, routing helpers, icons, and `directories.yaml`. +- Persistent data appears under `database/`, including `mxpic_data.db`, saved layout YAML/SVG files, and generated `_exports/*.gds`. +- Tests are JavaScript static/unit-style tests under `tests/`. +- Project docs exist under `docs/`, including intranet deployment, GDS/SVG generation, and PDK technology loading notes. +- A checked saved layout example at `database/engineer/layout/mxpic_project_1/mxpic_project_1.yml` contains unresolved merge-conflict markers, so at least some local saved data may be invalid until cleaned. +- Conflict-marker search also found real markers in `database/engineer/layout/mxpic_project_1/mxpic_project_1.svg`, `tests/layout-ui-wiring.test.js`, and `tests/layout-backend-static.test.js`. +- `backend/directories.yaml` is a legacy/declarative directory category file with PDK-style categories; the active docs/source show library scanning is now driven by the role-scoped PDK filesystem. + +## Saved Layout YAML Shape +- Saved layout YAML uses schema version `2.0.0`, `kind: cell`, `coordinate_system: gds_y_up`, `canvas_size`, `project`, `name`, `type`, and `version`. +- Modern YAML uses `pins`, `instances`, `elements`, and `bundles`. +- `instances` can reference basic components like `circle`, generated/forge components, other project cells, or PDK paths such as `Silterra//primitives/...`. +- `bundles.output_bus.links` stores routed connections with source/target pins and route settings. +- Both checked `.project.json` metadata files (`admin` and `engineer`) select technology `Silterra/EMO1_2ML_CU_Al_RDL`. + +## README / Deployment +- The project is `mxpic_EDA`, an EDA layout tool for OptiHK. +- Runtime requirement explicitly listed in README is Flask. +- The application can launch login, dashboard, canvas editing, YAML generation, and PDK browsing without build-time router dependencies. +- Build/export actions require `mxpic_router` and Nazca; if `mxpic_forge.Route` is unavailable, routing falls back to Nazca interconnects. +- SVG preview generation for routed/build output requires `gdstk`. +- Intranet server is started with `run_intranet_server.ps1` and listens on `0.0.0.0:3000` by default. +- LAN users browse to `http://:3000`; firewall must allow inbound TCP `3000`. +- Default local accounts are `admin / 123456` and `engineer / 123456`. +- User project files are stored under `database//layout`. +- Important env vars include `MXPIC_SECRET_KEY`, `MXPIC_HOST`, `MXPIC_PORT`, `MXPIC_DEBUG`, `MXPIC_COOKIE_SECURE`, `MXPIC_PDK_PUBLIC_ROOT`, and `MXPIC_PDK_ATLAS_ROOT`. +- Public/developer PDK roots default to `../opt_pdk_public/foundries`; manager/atlas roots default to `../opt_pdk_atlas/foundries`. +- `run_intranet_server.ps1` sets default `MXPIC_SECRET_KEY` if absent, sets `MXPIC_HOST=0.0.0.0`, `MXPIC_PORT=3000`, `MXPIC_DEBUG=0`, then runs `python backend\server.py`. +- `backend/server.py` initializes the local SQLite database when the server process starts. +- Flask runs threaded on the configured host and port. + +## GDS / SVG Generation +- `Build Layout` serializes the active canvas page into layout YAML, posts it to `/api/save-layout`, writes `database//layout//.yml`, writes optional route sidecar data, then calls router-backed SVG preview generation. +- Routed SVG preview uses `backend/routed_layout_preview.py`, which delegates to `mxpic_router.build_project_gds`, reads the temporary GDS with `gdstk`, and writes `.svg`. +- `Build GDS` posts to `/api/build-gds` with only the project name. It does not automatically serialize unsaved in-memory canvas state first. +- Final GDS export reads existing saved project YAML files, calls `backend/gds_builder.py`, delegates to `mxpic_router`, writes `database/_exports//.gds`, returns a download URL, then cleans up the export folder after response close. +- Saved layout files are under `database//layout//`. +- External build dependencies are lazy: normal web usage can work without router stack, while preview/build actions require `mxpic_router`, Nazca, and sometimes `gdstk`. + +## PDK / Technology / Xsections +- PDK components, technology manifests, and GDS assets all come from role-scoped PDK roots. +- Dashboard loads available technologies from `/api/technologies`, scanning `///technology.yml`. +- Project creation stores selected technology in `database//layout//.project.json`. +- Canvas loads project metadata from `/api/projects/`, then loads `/api/technologies///manifest`. +- `technology.yml` supplies layer mappings, routing type options, defaults, and xsection definitions such as `strip`, `rib_low`, `metal_1`, and `metal_2`. +- Canvas route editing uses the active technology manifest to populate xsection choices and route defaults. +- Saved YAML stores component paths and per-link route data such as `xsection`, `family`, `width`, `radius`, and `routing_type`. +- Build-time router applies `technology.yml` to Nazca layers/xsections before resolving PDK assets and routing links. + +## Backend Route Surface +- `backend/server.py` serves `/`, `/dashboard`, `/canvas`, `/canvas-helpers.js`, and `/logout`. +- Login endpoint is `POST /login`. +- Health check endpoint is `/api/health`. +- Account/profile endpoints include `/api/profile`, `/api/profile/password`, and `/api/logs`. +- Project endpoints include listing/creating `/api/projects`, reading/deleting `/api/projects/`, cell rename/delete under `/api/projects//cells/`, and `/api/save-layout`. +- Build/export endpoints include `/api/build-gds`, `/api/exports//`, and `/api/projects//gds/`. +- PDK/technology endpoints include `/api/technologies`, `/api/technologies///manifest`, `/api/library`, `/api/component/`, `/api/component//image`, and `/api/icon/`. +- Project listing treats each `.yml`/`.yaml` inside a project folder as one saved cell/canvas. +- Project creation sanitizes the requested name, adds a numeric suffix if needed, creates an initial project folder, writes `.project.json`, and logs `project.create`. +- `/api/save-layout` accepts `project`, `cell`, `content`, and optional `preview` flag. +- `/api/library` rebuilds the component tree on each request so project technology and user role are reflected immediately. + +## Frontend Page Flow +- `frontend/login.html` renders a login form that submits `POST /login` and then moves authenticated users into the dashboard. +- `frontend/dashboard.html` loads recent logs from `/api/logs`, profile data from `/api/profile`, projects from `/api/projects`, and technology choices from `/api/technologies`. +- Opening a project navigates to `/canvas?project=`. +- Creating a project posts `{ name, technology }` to `/api/projects`. +- Dashboard also supports deleting projects, updating occupation, and changing password through backend APIs. +- `frontend/canvas.html` loads project metadata/cells from `/api/projects/`, then loads the selected technology manifest. +- Canvas loads the component library with `/api/library?project=`, component metadata from `/api/component/?project=`, and component images from `/api/component//image?project=`. +- Canvas save/build controls call `/api/save-layout` and `/api/build-gds`. +- Dashboard `openProject(name)` navigates directly to `/canvas?project=`. +- Canvas `loadTechnologyManifest` falls back to `FALLBACK_TECHNOLOGY_MANIFEST` when the saved technology is missing/invalid. +- Canvas `fetchLibrary` is project-scoped, so the visible library follows the selected project technology. +- Canvas source comments define the control split: + - `handleBuildLayout`: save active page, generate preview assets, show preview tab. + - `handleSaveProjectLayouts`: save YAML for every editable page without opening previews. + - `handleBuildGds`: build project GDS through the backend and trigger download. + +## Database +- `backend/database.py` uses SQLite at `database/mxpic_data.db`. +- Tables: `users` and `user_logs`. +- User records include password hash, creation date, credits, occupation, and `user_group`. +- Database migrations add missing columns to older local SQLite files. +- Default account roles are `admin -> manager`, `engineer -> developers`, and ordinary users default to `user`. +- Audit logs record user action, project/cell context, detail, IP address, and UTC timestamp. + +## PDK Access and Build Helpers +- `backend/pdk_access.py` defines supported user groups: `manager`, `developers`, and `user`. +- Managers resolve to `MXPIC_PDK_ATLAS_ROOT` or `opt_pdk_atlas/foundries`; developers/users resolve to `MXPIC_PDK_PUBLIC_ROOT` or `opt_pdk_public/foundries`. +- Only managers prefer full component GDS assets; other roles use public/black-box style assets. +- Temporary GDS exports are created in UUID folders and old export folders are cleaned up after an age threshold. +- `backend/gds_builder.py` validates that saved cell YAML files exist, then delegates all final GDS work to `mxpic_router.build_project_gds`. +- Local GDS building is not implemented as a fallback in this repository. + +## Tests +- Tests are JavaScript assertion scripts in `tests/`. +- The test suite heavily checks static frontend/backend integration contracts, such as route existence, API strings, layout/GDS wiring, technology manifest loading, and PDK access behavior. +- `tests/canvas-helpers.test.js` directly imports `frontend/canvas-helpers.js` and checks handle placement, YAML serialization, route defaults, element ports, route YAML, and route crossing helpers. +- Several tests intentionally assert that legacy local preview/registry modules are absent and that the router-backed preview/GDS path is present. +- Current checked test files include unresolved conflict markers in at least two files, so `node` test execution may fail before assertions run unless those files are cleaned. + +## Open Questions +- None remaining for the requested project usage/workflow summary. diff --git a/develop_plan/progress.md b/develop_plan/progress.md new file mode 100644 index 0000000..7482d84 --- /dev/null +++ b/develop_plan/progress.md @@ -0,0 +1,50 @@ +# Project Understanding Progress + +## Session Log +- Started project read-through on 2026-06-08. +- Loaded requested `planning-with-files` skill and project-analysis guidance. +- Collected initial file inventory with `rg --files`. +- Created `develop_plan` planning notes. +- Read `README.md` and `docs/INTRANET_DEPLOYMENT.md`. +- Read `docs/GDS_SVG_GENERATION_LOGIC.md` and `docs/PDK_TECHNOLOGY_XSECTION_LOADING.md`. +- Listed `backend/server.py` route/function signatures. +- Read `backend/database.py`. +- Read `backend/pdk_access.py` and `backend/gds_builder.py`. +- Read `run_intranet_server.ps1` and backend startup/config references. +- Inspected login/dashboard and canvas frontend API wiring. +- Read dashboard and canvas handler context around project open, technology load, library load, save, preview, and GDS build. +- Read backend handler context and test structure. +- Read a saved engineer project YAML example and `backend/directories.yaml`. +- Searched for conflict markers and read admin/engineer `.project.json` metadata files. +- Wrote `develop_plan/project_understanding.md`. + +## Commands / Checks +- `rg --files` succeeded with escalated approval after sandbox spawn failure. +- `Get-Content -Raw README.md` succeeded. +- `Get-Content -Raw docs\INTRANET_DEPLOYMENT.md` succeeded. +- `Get-Content -Raw docs\GDS_SVG_GENERATION_LOGIC.md` succeeded. +- `Get-Content -Raw docs\PDK_TECHNOLOGY_XSECTION_LOADING.md` succeeded. +- `rg "@app\\.route|def " backend\server.py` succeeded. +- `Get-Content -Raw backend\database.py` succeeded. +- `Get-Content -Raw backend\pdk_access.py` succeeded. +- `Get-Content -Raw backend\gds_builder.py` succeeded. +- `Get-Content -Raw run_intranet_server.ps1` succeeded. +- `rg -n "app.run|MXPIC_HOST|MXPIC_PORT|MXPIC_DEBUG|SECRET_KEY|init_db|database" backend\server.py` succeeded. +- `rg -n "fetch\\(|window\\.location|..." frontend\login.html frontend\dashboard.html` succeeded. +- `rg -n "fetch\\(|handleBuildLayout|handleBuildGds|..." frontend\canvas.html frontend\canvas-helpers.js` succeeded. +- `rg -n -C 4 "function openProject|..." frontend\dashboard.html` succeeded. +- `rg -n -C 5 "const loadProject|..." frontend\canvas.html` succeeded. +- `rg -n -C 8 "def login|def list_projects|..." backend\server.py` succeeded. +- `rg -n "node:test|assert|..." tests` succeeded. +- `Get-Content -Raw database\engineer\layout\mxpic_project_1\mxpic_project_1.yml` succeeded. +- `Get-Content -Raw backend\directories.yaml` succeeded. +- `rg -n "<<<<<<<|=======|>>>>>>>"` succeeded. +- `rg --files -g .project.json -g !database\_exports` succeeded. +- `Get-Content -Raw database\admin\layout\mxpic_project_1\.project.json` succeeded. +- `Get-Content -Raw database\engineer\layout\mxpic_project_1\.project.json` succeeded. + +## Files Created / Modified +- Created `develop_plan/task_plan.md`. +- Created `develop_plan/findings.md`. +- Created `develop_plan/progress.md`. +- Created `develop_plan/project_understanding.md`. diff --git a/develop_plan/project_understanding.md b/develop_plan/project_understanding.md new file mode 100644 index 0000000..306817c --- /dev/null +++ b/develop_plan/project_understanding.md @@ -0,0 +1,333 @@ +# mxpic_EDA Project Understanding + +## Purpose + +`mxpic_EDA` is a local/intranet EDA web application for creating photonic integrated circuit layout projects. It combines: + +- A Flask backend for authentication, project APIs, PDK browsing, layout persistence, preview generation, and GDS export. +- Static frontend pages for login, dashboard, and canvas editing. +- SQLite account/audit storage plus filesystem-based project layout storage. +- External build-time tooling (`mxpic_router`, Nazca, and sometimes `gdstk`) for routed SVG preview and final GDS generation. + +The project is designed so normal login, dashboard, canvas editing, YAML generation, and PDK browsing can run without importing the router stack. Build actions load those heavier dependencies only when needed. + +## Main Entry Points + +### Start the App + +The intended intranet startup path is: + +```powershell +.\run_intranet_server.ps1 +``` + +That script sets: + +- `MXPIC_HOST=0.0.0.0` +- `MXPIC_PORT=3000` +- `MXPIC_DEBUG=0` +- a fallback `MXPIC_SECRET_KEY` if none is set + +Then it runs: + +```powershell +python backend\server.py +``` + +The server listens on: + +```text +http://:3000 +``` + +Default local accounts are: + +```text +admin / 123456 +engineer / 123456 +``` + +`admin` is a manager account. `engineer` is a developer account. + +## Repository Structure + +```text +backend/ + server.py Flask app, routes, project/layout APIs + database.py SQLite initialization, users, profiles, audit logs + pdk_access.py Role-aware PDK root selection and export helpers + gds_builder.py Final GDS wrapper around mxpic_router + routed_layout_preview.py SVG preview generation via temporary routed GDS + router_dependency.py Lazy build-time dependency validation + technology_manifest.py technology.yml loading/validation + icons/ Category icons served by backend + +frontend/ + login.html Login page + dashboard.html Project/account dashboard + canvas.html Main layout editor + canvas-helpers.js Canvas/YAML/route helper functions and tests target + +database/ + mxpic_data.db SQLite app database + /layout/... Saved project metadata, YAML cells, SVG previews + _exports//... Temporary generated GDS downloads + +docs/ + INTRANET_DEPLOYMENT.md + GDS_SVG_GENERATION_LOGIC.md + PDK_TECHNOLOGY_XSECTION_LOADING.md + +tests/ + JavaScript assertion tests for static wiring and canvas helpers +``` + +## User Workflow + +1. User opens `/`. +2. If not logged in, Flask serves `frontend/login.html`. +3. Login form posts credentials to `POST /login`. +4. On success, the session stores user id, username, and user group. +5. User lands on `/dashboard`. +6. Dashboard loads: + - `/api/profile` + - `/api/logs` + - `/api/projects` + - `/api/technologies` +7. User creates or opens a project. +8. Creating a project posts `{ name, technology }` to `POST /api/projects`. +9. Opening a project navigates to `/canvas?project=`. +10. Canvas loads project data from `/api/projects/`. +11. Canvas loads the selected `technology.yml` manifest from `/api/technologies///manifest`. +12. Canvas loads the project-scoped PDK library from `/api/library?project=`. +13. User places components, elements, pins, and routes. +14. Save or Build Layout writes YAML to disk through `/api/save-layout`. +15. Build Layout also generates and opens an SVG preview. +16. Build GDS calls `/api/build-gds` and downloads the generated GDS. + +## Project and Data Model + +Each user's projects live under: + +```text +database//layout// +``` + +Project metadata is stored in: + +```text +database//layout//.project.json +``` + +Example: + +```json +{ + "name": "mxpic_project_1", + "technology": "Silterra/EMO1_2ML_CU_Al_RDL" +} +``` + +Saved cells are YAML files: + +```text +database//layout//.yml +``` + +Generated previews are SVG files: + +```text +database//layout//.svg +``` + +Modern saved layout YAML contains: + +- `schema_version` +- `kind` +- `coordinate_system` +- `canvas_size` +- `project` +- `name` +- `type` +- `version` +- `pins` +- `instances` +- `elements` +- `bundles` + +`instances` reference basic components, forge/generated components, other project cells, or PDK component paths. `bundles` store routed links and route settings such as `xsection`, `family`, `width`, `radius`, and `routing_type`. + +## PDK and Technology Workflow + +The active PDK root is chosen by user role: + +- `manager`: `MXPIC_PDK_ATLAS_ROOT` or `opt_pdk_atlas/foundries` +- `developers` and `user`: `MXPIC_PDK_PUBLIC_ROOT` or `opt_pdk_public/foundries` + +The dashboard lists available technologies by scanning: + +```text +///technology.yml +``` + +The selected technology is saved in `.project.json`. + +Canvas then uses that selected technology to: + +- Load route defaults and xsections from `technology.yml`. +- Scope the component library browser to the chosen foundry/technology. +- Save component paths that can later resolve under the base role PDK root. + +At build time, the router receives the active PDK root and the selected project's technology manifest path. The router applies technology layers/xsections to Nazca before resolving PDK assets and routing links. + +## Build Layout vs Save vs Build GDS + +### Save + +The canvas "Save" path calls `handleSaveProjectLayouts`. It writes YAML for every editable project/cell page to `/api/save-layout` with preview disabled. It is for persistence, not preview. + +### Build Layout + +The canvas "Build Layout" path: + +1. Validates route crossings. +2. Serializes the active page to YAML. +3. Posts to `/api/save-layout`. +4. Backend writes `.yml`. +5. Backend writes route sidecar data when available. +6. Backend calls `routed_layout_preview.py`. +7. `routed_layout_preview.py` calls `mxpic_router.build_project_gds`. +8. The temporary routed GDS is converted to `.svg` with `gdstk`. +9. Frontend opens the SVG preview tab. + +### Build GDS + +The canvas "Build GDS" path: + +1. Validates route crossings across editable pages. +2. Posts `{ project }` to `/api/build-gds`. +3. Backend reads saved YAML files already on disk. +4. Backend creates `database/_exports//.gds`. +5. `backend/gds_builder.py` delegates to `mxpic_router.build_project_gds`. +6. Backend returns `download_url`. +7. Frontend triggers a browser download. +8. Backend removes the temporary export folder after serving the file. + +Important: Build GDS does not serialize unsaved in-memory canvas state first. Users should Save or Build Layout before Build GDS if they want latest canvas edits included. + +## Backend API Map + +Primary pages: + +- `GET /` +- `POST /login` +- `GET /dashboard` +- `GET /canvas` +- `GET /canvas-helpers.js` +- `GET /logout` + +Account and activity: + +- `GET /api/health` +- `GET/PATCH /api/profile` +- `POST /api/profile/password` +- `GET/POST /api/logs` + +Projects and cells: + +- `GET /api/projects` +- `POST /api/projects` +- `GET /api/projects/` +- `DELETE /api/projects/` +- `PATCH/DELETE /api/projects//cells/` +- `POST /api/save-layout` +- `GET /api/projects//cells//layout.svg` + +Build/export: + +- `POST /api/build-gds` +- `GET /api/exports//` +- `GET /api/projects//gds/` + +PDK/technology/library: + +- `GET /api/technologies` +- `GET /api/technologies///manifest` +- `GET /api/library` +- `GET /api/component/` +- `GET /api/component//image` +- `GET /api/icon/` + +## Persistence and Accounts + +SQLite database: + +```text +database/mxpic_data.db +``` + +Tables observed: + +- `users` +- `user_logs` + +The backend initializes the database on startup. It also performs lightweight migrations for profile, credit, occupation, and group fields. + +User groups affect PDK access: + +- `manager` can use atlas/private PDK roots and prefers full GDS assets. +- `developers` and `user` use the public PDK roots. + +Audit logs record user actions with project/cell context, details, IP address, and UTC timestamp. + +## Tests + +Tests are JavaScript assertion scripts under `tests/`. + +The suite mostly checks integration contracts by reading source files, including: + +- API route strings and handler wiring. +- Build Layout and Build GDS frontend/backend wiring. +- Removal of legacy local preview/PDK registry modules. +- Router-backed GDS and SVG preview paths. +- Technology manifest and PDK access behavior. +- Canvas helper behavior such as pin/handle placement, YAML serialization, route defaults, route YAML, element ports, and route crossing checks. + +Likely command: + +```powershell +node --test tests +``` + +## Current Repository State Notes + +This checkout contains unresolved merge-conflict markers in some tracked files: + +- `database/engineer/layout/mxpic_project_1/mxpic_project_1.yml` +- `database/engineer/layout/mxpic_project_1/mxpic_project_1.svg` +- `tests/layout-ui-wiring.test.js` +- `tests/layout-backend-static.test.js` + +That means some checked sample data may not parse as YAML/SVG, and the test suite may fail before reaching assertions until those files are cleaned. + +The checked admin and engineer project metadata both select: + +```text +Silterra/EMO1_2ML_CU_Al_RDL +``` + +## Mental Model + +Think of this app as: + +```text +Flask session/account layer + -> role-scoped PDK/technology selection + -> dashboard project metadata + -> canvas layout editing + -> YAML saved on disk + -> mxpic_router/Nazca build path + -> SVG preview or downloadable GDS +``` + +The repository itself owns the web UI, persistence, API contracts, and orchestration. The actual routed photonic layout build is intentionally delegated to the external `mxpic_router` stack. diff --git a/develop_plan/task_plan.md b/develop_plan/task_plan.md new file mode 100644 index 0000000..61ed864 --- /dev/null +++ b/develop_plan/task_plan.md @@ -0,0 +1,19 @@ +# Project Understanding Plan + +## Goal +Read the `mxpic_EDA` project and document its usage and workflow in Markdown files under `develop_plan`. + +## Phases +| Phase | Status | Notes | +|---|---|---| +| Initialize planning files | complete | Created `develop_plan` planning notes. | +| Inventory repository structure | complete | File list collected with `rg --files`. | +| Read README and operational docs | complete | README, intranet, GDS/SVG, and PDK technology docs read. | +| Read backend entry points and data layer | complete | Route surface, database, PDK access, and GDS builder inspected. | +| Read frontend entry points | complete | Login/dashboard/canvas API wiring and handler context inspected. | +| Summarize project usage/workflow | complete | Wrote `develop_plan/project_understanding.md`. | + +## Errors Encountered +| Error | Attempt | Resolution | +|---|---|---| +| `windows sandbox: spawn setup refresh` | Tried normal PowerShell/read commands in sandbox | Re-ran required commands with escalated approval. | diff --git a/docs/GDS_SVG_GENERATION_LOGIC.md b/docs/GDS_SVG_GENERATION_LOGIC.md index f50aad4..d25e350 100644 --- a/docs/GDS_SVG_GENERATION_LOGIC.md +++ b/docs/GDS_SVG_GENERATION_LOGIC.md @@ -31,15 +31,15 @@ Important functions: ## Generated Files -- Saved cell YAML: `database//layout//.yml` +- Saved cell YAML: `mxpic_EDA_database//layout//.yml` - Path helpers: `user_layout_root`, `project_root`, `cell_file_path` (`backend/server.py` lines 124-137). -- Saved layout preview SVG: `database//layout//.svg` +- Saved layout preview SVG: `mxpic_EDA_database//layout//.svg` - Path helper: `cell_svg_path` (`backend/server.py` lines 140-142). -- Optional route sidecar: `database//layout//.routes.yml` +- Optional route sidecar: `mxpic_EDA_database//layout//.routes.yml` - Path helper and writer: `cell_routes_path`, `write_route_points_sidecar` (`backend/server.py` lines 145-175). -- Downloadable GDS export: `database/_exports//.gds` +- Downloadable GDS export: `mxpic_EDA_database/_exports//.gds` - Created by `create_export_path` (`backend/pdk_access.py` lines 53-59). ## Build Layout: Click Button -> YAML -> Router GDS -> SVG @@ -170,7 +170,7 @@ Important behavior: - Old exports are cleaned (`backend/server.py` line 781). - The project directory is resolved and validated (`backend/server.py` lines 782-784). - - `create_export_path` creates `database/_exports//.gds` + - `create_export_path` creates `mxpic_EDA_database/_exports//.gds` (`backend/server.py` line 785, `backend/pdk_access.py` lines 53-59). - `build_project_gds(...)` is called (`backend/server.py` lines 786-792). diff --git a/docs/INTRANET_DEPLOYMENT.md b/docs/INTRANET_DEPLOYMENT.md index b135af9..aa99c41 100644 --- a/docs/INTRANET_DEPLOYMENT.md +++ b/docs/INTRANET_DEPLOYMENT.md @@ -61,9 +61,22 @@ Change these passwords from the dashboard profile panel before regular use. Each user stores projects under: ```text -database//layout +mxpic_EDA_database//layout ``` +Before starting the server, move the existing `database` folder beside the repo +and rename it to `mxpic_EDA_database`: + +```text +/ + mxpic_EDA/ + mxpic_EDA_database/ +``` + +The backend fails fast if the runtime database folder is missing or still inside +the repository. Use `MXPIC_DATABASE_ROOT` only when the database must live in a +different external location. + ## Useful environment variables ```text @@ -72,6 +85,7 @@ MXPIC_PORT=3000 MXPIC_DEBUG=0 MXPIC_SECRET_KEY= MXPIC_COOKIE_SECURE=0 +MXPIC_DATABASE_ROOT= MXPIC_PDK_PUBLIC_ROOT= MXPIC_PDK_ATLAS_ROOT= ``` diff --git a/docs/PDK_TECHNOLOGY_XSECTION_LOADING.md b/docs/PDK_TECHNOLOGY_XSECTION_LOADING.md index 6aa54c9..0ba08ad 100644 --- a/docs/PDK_TECHNOLOGY_XSECTION_LOADING.md +++ b/docs/PDK_TECHNOLOGY_XSECTION_LOADING.md @@ -28,7 +28,7 @@ There are three related but separate data paths. load route defaults, and register Nazca layers/xsections. 3. Saved project layout YAML - - Source: `database//layout//.yml`. + - Source: `mxpic_EDA_database//layout//.yml`. - Contains placed component paths and `bundles.*.links[*].xsection`. - Consumed by `mxpic_router` when building SVG preview GDS or downloadable GDS. @@ -102,7 +102,7 @@ Detailed path: Saved metadata location: -`database//layout//.project.json` +`mxpic_EDA_database//layout//.project.json` Example: diff --git a/tests/database-root-static.test.js b/tests/database-root-static.test.js new file mode 100644 index 0000000..8e946d2 --- /dev/null +++ b/tests/database-root-static.test.js @@ -0,0 +1,64 @@ +/* + * Description: Static regression tests for keeping mxPIC EDA runtime data outside the repository. + * Inside functions: N/A - assertion-based test/module script. + * Developer : Qin Yue @ 2026 + * Organization : OptiHK Limited + */ +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); + +const root = path.resolve(__dirname, '..'); +const backend = path.join(root, 'backend'); +const storagePathsPath = path.join(backend, 'storage_paths.py'); +const storagePathsPy = fs.existsSync(storagePathsPath) + ? fs.readFileSync(storagePathsPath, 'utf8') + : ''; +const databasePy = fs.readFileSync(path.join(backend, 'database.py'), 'utf8'); +const serverPy = fs.readFileSync(path.join(backend, 'server.py'), 'utf8'); +const gitignore = fs.readFileSync(path.join(root, '.gitignore'), 'utf8'); + +assert( + fs.existsSync(storagePathsPath), + 'backend/storage_paths.py should be the single source of truth for runtime storage paths' +); +assert( + storagePathsPy.includes('MXPIC_DATABASE_ROOT'), + 'storage path layer should support MXPIC_DATABASE_ROOT override' +); +assert( + storagePathsPy.includes('mxpic_EDA_database'), + 'default runtime database folder should be sibling mxpic_EDA_database' +); +assert( + storagePathsPy.includes('DB_FILE') && storagePathsPy.includes('EXPORT_ROOT'), + 'storage path layer should export DB_FILE and EXPORT_ROOT' +); +assert( + storagePathsPy.includes('raise RuntimeError'), + 'storage path layer should fail fast when the external database root is invalid' +); +assert( + !serverPy.includes("DATABASE_ROOT = os.path.abspath(os.path.join(BASE_DIR, '..', 'database'))"), + 'server.py should not hardcode in-repo database/ as DATABASE_ROOT' +); +assert( + serverPy.includes('from storage_paths import DATABASE_ROOT, EXPORT_ROOT'), + 'server.py should import runtime storage roots from storage_paths' +); +assert( + !databasePy.includes('"..", "database", "mxpic_data.db"') && + !databasePy.includes("'..', 'database', 'mxpic_data.db'"), + 'database.py should not hardcode database/mxpic_data.db inside the repository' +); +assert( + databasePy.includes('from storage_paths import DB_FILE'), + 'database.py should import DB_FILE from storage_paths' +); +assert( + gitignore.includes('/database/') && + gitignore.includes('/backend/*.db') && + gitignore.includes('*.db-wal') && + gitignore.includes('/mxpic_EDA_database/'), + '.gitignore should ignore old and accidental in-repo runtime database artifacts' +);