Startup¶
First-run seeding, startup variables and job cleanup served by the /erudi/startup routes.
src.domains.startup
¶
Startup domain - Application startup state management.
This domain manages persistent UI state flags that survive across application restarts, such as welcome popup display status. Uses singleton pattern for the StartupVariables entity.
Modules:
| Name | Description |
|---|---|
- endpoints |
FastAPI routes for startup state management. |
- repository |
Data access layer for StartupVariables entity. |
- schemas |
Pydantic models for request/response validation. |
Example
from src.domains.startup.repository import Startup_Variables_Repository from src.domains.startup.schemas import WelcomePopupResponse
In FastAPI endpoint¶
@router.get("/welcome-popup", response_model=WelcomePopupResponse) def check_popup(repo: Startup_Variables_Repository = Depends(get_startup_repository)): vars = repo.get_or_create() return WelcomePopupResponse(has_already_displayed=vars.welcome_popup_has_already_displayed)
src.domains.startup.endpoints
¶
FastAPI endpoints for startup state management.
This module provides REST API endpoints for managing application startup state, including UI flags that persist across app restarts (e.g., welcome popup status).
Architecture
- Endpoints use repository pattern via dependency injection.
- Pydantic schemas validate all request/response data.
- Structured logging for traceability.
- Proper error handling with domain-specific exceptions.
Endpoints
GET /startup/welcome-popup - Check and update welcome popup display status.
Example
curl http://127.0.0.1:27182/erudi/startup/welcome-popup {"has_already_displayed": false}
get_startup_repository(db=Depends(get_db))
¶
FastAPI dependency injection factory for Startup_Variables_Repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Session
|
SQLAlchemy session (injected by FastAPI via Depends(get_db)). |
Depends(get_db)
|
Returns:
| Name | Type | Description |
|---|---|---|
Startup_Variables_Repository |
Startup_Variables_Repository
|
Configured repository instance. |
Source code in backend/src/domains/startup/endpoints.py
get_welcome_popup_status(startup_repo=Depends(get_startup_repository), db=Depends(get_db))
async
¶
Check welcome popup display status and mark as shown if first time.
Implements "check-and-set" logic: returns False on first call (popup should show), then sets flag to True. Subsequent calls return True (popup already shown).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
startup_repo
|
Startup_Variables_Repository
|
Injected startup variables repository. |
Depends(get_startup_repository)
|
db
|
Session
|
Database session for transaction control. |
Depends(get_db)
|
Returns:
| Name | Type | Description |
|---|---|---|
WelcomePopupResponse |
{"has_already_displayed": bool} |
Raises:
| Type | Description |
|---|---|
DatabaseException
|
If database operation fails. |
Example
First call: GET /startup/welcome-popup → {"has_already_displayed": false} Second call: GET /startup/welcome-popup → {"has_already_displayed": true}
Source code in backend/src/domains/startup/endpoints.py
src.domains.startup.repository
¶
Data access layer for StartupVariables entity.
This module provides the repository class following the Repository pattern for database operations on startup state variables. The repository encapsulates all SQLAlchemy queries and database interactions for the singleton StartupVariables entity.
Architecture
- Startup_Variables_Repository: Singleton operations for startup state management.
Repository Pattern Benefits
- Single source of truth for data access logic.
- Easy to mock for testing.
- Clear separation between business logic (services) and data access.
- Consistent error handling and logging.
Example
from src.domains.startup.repository import Startup_Variables_Repository
In endpoint or service¶
startup_repo = Startup_Variables_Repository(db) vars = startup_repo.get_or_create()
Startup_Variables_Repository(db)
¶
Repository for StartupVariables entity database operations.
Handles all operations for the singleton StartupVariables entity, which stores persistent UI state flags across app restarts (e.g., welcome popup display status).
Attributes:
| Name | Type | Description |
|---|---|---|
db |
SQLAlchemy database session (injected by FastAPI). |
Example
startup_repo = Startup_Variables_Repository(db) vars = startup_repo.get_or_create() startup_repo.mark_welcome_popup_displayed(vars)
Initialize repository with database session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Session
|
SQLAlchemy session for database operations. |
required |
Source code in backend/src/domains/startup/repository.py
get_or_create()
¶
Retrieve the singleton StartupVariables record, creating if absent.
Returns:
| Name | Type | Description |
|---|---|---|
StartupVariables |
StartupVariables
|
The singleton startup state entity. |
Note
This is a singleton entity - only one row should exist in the table. Creates with default values (welcome_popup_has_already_displayed=False) if missing.
Source code in backend/src/domains/startup/repository.py
get_welcome_popup_status()
¶
Check if welcome popup has already been displayed to user.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if popup was already shown, False if first time. |
Source code in backend/src/domains/startup/repository.py
mark_welcome_popup_displayed(vars)
¶
Mark welcome popup as displayed (set flag to True).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vars
|
StartupVariables
|
StartupVariables entity to update. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StartupVariables |
StartupVariables
|
Updated entity (not yet committed, use flush()). |
Source code in backend/src/domains/startup/repository.py
reset(vars)
¶
Reset all startup variables to default values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vars
|
StartupVariables
|
StartupVariables entity to reset. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StartupVariables |
StartupVariables
|
Reset entity (not yet committed, use flush()). |
Source code in backend/src/domains/startup/repository.py
update_field(vars, field, value)
¶
Update a specific field on the StartupVariables entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vars
|
StartupVariables
|
StartupVariables entity to update. |
required |
field
|
str
|
Name of the field to update. |
required |
value
|
New value for the field. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
StartupVariables |
StartupVariables
|
Updated entity (not yet committed, use flush()). |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If field does not exist on entity. |
Source code in backend/src/domains/startup/repository.py
src.domains.startup.schemas
¶
Pydantic validation schemas for startup state management.
This module defines data transfer objects (DTOs) for the startup domain, handling UI state persistence flags across application restarts.
Schema Purpose: - WelcomePopupResponse: Response indicating if welcome popup should be shown.
Example
from src.domains.startup.schemas import WelcomePopupResponse from fastapi import FastAPI
app = FastAPI()
@app.get("/startup/welcome-popup", response_model=WelcomePopupResponse) def check_welcome_popup(): return {"has_already_displayed": True}
WelcomePopupResponse
¶
Bases: BaseModel
Response schema for welcome popup display status.
Indicates whether the welcome popup has already been shown to the user. Used by frontend to determine if popup should be displayed.
Attributes:
| Name | Type | Description |
|---|---|---|
has_already_displayed |
bool
|
True if popup was already shown, False if first time. |
Example
response = WelcomePopupResponse(has_already_displayed=False) print(response.has_already_displayed) False
Config
¶
Pydantic configuration for WelcomePopupResponse model.
Enables JSON schema generation for OpenAPI documentation.