โ† Core
In the workslicense: proprietary

tom_core_server

tom_core_server ยท v1.1.0

The server half of a Tom application: authentication, authorization, data sources, database migration, endpoints, transactions, object persistence, caching, and health checks over Shelf.

See License
Status
In the works
LOC
7.0k
Tests
216
Test LOC
1.6k

Overview

From the module readme.md file:

What it enables

No downstream modules declared yet.

Relationships

Standalone โ€” no declared relationships.

tom_core_server

> Attribution. The Tom Framework is developed by Peter Nicolai Alexis Kyaw. > These packages are proprietary and internal (publish_to: none).

Server-side runtime for the Tom Framework โ€” an HTTP host, an endpoint pipeline, and a relational persistence layer built on the platform-neutral kernel.

Overview

tom_core_server is the backend layer of the Tom Framework. It builds on tom_core_kernel (dependency injection, observable state, security, resources) and adds everything a service needs:

  • a shelf-based HTTP host (TomServer) with a middleware pipeline โ€”

request context, per-request IDs, authentication, logging, and JSON error mapping wrapped around a declarative endpoint router; - an ORM-style persistence layer โ€” repositories with type-safe queries built from expression operators, persistence annotations, and a query builder, over pluggable datasources (MariaDB/MySQL driver included); - versioned schema migrations and local/XA transaction coordination; - server configuration (typed config + YAML resources), an isolate-backed cache, authentication/authorization services, and health endpoints.

Because the barrel re-exports the kernel, a server app depends only on tom_core_server โ€” one import gives both the kernel API and the server stack.

Installation

This package is internal to the Tom workspace and consumed by path (it is publish_to: none), so there is no dart pub add line:

dependencies:
  tom_core_server:
    path: ../tom_core_server

Then import the single barrel โ€” it re-exports tom_core_kernel, tom_basics_console, and the MariaDB client, so you rarely import those directly:

import 'package:tom_core_server/tom_core_server.dart';

SDK: Dart ^3.10.0. Modules that use reflection (persistence entities, endpoint services) require dart run build_runner build to generate *.reflection.dart. The relational layer targets MariaDB/MySQL via mysql_client; the datasource, dialect, migration, and repository contracts are abstract, so other backends can be added.

Features

HTTP host & endpoints (server, endpoints)

TypeResponsibility
TomServerThe shelf-based HTTP host and its middleware pipeline
TomEndpoint / TomEndpointHandler / TomEndpointRouting Endpoint declaration and the request-handling pipeline
TomService / TomApiImplementation Annotations that turn a class into a routed API

Persistence (object_persistence, datasources)

TypeResponsibility
TomRepository / TomSqlDatasourceRepository CRUD + type-safe query repository
TomDbTable / TomDbColumn / TomEntityId / TomReference Entity-mapping annotations
TomQueryBuilder + Eq / And / Like / In / Gte โ€ฆ Type-safe query expressions
TomDataSource / MariaDbDatasource / MariaDbXADatasource Connection drivers (MariaDB/MySQL)
TomDbType family / TomStandardSqlDialect Typed columns and SQL rendering
TomSelect / TomCount / TomDelete Generated query objects

Schema & transactions (db_migration, transactions)

TypeResponsibility
TomDbMigrator / TomDbMigrations / TomDbVersion Versioned schema migrations (MariaDB adapter)
TomTransactionManager / TomTransaction / TomTransactionParticipant Local/XA transaction coordination

Platform services (configuration, cache, authentication, authorization, healthcheck, cmdline)

ModuleKey typesWhat it does
configuration TomBaseServerConfiguration , TomServerConfigResourceProvider , TomConfig<T> , TomYaml Typed config + YAML resources
cache TomCache, TomCacheManager Isolate-backed server-side cache
authentication TomAuthenticationService , TomAuthenticationData , TomAuthenticationAdaptor , Tom2FAAdaptor Authentication service + adaptor annotations
authorization TomAuthorizationCache Isolate-backed authorization cache
healthcheck TomHealthService, TomHealthServer, HealthAnalyzer Health endpoints and analyzers
cmdline TomArgs, TomEnvFile Argument parsing and .env loading
little_things TomServerException Server exception base (extends kernel TomException)

Quick start

Construct a server from a configuration and start it:

import 'package:tom_core_server/tom_core_server.dart';

void main(List<String> argv) {
  // `configuration` is your subclass of TomBaseServerConfiguration.
  final server = TomServer(configuration);
  server.start(); // HTTP host listening; endpoints routed
}

Parse command-line arguments and a .env file into typed values:

final config = TomArgs.fillFromArgs(argv, MyServerArgs()); // reflected key=value
final env = TomEnvFile.read('.env');                       // typed map

