# assai-id/nemesis architecture

> Architecture diagram of the GitHub repository assai-id/nemesis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/assai-id/nemesis
- Repository: https://github.com/assai-id/nemesis

## Overview

1. **System shape**
   - Nemesis is a two-tier application: a **static frontend** and a **Node.js backend API**.
   - The product goal is an investigative dashboard over a large procurement dataset, with anomalies surfaced for public consumption.

2. **Frontend boundary**
   - `frontend/index.html` plus plain CSS/JS under `frontend/assets/` form a **no-build static client**.
   - There is no frontend framework or bundler in the repo; the browser UI is served separately and talks to the backend over HTTP.

3. **Backend runtime**
   - The backend is a **Node.js service** in `backend/src/`.
   - Key files suggest a typical server split:
     - `server.js` for process startup/listening
     - `app.js` for application wiring
     - `config.js` for environment/config loading
     - `db.js` for database access
     - `dashboard-repository.js` for query/data-access logic
     - `seed.js` and `db-transfer.js` for data loading/migration concerns

4. **Primary request flow**
   - Browser UI requests data from the backend at `http://127.0.0.1:3000/api` per the README.
   - The backend likely translates those requests into SQLite queries through the repository layer, then returns JSON to the frontend.
   - This is the core runtime path: **UI → API → repository/db → JSON response**.

5. **Data store**
   - The backend depends on a local **SQLite database** at `backend/data/dashboard.sqlite`.
   - The README emphasizes that the application is data-first: the DB is prepopulated from a dataset rather than backed by an external live system.

6. **Dataset ingestion / offline preparation**
   - The repo includes operational scripts in `backend/scripts/`:
     - `import-db.js`
     - `export-db.js`
     - `reset-db.js`
   - These indicate the database is managed as an offline artifact, with import/export/reset workflows for rebuilding or exchanging the SQLite file.

7. **Geospatial subsystem**
   - `backend/seed/geo/` contains many GeoJSON files organized by administrative level:
     - `02-provinces/province-only`
     - `02-provinces/with-districts`
     - `03-districts`
   - This is a separate data boundary from procurement records: it provides **reference geography** for mapping, joins, or region-aware visualization.

8. **Seeding and reference data**
   - The presence of `backend/src/seed.js` and the GeoJSON hierarchy suggests backend initialization may load or validate reference geographic layers.
   - The repo also has a `None.geojson` file among districts, which suggests the data pipeline handles incomplete or unmapped records explicitly.

9. **Configuration and environment**
   - Backend configuration comes from `backend/.env` with defaults for:
     - `PORT`
     - `CORS_ORIGIN`
     - `SQLITE_PATH`
     - `AUDIT_DATASET_DIR`
     - `GEO_ROOT_PATH`
   - This shows the backend is designed to be portable and to locate both the database and seed data via environment variables.

10. **Deployment/runtime topology**
   - Development uses two processes:
     - backend on `http://127.0.0.1:3000`
     - frontend served separately on `http://127.0.0.1:8080`
   - The frontend is not embedded into the backend build, so the architecture keeps **static presentation** and **API/data processing** cleanly separated.

11. **External dependencies and serving model**
   - The README links to downloadable dataset artifacts hosted externally, but the running application itself does not appear to depend on an external live API.
   - That means the main production dependency is the local SQLite file, not a remote database service.

12. **What to draw in an architecture diagram**
   - Draw four main boxes:
     - **Browser UI**
     - **Static frontend files**
     - **Node.js backend API**
     - **SQLite database + GeoJSON seed/reference data**
   - Show one primary data path from browser to API to SQLite.
   - Show a secondary offline path from dataset artifacts and seed files into the database via the import/seed scripts.

