PrimeLoader System Architecture
Multi-Tenant Hydrology Sensor SaaS Platform
Delphi
Spring4D
XData
OAuth2
Linux Daemon
Overview
PrimeLoader is a Linux daemon-based multi-tenant application server built with Delphi. It manages multiple tenant databases, dynamic plugin loading, and OAuth2 authentication.
Key Patterns:
- Dependency Injection — Spring4D container for IoC
- Multi-Tenancy — Separate database per tenant with connection pooling
- Plugin Architecture — Dynamic .so library loading at runtime
- Factory Pattern — Tenant and Plugin factories
- Thread-Safe Pooling — Critical sections protecting shared resources
Class Diagram
%%{init: {'theme': 'dark'}}%%
classDiagram
direction TB
class PrimeLoader_Apache {
-SID: Integer
-ControllerModule: TMainServer
+RunDaemon()
+Daemonize()
+StartServer()
}
class IServer {
+HttpServer
+TenantFactory
+PluginFactory
+CreateServer()
+StartServer()
}
class TServer {
-FHTTPServer
-FTenantFactory
+CreateServer()
}
class TMainServer {
+AdminServer: TXDataServer
+InitialiseServer()
+LoadPlugins()
}
class TTenantPoolManager {
-FPools: TDictionary
-FLock: TCriticalSection
+GetPool()
+Shutdown()
}
class TTenantConnectionPool {
-FPool: TList
-FInUse: TList
+Acquire()
+Release()
}
class IPluginFactory {
+ManagePluginLibraries()
+FindPlugin()
}
PrimeLoader_Apache --> IServer
PrimeLoader_Apache --> TMainServer
IServer <|.. TServer
TServer --> TTenantPoolManager
TMainServer --> TTenantPoolManager
TTenantPoolManager o-- TTenantConnectionPool
TServer --> IPluginFactory
Startup Sequence
%%{init: {'theme': 'dark'}}%%
sequenceDiagram
participant OS as Linux
participant D as PrimeLoader
participant IC as DI Container
participant S as IServer
participant MS as TMainServer
participant TPM as PoolManager
OS->>D: Start
D->>D: Daemonize()
D->>IC: Register interfaces
D->>IC: Resolve IServer
IC-->>S: TServer
D->>MS: Create TMainServer
MS->>MS: LoadConfigs()
D->>S: CreateServer()
D->>MS: InitialiseServer()
MS->>TPM: Initialize pools
MS->>MS: LoadPlugins()
D->>S: StartServer()
HTTP Request Flow
%%{init: {'theme': 'dark'}}%%
sequenceDiagram
participant C as Client
participant H as HTTP Server
participant JWT as JWT Middleware
participant TPM as PoolManager
participant Pool as ConnectionPool
participant Svc as Service
C->>H: Request
H->>JWT: Validate Token
JWT->>TPM: GetPool(tenant)
TPM-->>JWT: Pool
JWT->>Pool: Acquire()
Pool-->>JWT: Connection
JWT->>Svc: Execute
Svc-->>JWT: Response
JWT->>Pool: Release()
JWT-->>C: Response
Component Reference
Core
PrimeLoader_Apache
Main daemon entry point.
PRIMELOADER/PrimeLoader_Apache.dpr
TServer
HTTP server, factories, modules.
COMMON/SERVER/OBJECTS/Obj.Server.pas
TMainServer
Primary DataModule controller.
COMMON/DATAMODULES/BackOffice.Data.Main.pas
Multi-Tenancy
TTenantPoolManager
Singleton managing all pools.
COMMON/USERS/OBJECTS/Obj.Tenant.PoolManager.pas
TTenantConnectionPool
Per-tenant thread-safe pool.
COMMON/USERS/OBJECTS/Obj.Tenant.ConnectionPool.pas
TTenantFactory
Creates/manages tenants.
COMMON/FACTORIES/OBJECTS/Obj.Factory.Tenant.pas
Interface Summary
| Interface | Implementation | Purpose |
|---|---|---|
| IServer | TServer | Application server |
| ITenant | TTenant | Tenant entity |
| ITenantFactory | TTenantFactory | Tenant creation |
| IPlugin | TPlugin | Plugin entity |
| IPluginFactory | TPluginFactory | Plugin management |