How gracelium64/dartbackendserver works
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: server.dart HTTP server · db_manager.dart Database manager · main.dart Main executable · document_operations.dart Admin workflows
Components 18
Entry points
- Main executable · Dispatches server and operator commands.
bin/main.dart - Server command
bin/commands/server_command.dart - Admin command
bin/commands/admin_command.dart - Log-tail command
bin/commands/log_tail_command.dart
Backend runtime
- HTTP server · Routes health, auth, CRUD, admin SQL, and media requests.
lib/server.dart - CRUD handlers
lib/api/crud_handlers.dart - Auth service · Handles signup, login, token issuance, and refresh.
lib/auth/auth_service.dart - Rule engine
lib/auth/rule_engine.dart - Password utilities
lib/auth/password_utils.dart
Data and operations
- Database manager · SQLite access for collections, documents, users, media, and audit records.
lib/database/db_manager.dart - Migrations
lib/database/migrations.dart - SQLite database
data/shadow_app.db - Audit logger
lib/logging/logger.dart - Admin workflows · Manages documents, users, and reports.
bin/helpers/document_operations.dart - Email service · Delivers operator reports through Gmail SMTP.
lib/logging/email_service.dart
Client surfaces
- Flutter SDK · Provides initialization and collection façade.
flutter_sdk/lib/shadow_app.dart - Remote CLI client
cli_client/bin/client.dart - React SDK
react_sdk/src/client.ts
Connections 20
- 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