Directory Structure
Understanding the organization of the Zyeta backend codebase
The Zyeta backend follows a well-organized directory structure that promotes separation of concerns and maintainability. This guide will help you navigate the codebase and understand the purpose of each directory.
Root Directory Structure
Source Code Structure (src/
)
Key Directories Explained
Services (src/services/
)
The services directory contains the core business logic of the application, organized by domain. Each service typically includes:
service.py
: The main service implementation with HTTP-exposed methodsschema.py
: Pydantic models for request/response validation- Additional domain-specific modules as needed
Services follow this pattern:
Base Service (__base/
)
The __base/
directory contains core service infrastructure:
acquire.py
: Dependency injection containermanager.py
: Service discovery and registration
Models (src/models/
)
The models directory contains SQLAlchemy ORM models representing database entities. Each file typically follows the *_model.py
naming convention and defines one or more related models.
Models follow this pattern:
Database (src/database/
)
Contains database connection management, session handling, and base model classes:
models.py
: Base model class and CRUD operationspostgres.py
: PostgreSQL connection setup__init__.py
: Exports session factories and utilities
Middlewares (src/middlewares/
)
Contains FastAPI middleware components that process requests and responses:
exceptions.py
: Global exception handlingratelimit.py
: Rate limiting middleware
Dependencies (src/dependencies/
)
Contains FastAPI dependencies for authentication, authorization, and other cross-cutting concerns:
security.py
: JWT bearer token authentication and RBAC
Libraries (src/libs/
)
Contains integrations with external services and reusable libraries:
s3/
: Amazon S3 compatible storagevectorstore/
: Vector embeddings and similarity searchtools_factory/
: Dynamic tool generation
Testing Structure (tests/
)
Documentation Structure (docs/
)
Configuration Files
alembic.copy.ini
Template for Alembic database migration configuration. This should be copied to alembic.ini
and updated with your database connection details.
.env.local
Template for environment variables. This should be copied to .env
and populated with your configuration values.
pyproject.toml
Contains project metadata, dependencies, and tool configurations using Poetry format.
ruff.toml
Configuration for the Ruff linter, specifying code style and quality rules.
mypy.ini
Configuration for Mypy type checking, ensuring strict type safety.
Working with the Codebase
Adding New Features
When adding new features, you typically need to:
- Create a new model in
src/models/
if you need database entities - Create a new service in
src/services/
with appropriate business logic - Update any dependencies or integrations as needed
- Add tests in the
tests/
directory - Update documentation in the
docs/
directory
Code Organization Principles
Zyeta follows these principles for code organization:
- Domain-driven organization: Code is organized by domain (auth, org, kb, etc.)
- Single responsibility: Each module has a clear, focused purpose
- Explicit dependencies: Dependencies are injected through the
Acquire
class - Clear interfaces: Services expose clear HTTP endpoints through the
http_exposed
property
Naming Conventions
- Service methods:
{http_method}_{resource}
- Example:
post_signup
,get_user
,put_update_profile
- Example:
- Model files:
{entity}_model.py
- Example:
user_model.py
,organization_model.py
- Example:
- Schema files:
schema.py
(within service directories) - Test files:
test_{component}.py
Next Steps
- Services Overview: Learn about the key services
- Database Design: Understand the data model
- Development Workflow: Learn the development process
Was this page helpful?