-
Notifications
You must be signed in to change notification settings - Fork 4
Closed
Labels
Description
Prerequisites
- I have searched the existing issues to avoid duplicates
- I understand that this is just a suggestion and might not be implemented
Problem Statement
Update the project’s folder structure to follow a Feature-Based Layered Architecture (Vertical Slice Architecture), with clear separation for chains, graphs, shared, and core folders. This will improve maintainability, scalability, and team collaboration.
Proposed Solution
Why
- High Cohesion: Related code stays together
- Low Coupling: Features are independent
- Easy Navigation: All code for a feature in one place
- Scalability: Easily add features without touching existing ones
- Team Collaboration: Teams can own entire features
Proposed Structure
src/
├── api/ # API Layer (Routes)
├── features/ # Feature Modules
│ ├── chat/
│ │ ├── api/
│ │ ├── services/
│ │ ├── repositories/
│ │ ├── models/
│ │ ├── agents/
│ │ ├── chains/
│ │ ├── tools/
│ │ ├── utils/
│ │ └── tests/
│ ├── rag/
│ │ ├── api/
│ │ ├── services/
│ │ ├── repositories/
│ │ ├── models/
│ │ ├── chains/
│ │ └── tests/
│ ├── documents/
│ ├── crawl/
│ ├── mcp_agents/
│ └── workflows/
│ ├── graphs/
├── core/ # Shared/Core Layer
│ ├── config/
│ ├── database/
│ ├── cache/
│ ├── langchain/
│ ├── logging/
│ └── exceptions/
├── shared/ # Shared Utilities
│ ├── schemas/
│ ├── utils/
│ └── constants/
└── main.py
- Include folders for:
chains(conversations, rag, agents)graphs(components, states, workflows)shared(schemas, utils, constants)core(database, cache, config, langchain, etc.)
Migration Guide
# 1. Create feature directories
mkdir -p src/features/chat/{api,services,repositories,models,chains,agents,tools,utils,tests}
# 2. Move files into appropriate feature/module folders
# Example:
mv src/api/endpoints/chat.py src/features/chat/api/routes.py
mv src/services/chat_service.py src/features/chat/services/
mv src/models/chat.py src/features/chat/models/
# 3. Update imports throughout the codebase
# e.g., from src.services.chat_service import ChatService
# -> from features.chat.services.chat_service import ChatService
# 4. Add __init__.py files where needed
touch src/features/chat/{__init__,api/__init__,services/__init__}.py
# 5. Repeat for other features/modulesAlternatives Considered
Best Practices
- Keep API thin: Move business logic to service layer
- Use dependency injection: For database, repositories, and services
- Keep features independent: Use interfaces/protocols where possible
- Shared/core layers: For cross-cutting concerns and utilities
Additional Context
References
- See issue description for architecture diagrams, migration tips, and code examples.
**Let's use this issue to discuss and track migration progress! **
Priority
High
Reactions are currently unavailable