# gracelium64/dartbackendserver architecture

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

- Interactive diagram: https://gitdiagram.com/gracelium64/dartbackendserver
- Repository: https://github.com/gracelium64/dartbackendserver

## Overview

#### Purpose and Entry Points
Shadow App is a Dart/Shelf learning backend providing JWT authentication, SQLite-backed document collections, media storage, audit logging, and operator tooling. The primary executable is `bin/main.dart`, which dispatches server, interactive admin, and log-tail commands through `bin/commands/server_command.dart`, `bin/commands/admin_command.dart`, and `bin/commands/log_tail_command.dart`.

#### HTTP Server and API Boundary
`lib/server.dart` owns HTTP routing, including health, authentication, CRUD, admin SQL, and media endpoints. CRUD-specific request parsing and responses are separated into `lib/api/crud_handlers.dart`. This is the public REST boundary consumed by remote clients and SDKs; authentication and collection permissions gate operations before persistence.

#### Authentication and Authorization
`lib/auth/auth_service.dart` implements signup, login, JWT issuance, and refresh flows. Password derivation/verification is isolated in `lib/auth/password_utils.dart`; access-rule evaluation is in `lib/auth/rule_engine.dart`. Requests move from server routing through token validation and role/collection-rule checks before invoking document or administrative actions.

#### Persistence and Domain Model
SQLite is the local system of record, managed by `lib/database/db_manager.dart`. Schema setup/evolution is centralized in `lib/database/migrations.dart`, while database-facing entities reside in `lib/database/models.dart`. Runtime database artifacts live under `data/` (currently including `data/shadow_app.db` and WAL/shm files). The design supports collections, documents, users, media, and audit records; the stated larger-scale PostgreSQL/Redis/S3 topology is guidance rather than represented runtime infrastructure.

#### CRUD, Media, and Administrative Data Access
Document collection operations are exposed through `lib/api/crud_handlers.dart` and persist through the database layer after authorization. The server also exposes admin SQL blocks, a privileged path distinct from normal CRUD. Media upload/download is part of the server API and is surfaced in client SDKs, including `flutter_sdk/lib/media_service.dart`. Operator-facing database/user/report workflows are implemented by `bin/helpers/document_operations.dart`, `bin/helpers/user_management.dart`, and `bin/helpers/report_generator.dart`.

#### Audit, Monitoring, and Email Integration
Operational events are recorded through `lib/logging/logger.dart`; the `log-tail` command provides live terminal access to that audit stream. `lib/logging/email_service.dart` integrates Gmail SMTP for report delivery, making Gmail credentials/configuration an external-service boundary. The admin console can export report bundles and manage users without directly exposing these maintenance operations as ordinary client CRUD.

#### Client Integration Surfaces
The Flutter package is a separate Dart package rooted at `flutter_sdk/`, with initialization and collection façade in `flutter_sdk/lib/shadow_app.dart`, auth calls in `flutter_sdk/lib/auth_service.dart`, and CRUD calls in `flutter_sdk/lib/crud_service.dart`. A standalone remote CLI client enters at `cli_client/bin/client.dart`. A TypeScript/React SDK is also present under `react_sdk/src/client.ts` and `react_sdk/src/context.tsx`, indicating the REST API is intentionally language-agnostic.

#### Runtime and Deployment
The core runtime is Dart with Shelf and SQLite, configured through `lib/config.dart`; the repository includes a `Dockerfile` for containerized operation. Typical local control flow is: launch server → initialize database/migrations → accept HTTP requests → authenticate/authorize → perform SQLite operations → emit audit events. Production integrations explicitly include Gmail SMTP; future-scale dependencies described in documentation are not core checked-in components.

