Repository Structure¶
Document status: Architecture-informed reference. Verify directory names, filenames, and implementation details against the active application checkout before treating this page as a definitive source-code inventory.
This guide explains how to navigate the WhiteLotus AI codebase, identify the correct area for an engineering change, and trace functionality across service boundaries.
WhiteLotus AI follows a multi-service architecture that includes a Next.js frontend, Python backend services, AI orchestration, retrieval-augmented generation (RAG), external integrations, and supporting infrastructure.
Documentation scope
This page describes known architectural responsibilities and a repeatable method for inspecting the repository. It does not assert that every listed directory, file, or configuration artifact exists in the active branch.
The application source and documentation may reside in separate repositories.
1. Repository at a glance¶
The repository map should be derived from the checked-out source rather than maintained as a manually assumed directory tree.
The following diagram illustrates the logical architecture and investigation boundaries. It is not a verified directory listing or a complete runtime deployment diagram.
%%{init: {
"flowchart": {
"htmlLabels": true,
"nodeSpacing": 50,
"rankSpacing": 65,
"useMaxWidth": true
},
"themeVariables": {
"fontSize": "18px",
"lineColor": "#9CA3AF"
}
}}%%
flowchart TB
DEV["Developer"]
subgraph CLIENT["Client Layer"]
direction TB
FE["Next.js Frontend"]
end
subgraph BACKEND["Backend Services"]
direction TB
API["REST API Gateway"]
CHAT["Chat and AI Orchestration"]
SESSION["Session Service"]
USER["User Service"]
RAG["RAG Service"]
INTEG["Integrations Service"]
end
subgraph SHARED["Shared and Supporting Components"]
direction TB
LIB["Shared Backend Library"]
DATA[("Database and Vector Storage")]
CACHE[("Cache and Messaging")]
MODEL["Model Runtime"]
PROVIDERS["External Providers"]
end
DEV --> FE
FE -->|"HTTP API requests"| API
API -.-> CHAT
API -.-> SESSION
API -.-> USER
CHAT --> RAG
CHAT --> INTEG
CHAT --> LIB
SESSION --> LIB
USER --> LIB
RAG --> MODEL
RAG --> DATA
INTEG --> PROVIDERS
API --> CACHE
%% Pastel fills with category-specific colored outlines.
classDef developer fill:#F1F5F9,stroke:#64748B,stroke-width:1.5px,color:#334155
classDef client fill:#E8F0FE,stroke:#2563EB,stroke-width:1.5px,color:#23345B
classDef application fill:#EDE9FE,stroke:#7C3AED,stroke-width:1.5px,color:#3B267A
classDef support fill:#DDF5E5,stroke:#059669,stroke-width:1.5px,color:#16452B
classDef model fill:#FCE7F3,stroke:#DB2777,stroke-width:1.5px,color:#831843
classDef cache fill:#FFF2CC,stroke:#D97706,stroke-width:1.5px,color:#7C3E00
class DEV developer
class FE client
class API,CHAT,SESSION,USER,RAG,INTEG application
class LIB,DATA,PROVIDERS support
class MODEL model
class CACHE cache
%% Transparent containers preserve the active theme background.
style CLIENT fill:transparent,stroke:#2563EB,stroke-width:1.5px,color:inherit
style BACKEND fill:transparent,stroke:#7C3AED,stroke-width:1.5px,color:inherit
style SHARED fill:transparent,stroke:#059669,stroke-width:1.5px,color:inherit
%% Neutral connectors remain legible across themes.
linkStyle default stroke:#9CA3AF,stroke-width:1.3px
How to use this guide
- Finding code: Start with the component responsibility tables.
- Making a change: Trace the implementation, callers, authorization checks, and tests.
- Verifying structure: Run the inventory commands before documenting exact paths.
- Reviewing a pull request: Confirm that implementation, tests, configuration, and documentation remain consistent.
2. Repository organization¶
The table below maps known architectural components to their expected responsibilities. Directory names are candidate locations to verify, not guarantees about the current checkout.
| Component or path | Primary responsibility | What to inspect |
|---|---|---|
frontend/ |
Next.js user interface | App Router pages, components, API clients, frontend configuration, and npm scripts |
rest_api/ |
REST API gateway | Routes, validation, authentication, authorization, rate limiting, and service proxying |
chat/ |
Chat and AI orchestration | Chat endpoints, LangGraph workflow, graph nodes, state management, tool dispatch, and streaming |
session/ |
Session management | Session endpoints, ownership checks, persistence, and migrations |
rag/ |
Retrieval-augmented generation | Document ingestion, chunking, embeddings, vector retrieval, and relevance filtering |
user/ |
User management | User endpoints, data access, identity-related operations, and migrations |
integrations/ |
External application integrations | OAuth flows, connection management, provider adapters, tool operations, and credential handling |
sharedlib/ |
Shared backend functionality | Reusable schemas, utilities, common configuration, and shared abstractions |
docker-compose.yml or compose.yaml |
Local container orchestration, if present | Service definitions, networks, volumes, ports, and infrastructure dependencies |
Dockerfile files |
Container image definitions | Build context, dependencies, runtime configuration, and image size |
.gitlab-ci.yml |
GitLab CI/CD, if present | Linting, tests, image builds, registry publishing, and deployment stages |
WhitelotusAI_docs/ |
Documentation source, if colocated | Architecture, requirements, integrations, security, operations, and engineering guides |
zensical.toml |
Zensical configuration, if present | Navigation, theme, Markdown extensions, and site-build configuration |
Verify before relying on a path
A component's appearance in this table does not establish that its directory exists, that it contains a particular module, or that it owns every operation associated with that responsibility. Confirm the active branch and follow the actual implementation.
3. Find the right place to make a change¶
Use this task-oriented reference to choose an initial investigation point.
| Engineering task | Start by inspecting |
|---|---|
| Change a frontend page or component | Frontend routes, UI components, and API clients |
| Add or modify an API endpoint | The relevant backend service's route modules and request schemas |
| Investigate authentication or authorization | Gateway authentication, user-related operations, and service-level access checks |
| Change conversation processing | Chat endpoints, graph construction, and orchestration state |
| Modify LangGraph nodes or tool dispatch | Graph nodes, tool registry, dispatch logic, and shared abstractions |
| Add or change an integration | Provider adapter, connection lifecycle, tool registration, and orchestration integration |
| Enforce read-only integration behavior | Provider operations, registered tools, OAuth scopes, and server-side authorization |
| Change document retrieval | RAG ingestion, embedding configuration, vector queries, and access filters |
| Modify session persistence | Session data-access logic, models, and migrations |
| Change shared backend behavior | Shared library implementation and all affected consumers |
| Change service startup | Service entry points, dependency manifests, Dockerfiles, and Compose configuration |
| Update automated tests | Relevant unit, API, integration, and regression tests |
| Change CI/CD behavior | The verified pipeline configuration and related build scripts |
| Update documentation | Documentation source, navigation configuration, and applicable Markdown extensions |
Trace the complete execution path
A feature may span multiple services. Before changing it, identify its entry point, downstream calls, persistence layer, authorization boundary, error handling, and tests. Avoid modifying only the first matching file.
4. Generate a verified repository inventory¶
Run the following commands from the application repository root. Review their output locally before adding concrete filenames to this document.
4.1 List tracked and untracked source files¶
find . -maxdepth 3 \
\( -path './.git' \
-o -path './.venv' \
-o -path './venv' \
-o -path './node_modules' \
-o -path './__pycache__' \
-o -path './site' \
-o -path './dist' \
-o -path './build' \) -prune \
-o -type f -print | sort
This command lists files up to three directory levels deep while excluding common generated directories. It does not guarantee that sensitive files are excluded.
4.2 List top-level directories¶
find . -maxdepth 2 -type d \
-not -path './.git*' \
-not -path './.venv*' \
-not -path './venv*' \
-not -path './node_modules*' \
-not -path './__pycache__*' \
-not -path './site*' \
| sort
Use this output to check which service directories actually exist and how the repository is organized.
4.3 Locate development and build manifests¶
find . -maxdepth 3 \
\( -name Makefile \
-o -name pyproject.toml \
-o -name requirements.txt \
-o -name package.json \
-o -name Dockerfile \
-o -name compose.yaml \
-o -name docker-compose.yml \
-o -name .gitlab-ci.yml \) \
-type f -print | sort
These files help establish the available development commands, dependency boundaries, container build definitions, and CI/CD configuration.
Protect sensitive files
- Do not publish environment-file contents, credentials, access tokens, private keys, or OAuth secrets.
- Inspect filenames for database dumps, local datasets, logs, and other sensitive artifacts before sharing an inventory.
- Exclude virtual environments, caches, build output, and local data from published repository maps.
- Remember that a filename filter is not a complete security control.
5. Inspect each service consistently¶
Do not assume that every Python service has the same directory layout, startup command, dependency configuration, or migration strategy.
For each verified service, record the following elements where applicable.
| Element | Purpose | Verification target |
|---|---|---|
| Application entry point | Creates and configures the application | Startup module and server command |
| Route modules | Define HTTP endpoints and request handling | Router registration and endpoint definitions |
| Schemas | Validate requests and structure responses | Request and response models |
| Business logic | Implements service-specific behavior | Service functions and domain modules |
| Data access | Reads and writes persisted data | Repositories, queries, and database sessions |
| Models | Defines persisted entities or internal data structures | ORM and domain models |
| Configuration | Loads environment-dependent settings | Settings classes, environment templates, and defaults |
| Migrations | Defines database schema changes | Migration scripts and migration configuration |
| Tests | Verifies behavior and prevents regressions | Test files, fixtures, and test configuration |
| Development commands | Provides supported local workflows | Makefile, scripts, and project configuration |
| Dependencies | Defines runtime and development packages | Dependency manifests and lockfiles |
| Container definition | Defines the service image, if applicable | Dockerfile and build context |
Recommended inspection workflow¶
- Identify the service's actual entry point.
- Trace the route or event handler into its business logic.
- Locate data-access code and external dependencies.
- Identify configuration inputs and authorization checks.
- Find tests that cover the affected behavior.
- Verify the supported build and execution commands.
- Record only confirmed paths in the documentation.
6. AI orchestration and tool registry¶
The chat service owns conversation processing and AI orchestration. Its exact implementation should be identified from the active source rather than inferred from a high-level architecture diagram.
When auditing orchestration, locate the following responsibilities:
- Safety and context preparation: Input handling, safety checks, and conversation context.
- Intent classification and routing: Selection of the appropriate processing path.
- Authorization: Server-side verification of the user's identity and permissions.
- Tool registration: Declaration of available tools and supported operations.
- Tool dispatch: Selection and invocation of authorized operations.
- Model invocation: Construction of model inputs and processing of responses.
- Response formatting: Normalization of results and user-facing output.
- Streaming and errors: Event delivery, cancellation, and failure handling.
- Regression tests: Coverage for routing, authorization, tool execution, and streaming.
%%{init: {
"flowchart": {
"htmlLabels": true,
"nodeSpacing": 50,
"rankSpacing": 65,
"useMaxWidth": true
},
"themeVariables": {
"fontSize": "18px",
"lineColor": "#9CA3AF"
}
}}%%
flowchart TD
INPUT["Incoming Chat Request"]
SAFETY["Safety and Context"]
INTENT["Intent Classification"]
AUTH["Server-Side Authorization"]
DISPATCH["Tool Registry and Dispatch"]
EXEC["Authorized Operation"]
MODEL["Model Processing"]
FORMAT["Response Formatting"]
OUTPUT["Response or Stream"]
INPUT --> SAFETY
SAFETY --> INTENT
INTENT --> AUTH
AUTH --> DISPATCH
DISPATCH --> EXEC
EXEC --> MODEL
MODEL --> FORMAT
FORMAT --> OUTPUT
%% Pastel fills with category-specific colored outlines.
classDef boundary fill:#EDE9FE,stroke:#7C3AED,stroke-width:1.5px,color:#3B267A
classDef execution fill:#E8F0FE,stroke:#2563EB,stroke-width:1.5px,color:#23345B
classDef output fill:#DDF5E5,stroke:#059669,stroke-width:1.5px,color:#16452B
class INPUT,SAFETY,INTENT,AUTH boundary
class DISPATCH,EXEC,MODEL,FORMAT execution
class OUTPUT output
%% Neutral connectors remain legible across themes.
linkStyle default stroke:#9CA3AF,stroke-width:1.3px
Diagram note: This is an illustrative investigation model, not a verified representation of the exact production graph, node order, or error branches. Confirm the actual execution sequence in the current implementation.
Tool registration is not authorization
Finding a provider adapter or registered tool does not prove that an operation is reachable, correctly authorized, or restricted to read-only behavior.
Trace each operation from the user-facing intent through dispatch and authorization to the provider request. Verify that prohibited operations are rejected server-side, not merely hidden from the interface.
7. Integration implementations¶
The intended integration scope includes Gmail, Google Calendar, Google Drive, Jira, Slack, and Microsoft Teams.
For each provider, locate the verified implementation for the following areas.
| Area | What to verify |
|---|---|
| OAuth lifecycle | Authorization initiation, callback validation, state verification, and token exchange |
| Credential handling | Token storage, encryption where applicable, refresh behavior, and secret redaction |
| Connection management | Connection creation, ownership checks, status, and disconnection |
| Provider client | API requests, pagination, timeouts, and provider error handling |
| Tool registration | Available operations and the names exposed to orchestration |
| Permission enforcement | User identity, resource access, scopes, and server-side checks |
| Read-only restrictions | Allowed operations and explicit rejection of write operations |
| Testing | OAuth tests, mocked provider responses, authorization tests, and regression coverage |
Read-only means enforced at the backend
An integration is not demonstrably read-only merely because its interface exposes search or retrieval controls. Check the registered tools, provider operations, granted scopes, and server-side enforcement.
Document actual supported operations only after verifying their implementation and tests.
8. Configuration and secrets¶
Configuration should be documented from the service settings implementation, environment templates, and deployment definitions.
| Configuration area | Information to record |
|---|---|
| Environment variables | Variable name, purpose, required status, and safe default if one exists |
| Service endpoints | Base URLs, internal service addresses, and port configuration |
| Databases | Driver, connection settings, migration mechanism, and database selection |
| Cache and messaging | Redis, message broker, and related connection settings |
| Authentication | Token configuration, internal service authentication, and authorization settings |
| OAuth | Client configuration, callback URLs, scopes, and token-handling requirements |
| RAG | Embedding model, vector-store configuration, chunking, and retrieval thresholds |
| Model runtime | Provider, model identifier, context settings, and runtime dependencies |
| Observability | Logging, health checks, metrics, and error reporting |
| Testing and deployment | Test configuration, container settings, and CI/CD variables |
Use placeholders in examples rather than real secrets.
# Illustrative placeholders only; verify names against the actual settings.
DATABASE_URL=<database-connection-string>
REDIS_URL=<redis-connection-string>
INTERNAL_SERVICE_SECRET=<locally-configured-secret>
The names above are examples, not a declaration that these variables exist in the current application.
Document the contract, not the secret
A useful configuration reference explains what a variable controls, whether it is required, which service consumes it, and how to configure it safely. It must not reveal the deployed value.
9. Tests and quality assurance¶
Map the test suites to the behaviors and boundaries they verify. The following categories are audit targets; their existence and coverage must be confirmed from the repository.
| Test category | Verification objective |
|---|---|
| Unit tests | Validate individual functions and components |
| API tests | Verify request validation, response contracts, and error behavior |
| Integration tests | Verify interactions with databases and dependent services |
| Contract tests | Verify service and provider interface expectations |
| Security tests | Verify authentication, authorization, and credential protection |
| Routing tests | Verify intent classification and tool selection |
| Read-only regression tests | Verify that prohibited provider write operations are rejected |
| RAG tests | Verify retrieval relevance and document-access isolation |
| Streaming tests | Verify event delivery, cancellation, and error termination |
| Deployment checks | Verify startup configuration and dependency readiness |
Pull request verification checklist¶
Use this checklist when reviewing a change that affects service behavior.
- The implementation and its callers have been identified.
- Authentication and authorization boundaries have been reviewed.
- Relevant unit, API, and regression tests have been updated.
- External provider operations and error paths have been checked.
- Configuration changes are reflected in safe environment templates.
- Documentation and architecture diagrams match verified behavior.
- No credentials, local data, or generated artifacts have been committed.
- The relevant tests and documentation build complete successfully.
10. Deployment and CI/CD assets¶
Inspect the active repository and deployment configuration for the assets that actually exist.
| Asset | Review focus |
|---|---|
| Dockerfiles | Build context, dependency installation, runtime user, and image size |
| Compose configuration | Services, networks, volumes, ports, and health checks |
| GitLab CI/CD configuration | Actual stages, jobs, rules, test execution, and artifact handling |
| Environment templates | Required variables and safe example values |
| Database migrations | Schema evolution and deployment ordering |
| Runtime configuration | Process startup, worker settings, and service commands |
| Health checks | Readiness, liveness, and dependency availability |
| Infrastructure definitions | Provisioned resources, networking, and access controls |
| Deployment documentation | Supported release, rollback, and verification procedures |
Use the pipeline as the source of truth
Do not document a registry, deployment target, pipeline stage, or mandatory test job merely because it is common practice. Confirm it in the active CI/CD configuration and related deployment assets.
Keep local-development instructions distinct from production deployment procedures.
11. Ownership and change management¶
Apply the following rules when maintaining the repository and its documentation.
- Assign clear ownership to security-critical modules, authentication logic, and provider adapters.
- Preserve service boundaries and keep architecture diagrams aligned with verified source.
- Update tests when changing routes, tool dispatch, data access, or authorization.
- Treat generated code and build artifacts as generated content.
- Keep secrets, local databases, caches, virtual environments, and build output out of published repository maps.
- Update this guide when major directories, service responsibilities, or development workflows change.
- Verify paths and commands against the active branch before merging documentation changes.
12. Completion criteria¶
A repository map is ready to be treated as verified when all applicable criteria below have been met.
- Documented service directories have been checked against the active checkout.
- Application entry points and dependency manifests have been identified.
- Configuration, tests, migrations, and deployment assets have been located.
- Security-critical modules and integration boundaries have been mapped.
- No credentials or sensitive local paths are included.
- Confirmed facts are clearly distinguished from assumptions.
- All documented commands have been tested or their limitations stated.
- The documentation build completes successfully.
13. Build and maintain this page¶
After editing the page, run the documentation build from the documentation repository root, where zensical.toml is configured.
If the command reports an error, resolve it before merging. In particular, verify front matter, Markdown formatting, Mermaid rendering, internal links, and any admonition or extension syntax used by the site configuration.
Keep the guide useful
Review this page whenever repository layout, service ownership, configuration, tests, or deployment workflows change. Prefer a short, verified inventory over a detailed but speculative directory tree.