Main entry points: [`backend/src/app.js`](https://github.com/assai-id/nemesis/blob/main/backend/src/app.js) (App wiring), [`backend/src/dashboard-repository.js`](https://github.com/assai-id/nemesis/blob/main/backend/src/dashboard-repository.js) (Dashboard repo), [`backend/src/db-transfer.js`](https://github.com/assai-id/nemesis/blob/main/backend/src/db-transfer.js) (DB transfer), [`backend/src/seed.js`](https://github.com/assai-id/nemesis/blob/main/backend/src/seed.js) (Seeding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_browser(("Browser UI<br/>client"))
  node_static_html["HTML shell<br/>static entry<br/>[index.html]"]
  node_static_assets["Static assets<br/>plain CSS/JS"]
end

subgraph group_backend["Backend"]
  node_server_start["Server start<br/>bootstrap<br/>[server.js]"]
  node_app_wiring["App wiring<br/>composition<br/>[app.js]"]
  node_config["Config<br/>env loader<br/>[config.js]"]
  node_db_layer[("DB layer<br/>sqlite access<br/>[db.js]")]
  node_repo["Dashboard repo<br/>query layer"]
  node_seed_logic["Seeding<br/>bootstrap data<br/>[seed.js]"]
  node_transfer_logic["DB transfer<br/>migrate/import<br/>[db-transfer.js]"]
end

subgraph group_data["Data"]
  node_sqlitedb[("SQLite DB<br/>local datastore")]
  node_geo_ref["GeoJSON refs<br/>geography layers"]
  node_dataset_artifacts["Dataset artifacts<br/>offline inputs"]
end

subgraph group_ops["Offline prep"]
  node_import_script["Import DB<br/>ops script<br/>[import-db.js]"]
  node_export_script["Export DB<br/>ops script<br/>[export-db.js]"]
  node_reset_script["Reset DB<br/>ops script<br/>[reset-db.js]"]
end

node_browser -->|"loads"| node_static_html
node_static_html -->|"uses"| node_static_assets
node_browser -->|"requests JSON"| node_app_wiring
node_app_wiring -->|"bootstrapped by"| node_server_start
node_app_wiring -->|"reads"| node_config
node_app_wiring -->|"delegates to"| node_repo
node_repo -->|"queries"| node_db_layer
node_db_layer -->|"opens"| node_sqlitedb
node_repo -.->|"enriches with"| node_geo_ref
node_seed_logic -->|"loads"| node_geo_ref
node_seed_logic -->|"initializes"| node_sqlitedb
node_transfer_logic -->|"imports from"| node_dataset_artifacts
node_transfer_logic -->|"writes to"| node_sqlitedb
node_import_script -->|"invokes"| node_transfer_logic
node_export_script -->|"exports"| node_sqlitedb
node_reset_script -->|"resets"| node_sqlitedb

click node_static_html "https://github.com/assai-id/nemesis/blob/main/frontend/index.html"
click node_static_assets "https://github.com/assai-id/nemesis/tree/main/frontend/assets"
click node_server_start "https://github.com/assai-id/nemesis/blob/main/backend/src/server.js"
click node_app_wiring "https://github.com/assai-id/nemesis/blob/main/backend/src/app.js"
click node_config "https://github.com/assai-id/nemesis/blob/main/backend/src/config.js"
click node_db_layer "https://github.com/assai-id/nemesis/blob/main/backend/src/db.js"
click node_repo "https://github.com/assai-id/nemesis/blob/main/backend/src/dashboard-repository.js"
click node_seed_logic "https://github.com/assai-id/nemesis/blob/main/backend/src/seed.js"
click node_transfer_logic "https://github.com/assai-id/nemesis/blob/main/backend/src/db-transfer.js"
click node_geo_ref "https://github.com/assai-id/nemesis/tree/main/backend/seed/geo"
click node_import_script "https://github.com/assai-id/nemesis/blob/main/backend/scripts/import-db.js"
click node_export_script "https://github.com/assai-id/nemesis/blob/main/backend/scripts/export-db.js"
click node_reset_script "https://github.com/assai-id/nemesis/blob/main/backend/scripts/reset-db.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_browser,node_static_html,node_static_assets toneBlue
class node_server_start,node_app_wiring,node_config,node_db_layer,node_repo,node_seed_logic,node_transfer_logic toneAmber
class node_sqlitedb,node_geo_ref,node_dataset_artifacts toneMint
class node_import_script,node_export_script,node_reset_script toneRose
```

## Components

### Frontend

No-build static browser client

- **Browser UI**: client · Investigative dashboard used to consume procurement data
- [HTML shell](https://github.com/assai-id/nemesis/blob/main/frontend/index.html): static entry · Frontend entry page · `frontend/index.html`
- [Static assets](https://github.com/assai-id/nemesis/tree/main/frontend/assets): plain CSS/JS · No-build browser logic and styling · `frontend/assets`

### Backend

Node.js API and data access

- [Server start](https://github.com/assai-id/nemesis/blob/main/backend/src/server.js): bootstrap · Process startup and HTTP listening · `backend/src/server.js`
- [App wiring](https://github.com/assai-id/nemesis/blob/main/backend/src/app.js): composition · Middleware, routes, and application setup · `backend/src/app.js`
- [Config](https://github.com/assai-id/nemesis/blob/main/backend/src/config.js): env loader · Loads runtime settings such as port, CORS, and paths · `backend/src/config.js`
- [DB layer](https://github.com/assai-id/nemesis/blob/main/backend/src/db.js): sqlite access · Opens and manages the local database connection · `backend/src/db.js`
- [Dashboard repo](https://github.com/assai-id/nemesis/blob/main/backend/src/dashboard-repository.js): query layer · Encapsulates dashboard-specific queries and data shaping · `backend/src/dashboard-repository.js`
- [Seeding](https://github.com/assai-id/nemesis/blob/main/backend/src/seed.js): bootstrap data · Initializes or validates reference and dataset-loaded state · `backend/src/seed.js`
- [DB transfer](https://github.com/assai-id/nemesis/blob/main/backend/src/db-transfer.js): migrate/import · Moves data between database artifacts and source datasets · `backend/src/db-transfer.js`

### Data

SQLite store and reference geography

- **SQLite DB**: local datastore · Prepopulated dashboard database artifact
- [GeoJSON refs](https://github.com/assai-id/nemesis/tree/main/backend/seed/geo): geography layers · Province and district reference geometries, including unmapped records · `backend/seed/geo`
- **Dataset artifacts**: offline inputs · Downloaded procurement source data used to build the local DB

### Offline prep

Import, export, reset, and seeding workflows

- [Import DB](https://github.com/assai-id/nemesis/blob/main/backend/scripts/import-db.js): ops script · Builds or refreshes the SQLite artifact from source data · `backend/scripts/import-db.js`
- [Export DB](https://github.com/assai-id/nemesis/blob/main/backend/scripts/export-db.js): ops script · Exports the local database artifact · `backend/scripts/export-db.js`
- [Reset DB](https://github.com/assai-id/nemesis/blob/main/backend/scripts/reset-db.js): ops script · Resets the database to a clean state · `backend/scripts/reset-db.js`

## Connections

- Browser UI → HTML shell: loads · Browser opens the static client entry point
- HTML shell → Static assets: uses · HTML pulls in browser scripts and styling
- Browser UI → App wiring: requests JSON · UI calls the backend API over HTTP
- App wiring → Server start: bootstrapped by · App wiring is started by the server process
- App wiring → Config: reads · Runtime behavior depends on environment configuration
- App wiring → Dashboard repo: delegates to · Request handlers use the repository layer for query logic
- Dashboard repo → DB layer: queries · Repository executes database operations through the DB layer
- DB layer → SQLite DB: opens · Local SQLite file is the primary runtime datastore
- Dashboard repo → GeoJSON refs: enriches with · Query results can be joined or interpreted with reference geography
- Seeding → GeoJSON refs: loads · Seeding uses GeoJSON reference layers
- Seeding → SQLite DB: initializes · Seed step prepares the local database contents
- DB transfer → Dataset artifacts: imports from · Offline transfer starts from downloaded source datasets
- DB transfer → SQLite DB: writes to · Transfer scripts populate or refresh the SQLite artifact
- Import DB → DB transfer: invokes · Import script drives the database transfer workflow
- Export DB → SQLite DB: exports · Export script reads the local database artifact
- Reset DB → SQLite DB: resets · Reset script clears or recreates the database state