Example projects

Every module ships a runnable sample under example/, each mirrored by a test/<module>_test.dart suite. The connection-independent examples run without a database; the datasource/persistence drivers require a live MySQL and annotated entities and are documented in doc/.

SampleDemonstrates
example/server/ Building and starting TomServer
example/endpoints/ Declaring routed endpoints
example/object_persistence/ Repositories, annotations, query builder
example/datasources/ SQL-typed values and dialect rendering
example/db_migration/ Versioned schema migrations
example/transactions/ Local/XA transaction coordination
example/configuration/ Typed config + YAML resources
example/cache/Isolate-backed cache
example/authentication/ ยท example/authorization/ Auth service + authorization cache
example/healthcheck/ ยท example/cmdline/ ยท example/little_things/ Health, CLI, and exceptions

Run a single example:

dart run example/datasources/datasources_example.dart

Usage

Connecting a datasource (MariaDB/MySQL)

The MariaDB driver is configured by its connection fields, then connect() opens the live connection:

final ds = MariaDbDatasource()
  ..host = 'localhost'
  ..port = 3306
  ..username = 'tom'
  ..password = 'secret'
  ..databaseName = 'tomdb';
await ds.connect(); // throws MariadbDatasourceException on failure

> MySQL-in-Docker. The runnable end-to-end story โ€” a Docker Compose MySQL > plus bootstrap and migrations โ€” ships with the forthcoming > tom_core_samples/core_server_sample project (see the > repository map). This package provides the abstract > contracts and the MariaDB driver it builds on.

Repositories and type-safe queries

Repositories expose CRUD plus queries built from the expression operators (Eq, And, Like, In, Gte, โ€ฆ):

final all  = await repository.findAll();
final one  = await repository.findById(42);
final some = await repository.findByQuery(query, params);

Rendering SQL through the dialect

The dialect renders literals and bound-parameter placeholders, keeping untrusted input out of the SQL string:

final dialect = TomStandardSqlDialect();
print(dialect.text('abc'));     // 'abc'
print(dialect.objectOp([1, 2, 3])); // 1,2,3
print(dialect.p('userId'));     // :userId

Authentication, authorization, and health

TomAuthenticationService (with TomAuthenticationAdaptor / Tom2FAAdaptor annotations) drives login; TomAuthorizationCache caches authorization decisions on an isolate; TomHealthService / TomHealthServer expose health endpoints backed by HealthAnalyzers.

Architecture

                       TomServer (shelf host)
                            โ”‚
         middleware: context ยท request-id ยท auth ยท logging ยท JSON errors
                            โ”‚
                    TomEndpointRouting
                            โ”‚
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   object_persistence   transactions        services
   (TomRepository)   (TomTransactionMgr)  (auth ยท cache ยท health)
         โ”‚
     datasources  โ†’  MariaDbDatasource / MariaDbXADatasource (MySQL)
         โ”‚
     db_migration  โ†’  TomDbMigrator (versioned schema)
TypeResponsibility
TomServerHTTP host + middleware pipeline
TomEndpointRoutingMaps requests to endpoint handlers
TomRepositoryCRUD + type-safe query repository
TomDataSource / MariaDbDatasource Database connection driver
TomQueryBuilderBuilds type-safe queries from expression operators
TomDbMigratorApplies versioned schema migrations
TomTransactionManagerCoordinates local/XA transactions
TomBaseServerConfigurationServer configuration root

Ecosystem

tom_basics ยท tom_crypto ยท tom_reflection
                 โ”‚
          tom_core_kernel
                 โ”‚
          tom_core_server        โ† you are here
          (re-exports the kernel; HTTP, persistence, migrations)

tom_core_server sits directly on tom_core_kernel and re-exports it, so server apps get the full kernel API through one dependency. See the repository map for the full picture.

Further documentation

  • Per-module guides under doc/ โ€” one markdown file per module

(doc/object_persistence.md, doc/datasources.md, doc/endpoints.md, โ€ฆ). - tom_core_kernel โ€” the platform-neutral building blocks this layer is composed from. - tom_core_d4rt โ€” exposes the server API to d4rt scripts.

Status

  • Version: 1.1.0
  • Tests: 196 test cases across 14 module suites (run with testkit :test

or dart test). - License: proprietary โ€” see LICENSE. </content> </invoke>

License
Copyright (c) 2024-2026 Peter Nicolai Alexis Kyaw. All rights reserved.

This code is proprietary and confidential. Unauthorized copying, modification,
distribution, or use of this software, via any medium, is strictly prohibited.

For licensing inquiries, find me on LinkedIn under "Alexis Kyaw".