Main entry points: [`lib/server.dart`](https://github.com/gracelium64/dartbackendserver/blob/main/lib/server.dart) (HTTP server), [`lib/database/db_manager.dart`](https://github.com/gracelium64/dartbackendserver/blob/main/lib/database/db_manager.dart) (Database manager), [`bin/main.dart`](https://github.com/gracelium64/dartbackendserver/blob/main/bin/main.dart) (Main executable), [`bin/helpers/document_operations.dart`](https://github.com/gracelium64/dartbackendserver/blob/main/bin/helpers/document_operations.dart) (Admin workflows)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_main["Main executable<br/>Dart CLI<br/>[main.dart]"]
  node_server_cmd["Server command"]
  node_admin_cmd["Admin command<br/>[admin_command.dart]"]
  node_log_tail_cmd["Log-tail command"]
end

subgraph group_server["Backend runtime"]
  node_http_server["HTTP server<br/>Shelf REST API<br/>[server.dart]"]
  node_crud_handlers["CRUD handlers<br/>API layer<br/>[crud_handlers.dart]"]
  node_auth_service["Auth service<br/>JWT auth<br/>[auth_service.dart]"]
  node_rule_engine["Rule engine<br/>authorization<br/>[rule_engine.dart]"]
  node_password_utils["Password utilities<br/>credential security"]
end

subgraph group_data["Data and operations"]
  node_db_manager["Database manager<br/>persistence layer<br/>[db_manager.dart]"]
  node_migrations["Migrations<br/>schema evolution<br/>[migrations.dart]"]
  node_sqlite_data[("SQLite database<br/>local system of record<br/>[shadow_app.db]")]
  node_audit_logger["Audit logger<br/>operational logging<br/>[logger.dart]"]
  node_admin_tools["Admin workflows<br/>operator tooling"]
  node_email_service["Email service<br/>Gmail SMTP integration<br/>[email_service.dart]"]
end

subgraph group_clients["Client surfaces"]
  node_flutter_sdk["Flutter SDK<br/>Dart client package<br/>[shadow_app.dart]"]
  node_cli_client["Remote CLI client<br/>[client.dart]"]
  node_react_sdk["React SDK<br/>TypeScript client<br/>[client.ts]"]
end

node_main -->|"dispatches"| node_server_cmd
node_main -->|"dispatches"| node_admin_cmd
node_main -->|"dispatches"| node_log_tail_cmd
node_server_cmd -->|"starts"| node_http_server
node_http_server -->|"authenticates"| node_auth_service
node_auth_service -->|"verifies passwords"| node_password_utils
node_http_server -->|"authorizes"| node_rule_engine
node_http_server -->|"routes CRUD"| node_crud_handlers
node_crud_handlers -->|"persists documents"| node_db_manager
node_http_server -->|"admin SQL and media"| node_db_manager
node_db_manager -->|"initializes schema"| node_migrations
node_db_manager -->|"reads and writes"| node_sqlite_data
node_http_server -->|"emits events"| node_audit_logger
node_log_tail_cmd -->|"tails"| node_audit_logger
node_admin_cmd -->|"runs"| node_admin_tools
node_admin_tools -->|"maintains data"| node_db_manager
node_admin_tools -->|"delivers reports"| node_email_service
node_flutter_sdk -->|"REST calls"| node_http_server
node_cli_client -->|"REST calls"| node_http_server
node_react_sdk -->|"REST calls"| node_http_server

click node_main "https://github.com/gracelium64/dartbackendserver/blob/main/bin/main.dart"
click node_server_cmd "https://github.com/gracelium64/dartbackendserver/blob/main/bin/commands/server_command.dart"
click node_admin_cmd "https://github.com/gracelium64/dartbackendserver/blob/main/bin/commands/admin_command.dart"
click node_log_tail_cmd "https://github.com/gracelium64/dartbackendserver/blob/main/bin/commands/log_tail_command.dart"
click node_http_server "https://github.com/gracelium64/dartbackendserver/blob/main/lib/server.dart"
click node_crud_handlers "https://github.com/gracelium64/dartbackendserver/blob/main/lib/api/crud_handlers.dart"
click node_auth_service "https://github.com/gracelium64/dartbackendserver/blob/main/lib/auth/auth_service.dart"
click node_rule_engine "https://github.com/gracelium64/dartbackendserver/blob/main/lib/auth/rule_engine.dart"
click node_password_utils "https://github.com/gracelium64/dartbackendserver/blob/main/lib/auth/password_utils.dart"
click node_db_manager "https://github.com/gracelium64/dartbackendserver/blob/main/lib/database/db_manager.dart"
click node_migrations "https://github.com/gracelium64/dartbackendserver/blob/main/lib/database/migrations.dart"
click node_sqlite_data "https://github.com/gracelium64/dartbackendserver/blob/main/data/shadow_app.db"
click node_audit_logger "https://github.com/gracelium64/dartbackendserver/blob/main/lib/logging/logger.dart"
click node_admin_tools "https://github.com/gracelium64/dartbackendserver/blob/main/bin/helpers/document_operations.dart"
click node_email_service "https://github.com/gracelium64/dartbackendserver/blob/main/lib/logging/email_service.dart"
click node_flutter_sdk "https://github.com/gracelium64/dartbackendserver/blob/main/flutter_sdk/lib/shadow_app.dart"
click node_cli_client "https://github.com/gracelium64/dartbackendserver/blob/main/cli_client/bin/client.dart"
click node_react_sdk "https://github.com/gracelium64/dartbackendserver/blob/main/react_sdk/src/client.ts"

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_main,node_server_cmd,node_admin_cmd,node_log_tail_cmd toneBlue
class node_http_server,node_crud_handlers,node_auth_service,node_rule_engine,node_password_utils toneAmber
class node_db_manager,node_migrations,node_sqlite_data,node_audit_logger,node_admin_tools,node_email_service toneMint
class node_flutter_sdk,node_cli_client,node_react_sdk toneRose
```

## Components

### Entry points

- [Main executable](https://github.com/gracelium64/dartbackendserver/blob/main/bin/main.dart): Dart CLI · Dispatches server and operator commands. · `bin/main.dart`
- [Server command](https://github.com/gracelium64/dartbackendserver/blob/main/bin/commands/server_command.dart): command · `bin/commands/server_command.dart`
- [Admin command](https://github.com/gracelium64/dartbackendserver/blob/main/bin/commands/admin_command.dart): command · `bin/commands/admin_command.dart`
- [Log-tail command](https://github.com/gracelium64/dartbackendserver/blob/main/bin/commands/log_tail_command.dart): command · `bin/commands/log_tail_command.dart`

### Backend runtime

- [HTTP server](https://github.com/gracelium64/dartbackendserver/blob/main/lib/server.dart): Shelf REST API · Routes health, auth, CRUD, admin SQL, and media requests. · `lib/server.dart`
- [CRUD handlers](https://github.com/gracelium64/dartbackendserver/blob/main/lib/api/crud_handlers.dart): API layer · `lib/api/crud_handlers.dart`
- [Auth service](https://github.com/gracelium64/dartbackendserver/blob/main/lib/auth/auth_service.dart): JWT auth · Handles signup, login, token issuance, and refresh. · `lib/auth/auth_service.dart`
- [Rule engine](https://github.com/gracelium64/dartbackendserver/blob/main/lib/auth/rule_engine.dart): authorization · `lib/auth/rule_engine.dart`
- [Password utilities](https://github.com/gracelium64/dartbackendserver/blob/main/lib/auth/password_utils.dart): credential security · `lib/auth/password_utils.dart`

### Data and operations

- [Database manager](https://github.com/gracelium64/dartbackendserver/blob/main/lib/database/db_manager.dart): persistence layer · SQLite access for collections, documents, users, media, and audit records. · `lib/database/db_manager.dart`
- [Migrations](https://github.com/gracelium64/dartbackendserver/blob/main/lib/database/migrations.dart): schema evolution · `lib/database/migrations.dart`
- [SQLite database](https://github.com/gracelium64/dartbackendserver/blob/main/data/shadow_app.db): local system of record · `data/shadow_app.db`
- [Audit logger](https://github.com/gracelium64/dartbackendserver/blob/main/lib/logging/logger.dart): operational logging · `lib/logging/logger.dart`
- [Admin workflows](https://github.com/gracelium64/dartbackendserver/blob/main/bin/helpers/document_operations.dart): operator tooling · Manages documents, users, and reports. · `bin/helpers/document_operations.dart`
- [Email service](https://github.com/gracelium64/dartbackendserver/blob/main/lib/logging/email_service.dart): Gmail SMTP integration · Delivers operator reports through Gmail SMTP. · `lib/logging/email_service.dart`

### Client surfaces

- [Flutter SDK](https://github.com/gracelium64/dartbackendserver/blob/main/flutter_sdk/lib/shadow_app.dart): Dart client package · Provides initialization and collection façade. · `flutter_sdk/lib/shadow_app.dart`
- [Remote CLI client](https://github.com/gracelium64/dartbackendserver/blob/main/cli_client/bin/client.dart): client · `cli_client/bin/client.dart`
- [React SDK](https://github.com/gracelium64/dartbackendserver/blob/main/react_sdk/src/client.ts): TypeScript client · `react_sdk/src/client.ts`

## Connections

- Main executable → Server command: dispatches
- Main executable → Admin command: dispatches
- Main executable → Log-tail command: dispatches
- Server command → HTTP server: starts
- HTTP server → Auth service: authenticates
- Auth service → Password utilities: verifies passwords
- HTTP server → Rule engine: authorizes
- HTTP server → CRUD handlers: routes CRUD
- CRUD handlers → Database manager: persists documents
- HTTP server → Database manager: admin SQL and media
- Database manager → Migrations: initializes schema
- Database manager → SQLite database: reads and writes
- HTTP server → Audit logger: emits events
- Log-tail command → Audit logger: tails
- Admin command → Admin workflows: runs
- Admin workflows → Database manager: maintains data
- Admin workflows → Email service: delivers reports
- Flutter SDK → HTTP server: REST calls
- Remote CLI client → HTTP server: REST calls
- React SDK → HTTP server: REST calls
