Smart Site
Home Docs Smart Data Project Management

Project Management

The Project module implements multi-tenant isolation for Smart SCADA. Each project is an independent unit with its own database, configuration file, devices, tags, alarms, and scripts.

Interface Screenshot

Project Management (English UI)

Captured from the live Smart Site system with the English UI. See the zh-CN counterpart for the Chinese-UI screenshot.

1. Core Concepts

1.1 Project Isolation

Every project owns an independent SQLite database:

{PROJECTS_DIR}/{projectName}/db/system.db

The PROJECTS_DIR environment variable (or system config key) defines the root directory. The PROJECT_DB_MODE=isolated flag enables per-project DB isolation. Metadata tables (devices, device_groups, data_tags, alarms, scripts, ...) live inside each project DB, so two projects never share operational data.

1.2 projectinfo.json

Each project directory contains a projectinfo.json file (not stored in the database) that holds:

  • Project name, description, creation time
  • Protocol and collector settings
  • InfluxDB bucket mapping
  • Custom display preferences

Because it is a plain JSON file, it can be version-controlled and edited directly when the server is stopped.

1.3 Global vs Project Data

Scope Storage Examples
Global ss-data/data/ss-data.db / ss-node.db sys_users, sys_roles, sys_menus, system_configs
Project {PROJECTS_DIR}/{name}/db/system.db devices, data_tags, alarms, scripts

2. Functional Areas

2.1 Project CRUD

  • Create a new project (initializes the DB schema and projectinfo.json)
  • Update project metadata
  • Archive / delete a project (soft delete keeps the DB file)
  • List projects the current user is authorized to access

The ProjectService in @ss-node/ss-project orchestrates these operations. The HTTP entry point is ProjectController.

2.2 Project Switching

The frontend stores the active project ID and sends it as a path parameter (e.g. /api/v1/projects/:projectId/devices). The backend ProjectContext middleware resolves the project, opens its SQLite connection, and makes it available to all downstream services.

GET /api/v1/projects/{projectId}/devices

Switching projects in the UI reloads the active DB context — no server restart is required.

2.3 Project Authorization

Users can be bound to one or more projects through the project_authorizations table. A user without authorization receives 403 Forbidden when accessing that project's endpoints. Admins (weight = 2) bypass this check.

3. Operational Guidance

3.1 Creating a Project

  1. Navigate to System → Projects and click New Project
  2. Enter a unique name (used as the directory name, so avoid spaces and special characters)
  3. Select a template (optional) to pre-load device groups and tags
  4. Confirm — the backend creates the folder, initializes system.db, and writes projectinfo.json

3.2 Backing Up a Project

Stop the backend (or ensure no write activity), then copy the entire project folder:

Copy-Item -Recurse "{PROJECTS_DIR}\{projectName}" "D:\backup\{projectName}_$(Get-Date -Format yyyyMMdd)"

3.3 Moving a Project to Another Server

  1. Back up the project folder
  2. Back up any global config keys from sys_configs that reference the project
  3. On the target server, place the folder under the same PROJECTS_DIR
  4. Restart the backend — the project is discovered automatically

4. FAQ

Q: After creating a project, devices cannot be added. A: Verify the project folder and db/system.db were created under PROJECTS_DIR. If PROJECT_DB_MODE is not isolated, tables may land in the global DB instead. Check the .env file and restart.

Q: Can two projects share the same InfluxDB bucket? A: Technically yes, but it is strongly discouraged. Configure a separate bucket per project in projectinfo.json to keep time-series data isolated.

Q: Deleting a project throws a foreign-key error. A: The project still has devices or alarms referencing it. Either archive (soft delete) instead of hard delete, or remove the dependent records first.

Q: Where is PROJECTS_DIR configured? A: It is read from the environment variable first; if absent, the SystemConfigService falls back to the system_configs table. Environment variables always take priority.

  • ../../../../../../../docs/03-架构设计/后端-数据库设计.md
  • ../../../../../../../docs/02-详细设计/ss-services/00-整体设计/后端整体架构设计.md
  • Project Package