What Is the Directory Structure of Open-Notebook? A Complete Guide to the Three-Tier Codebase
The open-notebook repository follows a modular three-tier architecture with frontend/ (Next.js/React), api/ (FastAPI), and open_notebook/ (core Python library) as top-level directories, organized to separate concerns between the UI layer, REST API, and domain logic.
Open Notebook is an open-source AI-powered notebook application maintained by lfnovo. Understanding the directory structure of open-notebook is essential for contributors navigating its frontend, REST API, and database layers, as the codebase intentionally separates concerns into distinct, testable packages.
High-Level Repository Layout
The root directory organizes the application into six primary groups. This structure supports the three-tier architecture (frontend → API → database) while keeping documentation and deployment configurations accessible.
open-notebook/
├── frontend/ # Next.js/React UI (TypeScript)
├── api/ # FastAPI REST layer (Python)
├── open_notebook/ # Core backend library (domain, graphs, AI, DB)
├── docs/ # User & developer documentation
├── examples/ # Docker-Compose starter files
├── tests/ # Pytest suite (backend) & Jest/Vitest (frontend)
├── .env.example # Template for required env vars
├── Dockerfile # Container images for API
├── docker-compose.yml # Multi-service Docker config
├── README.md # Project summary & quick-start guide
└── CONFIGURATION.md # All configurable options
Each top-level directory maintains its own CLAUDE.md file containing architecture-specific notes for that layer.
Frontend Directory: Next.js UI Layer
The frontend/ directory houses the TypeScript/React user interface built on Next.js. This tier handles all client-side rendering, state management, and API consumption.
Key Subdirectories
src/– React components, custom hooks, and utility functions. Containssrc/components/layout/AppSidebar.tsxand shared UI elements.app/– Next.js route definitions using the App Router pattern. Entry points includeapp/page.tsx(landing) andapp/layout.tsx(root layout).public/– Static assets including icons and images such aspublic/logo.svg.tests/– Vitest/Jest test suites validating component behavior, with examples likeAppSidebar.test.tsx.
Configuration Files
The frontend tier includes package.json for NPM dependencies, next.config.ts for framework settings, and tailwind.config.ts for styling. The frontend/README.md provides setup instructions specific to the UI layer.
API Directory: FastAPI REST Layer
The api/ directory implements the RESTful middleware that bridges the frontend and core library. Built with FastAPI, this layer handles HTTP routing, authentication, and request validation.
Structural Components
routers/– Individual FastAPI routers for each domain object. Key files includerouters/sources.pyfor content ingestion androuters/models.pyfor AI provider configuration.*_service.pyfiles – Business-logic layer separating API concerns from domain operations. Examples includesources_service.pyandmodels_service.py.main.py– FastAPI application bootstrap located atapi/main.py, responsible for CORS configuration and router mounting.auth.py– Simple password-based authentication for development environments.client.py– Helper utilities for internal HTTP calls and health checks.
The api/CLAUDE.md file documents architectural decisions specific to the REST layer.
Core Library: Domain Logic and AI Workflows
The open_notebook/ package contains the domain-driven backend logic, including Pydantic models, LangGraph workflows, and database abstractions.
Module Breakdown
domain/– Pydantic models and business logic for entities like notebooks, sources, and credentials. Key files includedomain/notebook.pyanddomain/credential.py.graphs/– LangGraph workflow definitions orchestrating AI interactions. Containsgraphs/chat.pyfor conversational flows andgraphs/ask.pyfor query processing.ai/– Multi-provider AI abstraction supporting 18+ LLM providers. Central files includeai/models.pyfor model selection andai/provision.pyfor provider instantiation.utils/– Helper utilities for text processing, encryption, and embeddings. Examples includeutils/chunking.pyandutils/encryption.py.database/– SurrealDB repository pattern and async migrations. Thedatabase/repository.pyfile provides the async abstraction for all database operations, whiledatabase/async_migrate.pyhandles schema updates.config.py– Global configuration management loading environment variables across the core library.
Supporting Directories
Documentation (docs/)
Markdown-based documentation covering installation, configuration guides, and API references. The docs/5-CONFIGURATION/ai-providers.md file explains LLM provider wiring.
Examples (examples/)
Ready-to-run Docker Compose configurations for different deployment scenarios:
docker-compose-dev.yml– Development stack with SurrealDB, API, and UIdocker-compose-ollama.yml– Local LLM deployment via Ollamadocker-compose-full-local.yml– Fully self-contained deployment
Tests (tests/)
Backend tests written in Pytest exercising API endpoints and graph logic, alongside frontend component tests. Representative files include test_models_api.py and ConfirmDialog.test.tsx.
Root Configuration Files
The repository root contains essential configuration and metadata:
.env.example– Template for required environment variables without secretsDockerfileandDockerfile.single– Multi-stage container builds for the API servicepyproject.toml– Poetry packaging configuration and Python dependenciesMakefile– Convenience targets for testing, linting, and development workflowsCONFIGURATION.md– Comprehensive reference for all environment variables and defaultsCHANGELOG.md– Release notes and version history
Practical Code Examples
Importing Core Domain Objects
To interact with the database layer from the core library:
from open_notebook.domain.notebook import Notebook
from open_notebook.database.repository import Repository
async def get_notebook(notebook_id: str) -> Notebook:
repo = Repository()
return await repo.notebook.get(notebook_id)
Calling the REST API
Accessing the sources endpoint directly:
curl -X GET "http://localhost:5055/sources/12345" \
-H "accept: application/json"
The router definition resides in api/routers/sources.py.
Using Frontend Components
Importing UI components in the Next.js application:
import { ModelSelector } from '@/components/source/ModelSelector';
export default function SettingsPage() {
return (
<section>
<h2>AI Model Settings</h2>
<ModelSelector />
</section>
);
}
The component source is located at frontend/src/components/source/ModelSelector.tsx.
Summary
The directory structure of open-notebook reflects its three-tier architecture through clear separation of concerns:
frontend/contains the Next.js/React UI tier with TypeScript components and Vitest testsapi/houses the FastAPI REST layer with routers inrouters/and business logic in*_service.pyfilesopen_notebook/provides the core Python library with domain models, LangGraph workflows ingraphs/, and SurrealDB abstractions indatabase/docs/andexamples/offer documentation and deployment configurations- Root configuration files like
CONFIGURATION.mdand.env.examplegovern environment setup
This modular layout enables independent testing of each tier and simplifies navigation for contributors working on specific layers.
Frequently Asked Questions
What is the purpose of the open_notebook/ directory?
The open_notebook/ directory serves as the core Python library containing domain logic, AI workflows, and database abstractions. It houses Pydantic models in domain/, LangGraph definitions in graphs/, and the SurrealDB repository pattern in database/, functioning as the backend brain that the FastAPI layer consumes.
Where are the frontend components located in open-notebook?
Frontend components reside in frontend/src/components/, with route definitions in frontend/app/ following the Next.js App Router convention. Static assets live in frontend/public/, while configuration files like next.config.ts and tailwind.config.ts sit in the frontend/ root.
How is the API layer structured in the open-notebook repository?
The API layer in api/ follows FastAPI conventions with domain-specific routers in routers/ (such as sources.py and models.py), service modules handling business logic, and main.py bootstrapping the application with CORS and middleware configurations. The *_service.py pattern separates HTTP handling from domain operations.
What database does open-notebook use and where is it configured?
Open Notebook uses SurrealDB as its primary database, with async repository patterns defined in open_notebook/database/repository.py. Schema migrations are handled by database/async_migrate.py, while connection settings are typically configured via environment variables referenced in open_notebook/config.py and the root .env.example file.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →