Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 70 additions & 26 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { defineConfig } from 'vitepress'
import { defineConfig } from "vitepress";

export default defineConfig({
title: "MvuviGo Technical Documentation",
base: '/pixels-technical-documentation/',
description: "Technical architecture and system design for the MvuviGo maritime safety platform",

head: [
['link', { rel: 'stylesheet', href: '/custom.css' }]
],
base: "/pixels-technical-documentation/",
description:
"Technical architecture and system design for the MvuviGo maritime safety platform",

head: [["link", { rel: "stylesheet", href: "/custom.css" }]],

themeConfig: {
logo: '/logo.png',
logo: "/logo.png",
nav: [
{ text: "Home", link: "/" },
{ text: "Overview", link: "/overview/" },
Expand All @@ -35,9 +34,18 @@ export default defineConfig({
collapsed: true,
items: [
{ text: "Introduction", link: "/architecture/" },
{ text: "Architecture Principles", link: "/architecture/architecture-principles" },
{ text: "System Architecture", link: "/architecture/system-architecture" },
{ text: "Component Diagram", link: "/architecture/component-diagram" },
{
text: "Architecture Principles",
link: "/architecture/architecture-principles",
},
{
text: "System Architecture",
link: "/architecture/system-architecture",
},
{
text: "Component Diagram",
link: "/architecture/component-diagram",
},
{ text: "Data Flow", link: "/architecture/data-flow" },
],
},
Expand Down Expand Up @@ -71,16 +79,25 @@ export default defineConfig({
{ text: "Repositories", link: "/repository/" },
{ text: "Backend Repository", link: "/repository/backend-repo" },
{ text: "Frontend Repository", link: "/repository/frontend-repo" },
{ text: "IoT Server Repository", link: "/repository/iot-server-repo" },
{
text: "IoT Server Repository",
link: "/repository/iot-server-repo",
},
],
},
{
text: "Communication Systems",
collapsed: true,
items: [
{ text: "Introduction", link: "/communication/" },
{ text: "RFID and Station Hardware", link: "/communication/rfid-and-station-hardware" },
{ text: "LoRa Relay and Mesh", link: "/communication/lora-relay-and-mesh" },
{
text: "RFID and Station Hardware",
link: "/communication/rfid-and-station-hardware",
},
{
text: "LoRa Relay and Mesh",
link: "/communication/lora-relay-and-mesh",
},
{ text: "SMS Integration", link: "/communication/sms-integration" },
{ text: "GPS Tracking", link: "/communication/gps-tracking" },
],
Expand All @@ -92,9 +109,15 @@ export default defineConfig({
{ text: "Introduction", link: "/frontend/" },
{ text: "Architecture", link: "/frontend/architecture" },
{ text: "Routing", link: "/frontend/routing" },
{ text: "Pages and Components", link: "/frontend/pages-and-components" },
{
text: "Pages and Components",
link: "/frontend/pages-and-components",
},
{ text: "State Management", link: "/frontend/state-management" },
{ text: "Forms and Validation", link: "/frontend/forms-and-validation" },
{
text: "Forms and Validation",
link: "/frontend/forms-and-validation",
},
{ text: "API Integration", link: "/frontend/api-integration" },
{ text: "Authentication", link: "/frontend/authentication" },
{ text: "Maps and Real-time", link: "/frontend/maps-and-real-time" },
Expand All @@ -110,32 +133,53 @@ export default defineConfig({
{ text: "Introduction", link: "/security/" },
{ text: "Access Control", link: "/security/access-control" },
{ text: "Data Protection", link: "/security/data-protection" },
{ text: "Logging and Monitoring", link: "/security/logging-and-monitoring" },
{
text: "Logging and Monitoring",
link: "/security/logging-and-monitoring",
},
{ text: "Failure Handling", link: "/security/failure-handling" },
],
},
{
text: "Setup",
text: "Developer Setup",
collapsed: true,
items: [
{ text: "Deployment and Contribution", link: "/deployment/" },
{ text: "Deployment", link: "/deployment/deployment" },
{ text: "Branching and Pull Requests", link: "/deployment/branching-and-prs" },
{ text: "Code Contribution", link: "/deployment/code-contribution" },
{ text: "Onboarding", link: "/setup/" },
{ text: "Prerequisites", link: "/setup/prerequisites" },
{ text: "Installation", link: "/setup/installation" },
{ text: "Run Locally", link: "/setup/run-locally" },
{
text: "Environment Variables",
link: "/setup/environment-variables",
},
{ text: "Database Setup", link: "/setup/database-setup" },
{ text: "Environment Variables", link: "/setup/environment-variables" },
{ text: "Run Locally", link: "/setup/run-locally" },
],
},
{
text: "Deployment and Contribution",
collapsed: true,
items: [
{ text: "Introduction", link: "/deployment/" },
{ text: "Deployment", link: "/deployment/deployment" },
{
text: "Branching and Pull Requests",
link: "/deployment/branching-and-prs",
},
{ text: "Code Contribution", link: "/deployment/code-contribution" },
],
},

{
text: "Workflows",
collapsed: true,
items: [
{ text: "Introduction", link: "/workflows/" },
{ text: "Trip Tracking", link: "/workflows/trip-tracking" },
{ text: "SOS Alert Flow", link: "/workflows/sos-alert-flow" },
{ text: "Rescue Coordination", link: "/workflows/rescue-coordination" },
{
text: "Rescue Coordination",
link: "/workflows/rescue-coordination",
},
],
},
{
Expand All @@ -151,4 +195,4 @@ export default defineConfig({
},
],
},
})
});
11 changes: 9 additions & 2 deletions docs/database/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Database

MvuviGo stores everything in a **PostgreSQL** database named `MvuviGo`. The backend (`pixels-backend`) talks to it through **SQLAlchemy** models, and the schema is versioned with **Alembic** migrations.
MvuviGo stores its application data in **PostgreSQL**. For local development, this documentation uses the database name `mvuvigo`; the backend (`pixels-backend`) accesses it through **SQLAlchemy**, and the schema is versioned with **Alembic** migrations.

## What the database holds

Expand All @@ -14,11 +14,18 @@ MvuviGo stores everything in a **PostgreSQL** database named `MvuviGo`. The back
## In this section

- [Entity relationship diagram](./er-diagram.md): how the tables connect.

- [Key entities](./key-entities.md): what each table stores and how an alert moves through them.
- [Constraints](./constraints.md): keys, unique rules, required columns and allowed values.
- [Migrations](./migrations.md): how the schema is versioned and changed with Alembic.
- [Seed data](./seed-data.md): the data a fresh database needs and how it is loaded.

- [Constraints](./constraints.md): keys, unique rules, required columns and allowed values.

- [Migrations](./migrations.md): how the schema is versioned and changed with Alembic.

- [Seed data](./seed-data.md): the data a fresh database needs and how it is loaded.

## Working with the database locally

The local database runs on `localhost:5432`. To create or update the tables, run the migrations from the backend repo:
Expand All @@ -27,6 +34,6 @@ The local database runs on `localhost:5432`. To create or update the tables, run
alembic upgrade head
```

If you get an error such as `relation "islands" already exists`, the tables were created before Alembic was set up on your machine. Either drop and recreate your local database, or mark the existing schema as up to date with `alembic stamp head` and then upgrade.
If you get an error such as `relation "islands" already exists`, the tables may have been created before Alembic was set up. For a disposable local database, recreate it and apply migrations from the beginning. `alembic stamp head` only records a version; use it only after verifying that the existing schema exactly matches that revision. Never drop or stamp a shared or production database as a troubleshooting shortcut.

Every change to a SQLAlchemy model needs a new migration. Do not edit the database by hand and leave the models behind.
31 changes: 23 additions & 8 deletions docs/database/migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ The schema is versioned with **Alembic** in `pixels-backend`. The SQLAlchemy mod
## Rules

- Every change to a SQLAlchemy model needs a new migration.

- Never edit the database by hand and leave the models behind.

- Keep one concern per migration, and keep it in the same PR as the model change.

- Read every generated migration before committing it. Autogenerate can miss renames and constraints.

- Write a working `downgrade` for every migration so it can be undone.

## Commands
Expand All @@ -28,13 +32,20 @@ Migration files live in the Alembic `versions` folder (**TO CONFIRM** the path i
## Adding a migration

1. Change the model in `pixels-backend`.
2. Run `alembic revision --autogenerate -m "describe the change"`.
3. Open the new file and check the `upgrade` and `downgrade` steps.
4. Run `alembic upgrade head` on your local database.
5. Run `alembic downgrade -1` and then `alembic upgrade head` again to prove both directions work.
6. Run the backend tests (`pytest`).
7. Commit the model change and the migration together.
8. Update [Key entities](./key-entities.md), [Constraints](./constraints.md) and the [entity relationship diagram](./er-diagram.md) if the schema changed.

1. Run `alembic revision --autogenerate -m "describe the change"`.

1. Open the new file and check the `upgrade` and `downgrade` steps.

1. Run `alembic upgrade head` on your local database.

1. Run `alembic downgrade -1` and then `alembic upgrade head` again to prove both directions work.

1. Run the backend tests (`pytest`).

1. Commit the model change and the migration together.

1. Update [Key entities](./key-entities.md), [Constraints](./constraints.md) and the [entity relationship diagram](./er-diagram.md) if the schema changed.

## Common problems

Expand All @@ -44,10 +55,14 @@ Migration files live in the Alembic `versions` folder (**TO CONFIRM** the path i
| Adding a unique constraint fails | The table already contains duplicate values. | Clean the duplicates first, for example in the migration itself, then upgrade again. |
| The app and the migrations disagree about the data | Alembic and the application are connected to different databases. | Make sure the connection setting in `.env` and the default in the application's database code name the same database. |

PostgreSQL treats names that differ only in capitals, such as `MvuviGo` and `mvuvigo`, as different databases when the name was created with quotes. The documented name is `MvuviGo`. **TO CONFIRM** the exact spelling every environment must use, and use it everywhere.
For local development, use the lower-case database name `mvuvigo` consistently in the database creation command and `DATABASE_URL`. PostgreSQL folds unquoted identifiers to lower case; a database created with a quoted mixed-case name is a different name and requires a matching connection string. Confirm the target database before running any migration.

Do not use `alembic stamp head` as a general fix for migration errors. It changes Alembic's recorded version without applying or validating the schema. Use it only after verifying that the existing database exactly matches the target revision; otherwise, recreate a disposable local database and apply migrations from the beginning. Never use this shortcut on a shared or production database.

## Production

- Take a database backup before every production migration.

- Run `alembic upgrade head` on every deploy, after the backup and before the new backend starts.

- Follow [Rollback and recovery](../deployment/deployment.md#rollback-and-recovery) if a migration has to be undone.
48 changes: 28 additions & 20 deletions docs/database/seed-data.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
# Seed Data

Seed data is the information a fresh database needs before the system is useful. Everything else is created by people using the dashboard and by the wristbands and stations.
Seed data is information needed to make a fresh database useful. The project documentation identifies island reference records and an initial station-operator account as potential setup needs, while sample fishers, wristbands, trips, locations and alerts are for local development or demos.

## What needs seeding

| Table | Why | Needed in production |
## Data categories

| Data | Documented purpose | Handling guidance |
| --- | --- | --- |
| `islands` | Reference data for the fishing areas: `island_name`, `island_latitude` and `island_longitude`. | Yes |
| `station_operators` | At least one operator must exist to log in and register fishers. The password is stored as a hash, never in plain text. | Yes, the first operator only |
| `fishers`, `wristbands`, `trips`, `locations` | Sample records for local development and demos. | No |
| `distressed_fisher_alerts`, `alert_responders` | Sample alerts for local development and demos. | No |
| Islands | Reference names and coordinates used by the product | Use an approved, sourced dataset. The exact list and source are not included here. |
| First station operator | Allows an authorized operator to access the dashboard | Create through the backend's secured account-creation process; never store a plaintext password in a seed file. Confirm the actual bootstrap flow in the backend repository. |
| Fishers, wristbands, trips and locations | Local development or demo records | Use invented identities and synthetic coordinates only. |
| SOS alerts and responders | Local workflow demonstration | Use synthetic events in a local/test environment; never replay test alerts to real responders. |

## Verify the seeding mechanism

From the backend repository root, before changing a database:

1. Read the repository README and inspect `pyproject.toml` for documented scripts or commands.

The list of islands to load: **TO CONFIRM**.
1. Inspect the Alembic migrations and search the repository for seed/fixture files or commands. Do not assume a filename or entry point.

## How seed data is loaded
1. Confirm whether reference data is created by a migration, an idempotent script, an API workflow or a manual approved process.

**TO CONFIRM:** whether seed data is loaded by a script, by a migration or by hand, and the exact command. Document it here once decided, for example:
1. If a script exists, verify that it is safe to run more than once and that it cannot target production by accident.

```bash
# TO CONFIRM: replace with the real command
python <seed-script>
```
1. Run it only against a disposable local/test database, then verify the resulting rows and record the exact command and source dataset here.

If there is no seed mechanism yet, state "none" here and list how the first operator and the islands are created.
If the checked-out application repository has no seed mechanism, document that explicitly and describe the approved local setup path for the first operator and reference data. Keep this page synchronized with any later script or migration change.

## Rules

- A seed script must be safe to run twice. Check for existing rows before inserting.
- Never load development sample data into production.
- Sample data uses invented names and phone numbers, never real people.
- Do not commit real passwords or real operator accounts. Create the first production operator through a secured step and store its credentials in the host's secret store.
- Backend tests create their own data and roll it back, so they do not depend on seed data.
- Keep development seed data separate from production data.

- Use synthetic names, phone numbers and locations; do not copy real fisher records into a test environment.

- Never seed plaintext passwords, API keys, tokens or provider credentials.

- Make repeatable seed operations idempotent or clearly document that they are one-time operations.

- Backend tests should use isolated test fixtures rather than depending on a developer's local seed dataset.
13 changes: 8 additions & 5 deletions docs/frontend/build-and-tooling.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Run these from the `pixels-frontend` folder:

| Command | What it does |
| --- | --- |
| `npm install` | Install dependencies |
| `npm ci` | Install the exact dependencies recorded in `package-lock.json` |
| `npm run dev` | Start the development server on port 3000 |
| `npm run build` | Create the optimised production build |
| `npm run start` | Serve the production build |
Expand All @@ -32,7 +32,10 @@ Variables that start with `NEXT_PUBLIC_` are included in the browser bundle, so

## Build process

1. `npm install` installs dependencies from `package-lock.json`.
2. `npm run build` compiles the pages, bundles the JavaScript and CSS, and generates the static assets.
3. The build fails on compile errors, so fix them before release.
4. `npm run start` serves the result for a final check.
1. `npm ci` installs the exact dependencies recorded in `package-lock.json`.

1. `npm run build` compiles the pages, bundles the JavaScript and CSS, and generates the static assets.

1. The build fails on compile errors, so fix them before release.

1. `npm run start` serves the result for a final check.
Loading
Loading