How derailed-dash/rickbot-adk works
1. Repo shape: a multi-surface agent application
- This repository is a monorepo for a “Rickbot” multi-personality chatbot.
- The runtime surfaces are split into a Python backend, a Next.js frontend, and a Streamlit frontend, with Docker and Cloud Run-style deployment support around them.
2. Core backend is the central system boundary
- src/main.py is the backend entrypoint, exposing the API layer that the UIs talk to.
- The backend is the main orchestration boundary: it hosts the chat API, persona discovery, auth checks, rate limiting, and agent execution.
3. Agent layer: ADK-based persona chatbot
- src/rickbot_agent/ contains the agent domain logic:
- agent.py for the core agent setup
- personality.py for persona selection and behavior
- services.py and tools_custom.py for tool/service integration
- auth.py, auth_models.py, and auth_middleware.py for access control concerns
- The personas are data-driven from src/rickbot_agent/data/personalities.yaml and persona-specific system prompts in src/rickbot_agent/data/system_prompts/.
4. Frontend split: modern Next.js UI and older Streamlit UI
- src/nextjs_fe/ is the primary modern chat UI.
- src/streamlit_fe/ is a separate Streamlit interface, likely retained for lightweight access, demos, or internal workflows.
- This means the repo supports two independent presentation layers over the same backend/agent domain.
5. Next.js frontend talks to backend for personas and chat streaming
- The README says the Next.js UI fetches persona metadata from the backend /personas endpoint.
- Chat uses streaming responses over SSE for incremental agent output.
- The UI also supports file uploads and tool-status visibility, so the frontend is not just a simple message form; it renders agent execution state.
6. Authentication and authorization are first-class
- The presence of pages/api/auth/[...nextauth].ts, auth_middleware.py, and multiple auth-related tests indicates a split auth model:
- frontend session/auth handling in Next.js
- backend authorization enforcement in Python
- src/tests/integration/test_rbac_e2e.py suggests role/permission behavior is part of the runtime architecture, not just an add-on.
7. Shared utilities centralize cross-cutting concerns
- src/rickbot_utils/ contains reusable infrastructure-like code:
- configuration
- logging
- rate limiting
- secret handling
- This package sits between the app layer and deployment/environment concerns, so it likely provides the common plumbing used by both backend and tests.
8. External services and cloud dependencies shape the design
- The repo is clearly built around Google Cloud and Gemini/ADK:
- Gemini Developer API / Google GenAI SDK
- Google Cloud deployment via Terraform
- Firestore for persistence
- Cloud Storage for object/file artifacts
- Secret Manager for sensitive config
- Artifact Registry and build triggers for CI/CD
- The architecture therefore has a cloud-backed control plane for secrets/builds and a runtime data plane for chat/state/artifacts.
9. RAG/file-search capability is an explicit subsystem
- The README and notebooks indicate a File Search Store used for retrieval-augmented responses, especially for certain personas.
- notebooks/file_search_store.ipynb and related integration tests show that this is treated as a managed external capability, not embedded app state.
10. Deployment is container-first and environment-driven
- Multiple Dockerfiles exist:
- Dockerfile.api
- Dockerfile.streamlit
- Dockerfile.unified
- docker-compose.yml and Makefile support local orchestration, while deployment/terraform/ defines the cloud infrastructure.
- The existence of separate API, Streamlit, frontend, and unified images suggests deployment flexibility across isolated and combined runtime topologies.
11. CI/CD and release automation are part of the architecture
- .cloudbuild/ and .github/workflows/ show two automation paths:
- Cloud Build pipelines for staging/prod-style deployment
- GitHub Actions for dispatch/review/triage and related automation
- The repo is not just source code; it includes operational automation for validation and promotion.
12. Testing is layered across unit, integration, and UI
- src/tests/unit, src/tests/integration, and the Next.js test suite under src/nextjs_fe/__tests__ indicate clear separation:
- unit tests for local logic
- integration tests for cloud/service behavior
- frontend tests for UI state and interaction
- This mirrors the app boundaries and reinforces where the important seams are.
13. Auxiliary content supports operations and evolution
- conductor/ contains archived design/spec/plan artifacts and workflow notes, which look like project management or agent-guided development records rather than runtime code.
- docs/ and deployment/README.md carry the architectural rationale and environment-specific setup, so the repo’s “real architecture docs” are intentionally split from code.
14. Main end-to-end flow
- User interacts through either the Next.js UI or Streamlit UI.
- The UI authenticates the user and sends chat requests to the Python backend.
- The backend validates access, selects the appropriate persona, invokes the ADK-powered agent, optionally consults tools/RAG/file search, and streams the response back to the client.
- Deployment and secrets are managed separately through Cloud Build, Terraform, and Google Cloud services.
Main entry points: main.py Backend API · agent.py Agent Core · index.tsx Next.js UI · auth.py Access Control
Components 21
Runtime
Python backend, agent domain, and shared runtime plumbing
- Backend API · Main Python entrypoint exposing chat, personas, auth, streaming, and orchestration
src/main.py - Agent Core · Primary agent setup and execution boundary
src/rickbot_agent/agent.py - Persona Router · Selects and shapes persona behavior for each conversation
src/rickbot_agent/personality.py - Persona Data · YAML persona definitions and persona-specific system prompts
src/rickbot_agent/data/personalities.yaml - Access Control · Authentication, authorization, and request enforcement
src/rickbot_agent/auth.py - Auth Models · Shared auth and role model definitions
src/rickbot_agent/auth_models.py - Auth Middleware · Backend request interception and auth enforcement layer
src/rickbot_agent/auth_middleware.py - Tools & Services · Custom tools and service integrations used by the agent
src/rickbot_agent/tools_custom.py - Services · Agent-facing service orchestration helpers
src/rickbot_agent/services.py - Shared Utils · Configuration, logging, rate limiting, and secret helpers
src/rickbot_utils/config.py
Frontends
User-facing chat surfaces
- Next.js UI · Modern web chat surface with auth, personas, uploads, and streaming
src/nextjs_fe/pages/index.tsx - NextAuth API · Frontend session and auth callback route
src/nextjs_fe/pages/api/auth/[...nextauth].ts - Streamlit UI · Alternative Streamlit interface for lightweight access and workflows
src/streamlit_fe/app.py
Platform
Containers, cloud infra, and automation
- Terraform · Google Cloud infrastructure definitions for runtime, storage, secrets, and IAM
deployment/terraform/apis.tf - Cloud Build · Staging and production deployment pipelines
.cloudbuild/staging.yaml - GitHub Actions · Repository automation for review, triage, and dispatch workflows
.github/workflows/gemini-review.yml - Container Images · API, Streamlit, and unified Docker build targets
Dockerfile.unified - Local Compose · Local multi-service composition and developer startup support
docker-compose.yml
Quality
Testing and verification
- API Tests · Backend API, auth, RBAC, rate limiting, and streaming coverage
src/tests/integration/test_api.py - Agent Tests · Multi-turn agent, personas, retrieval, and tool-status coverage
src/tests/integration/test_rickbot_agent_multiturn.py - UI Tests · Next.js component and interaction coverage
src/nextjs_fe/__tests__/Chat.test.tsx
Connections 23
- Next.js UI → NextAuth API: auth session · Next.js UI relies on the auth route for session handling
- Next.js UI → Backend API: chat + personas · Fetches persona metadata and sends chat requests to the backend
- Streamlit UI → Backend API: chat API · Alternative presentation layer over the same backend
- Backend API → Agent Core: invoke · Backend orchestrates agent execution
- Backend API → Persona Router: select persona · Resolves persona metadata and behavior per request
- Backend API → Access Control: authorize · Enforces authentication and RBAC before execution
- Backend API → Tools & Services: tool calls · Delegates external actions and custom integrations
- Backend API → Shared Utils: plumbing · Uses shared config, logging, rate limits, and secrets helpers
- Agent Core → Persona Router: prompting · Uses persona selection and behavior rules
- Agent Core → Tools & Services: extensions · Calls services and custom tools during execution
- Persona Router → Persona Data: driven by · Persona logic is backed by YAML definitions and prompt files
- Access Control → Auth Models: models · Authorization logic uses shared auth model definitions
- Access Control → Auth Middleware: middleware · Request enforcement is applied through middleware
- Terraform → Container Images: build · Infrastructure is deployed from container images
- Terraform → Cloud Build: release · Cloud Build coordinates deployment flows
- Cloud Build → Terraform: apply · Pipelines promote configured infrastructure and services
- Local Compose → Backend API: local run · Compose supports local backend orchestration
- Local Compose → Next.js UI: local run · Compose supports local frontend orchestration
- GitHub Actions → API Tests: validate · Automation gates changes with backend checks
- GitHub Actions → UI Tests: validate · Automation gates changes with frontend checks
- API Tests → Backend API: covers · Integration tests exercise backend endpoints and runtime behavior
- Agent Tests → Agent Core: covers · Integration tests exercise the agent domain and retrieval paths
- UI Tests → Next.js UI: covers · Frontend tests exercise chat, auth, and UI state