|
| 1 | +--- |
| 2 | +applyTo: "backend/**/*.py" |
| 3 | +--- |
| 4 | + |
| 5 | +## Backend |
| 6 | + |
| 7 | +The backend is built using Python with FastAPI as the web framework. |
| 8 | +It provides RESTful API endpoints for the frontend to interact with. |
| 9 | +It follows a modular architecture, separating concerns into different folders and files. |
| 10 | + |
| 11 | +### Libraries and Frameworks |
| 12 | + |
| 13 | +Dependencies are listed in pyproject.toml and managed with uv. |
| 14 | + |
| 15 | +- FastAPI for building the API (REST endpoints) |
| 16 | +- SQLAlchemy for database interactions |
| 17 | +- Alembic for database migrations |
| 18 | +- Pydantic for data validation |
| 19 | +- Omegaconf for configuration management |
| 20 | +- Loguru for logging |
| 21 | + |
| 22 | +### Databases |
| 23 | + |
| 24 | +The backend works with multiple databases: |
| 25 | + |
| 26 | +- PostgreSQL as the primary relational database |
| 27 | +- Weaviate for vector storage and similarity search |
| 28 | +- Elasticsearch for full-text search capabilities |
| 29 | +- Filesystem storage for storing uploaded files |
| 30 | + |
| 31 | +### Folder Structure |
| 32 | + |
| 33 | +- `/backend/configs`: Configuration files for different environments |
| 34 | +- `/backend/src`: Main application code |
| 35 | + - `/common`: Utility functions and helpers |
| 36 | + - `/core`: Core application logic. All core concepts are implemented here. |
| 37 | + - `/migrations`: Alembic database migrations |
| 38 | + - `/modules`: Application logic organized by feature. Modules use core services and systems to implement features. |
| 39 | + - `/repos`: Connections to external services, e.g., databases, file storage, etc. |
| 40 | + - `/systems`: Reusable systems that can be plugged into application logic |
| 41 | +- `/backend/tests`: Test cases for the backend code |
| 42 | + |
| 43 | +### File Naming Conventions |
| 44 | + |
| 45 | +The purpose of the file is reflected in its name. |
| 46 | +We use the following suffixes to indicate file types: |
| 47 | +- `*_endpoint.py`: API endpoint definitions |
| 48 | + |
| 49 | +- `*_dto.py`: Pydantic schemas (Data Transfer Objects) for request and response validation of payloads |
| 50 | +- `*_orm.py`: SQL Database models and schemas |
| 51 | +- `*_crud.py`: CRUD operations for database models (SQL) |
| 52 | + |
| 53 | +- `*_collection.py`: Weaviate collection schemas |
| 54 | +- `*_embedding_crud.py`: CRUD operations for embeddings stored in Weaviate |
| 55 | + |
| 56 | +- `*_elastic_index.py`: Elasticsearch index schemas |
| 57 | +- `*_elastic_crud.py`: CRUD operations for Elasticsearch indices |
| 58 | + |
| 59 | +- `*_system.py`: Reusable systems that encapsulate specific functionality |
| 60 | +- `*_service.py`: Business logic and service layer implementations |
| 61 | +- `*_repo.py`: Data access layer and repository implementations |
| 62 | +- `*_utils.py`: Utility functions and helpers |
| 63 | + |
| 64 | +### Coding Instructions |
| 65 | + |
| 66 | +When writing backend code, follow these guidelines: |
| 67 | + |
| 68 | +- Use type hints for function signatures and variable declarations. |
| 69 | +- Write docstrings for all public functions and classes. |
| 70 | +- Use loguru for logging sensible events and errors. |
0 commit comments