|
| 1 | +# CodeBox-AI Development Guide |
| 2 | + |
| 3 | +This guide contains instructions for developing, building, and testing the CodeBox-AI project using uv's native commands. |
| 4 | + |
| 5 | +## Build Commands |
| 6 | + |
| 7 | +### Environment Setup |
| 8 | +- Create virtual environment: `uv venv` |
| 9 | +- Activate virtual environment: |
| 10 | + - Unix/MacOS: `source .venv/bin/activate` |
| 11 | + - Windows: `.venv\Scripts\activate` |
| 12 | +- Install all dependencies: `uv sync` |
| 13 | +- Install with dev dependencies: `uv sync --extra dev` |
| 14 | +- Install with specific extras: `uv sync --extra "dev docs"` or `uv sync --extra "dev docs examples"` |
| 15 | + |
| 16 | +### Running the Application |
| 17 | + |
| 18 | +#### Standard Server |
| 19 | +```bash |
| 20 | +uv run -m codeboxai.main |
| 21 | +``` |
| 22 | + |
| 23 | +#### MCP Server Options |
| 24 | +- Standalone MCP server (for Claude Desktop): |
| 25 | + ```bash |
| 26 | + uv run mcp dev mcp_server.py |
| 27 | + ``` |
| 28 | + |
| 29 | +- Register with Claude Desktop: |
| 30 | + ```bash |
| 31 | + uv run mcp install mcp_server.py --name "CodeBox-AI" |
| 32 | + ``` |
| 33 | + |
| 34 | +- Combined FastAPI + MCP server: |
| 35 | + ```bash |
| 36 | + uv run run.py |
| 37 | + ``` |
| 38 | + |
| 39 | +- MCP server only: |
| 40 | + ```bash |
| 41 | + uv run run.py --mode mcp |
| 42 | + ``` |
| 43 | + |
| 44 | +### Testing |
| 45 | +- Run all tests: `uv run -m pytest` |
| 46 | +- Run single test: `uv run -m pytest tests/path/to/test.py::test_function_name -v` |
| 47 | +- Run tests with coverage: `uv run -m pytest --cov=codeboxai` |
| 48 | +- Generate coverage report: `uv run -m pytest --cov=codeboxai --cov-report=html` |
| 49 | + |
| 50 | +### Linting and Code Quality |
| 51 | +- Run all code quality checks: `uv run pre-commit run --all-files` |
| 52 | +- Individual checks: |
| 53 | + - Format code: `uv run -m black .` |
| 54 | + - Check imports: `uv run -m isort .` |
| 55 | + - Lint code: `uv run -m flake8` |
| 56 | + - Type checking: `uv run -m mypy .` |
| 57 | + |
| 58 | +### Project Management |
| 59 | +- Add a dependency: `uv add <package-name>` |
| 60 | +- Remove a dependency: `uv remove <package-name>` |
| 61 | +- Lock dependencies: `uv lock` |
| 62 | +- View dependency tree: `uv tree` |
| 63 | + |
| 64 | +### Building and Publishing |
| 65 | +- Build package: `uv run -m build` |
| 66 | +- Publish package: `uv publish` |
| 67 | + |
| 68 | +## Code Style Guidelines |
| 69 | + |
| 70 | +### Imports |
| 71 | +- Group in order: stdlib, third-party, local |
| 72 | +- Sort alphabetically within groups |
| 73 | +- Use `isort` for automatic sorting |
| 74 | + |
| 75 | +### Formatting |
| 76 | +- Use `black` for code formatting with default settings (line length 120 as configured in pyproject.toml) |
| 77 | +- Ensure consistent indentation (4 spaces) |
| 78 | + |
| 79 | +### Type Annotations |
| 80 | +- Use type hints for all function parameters and return values |
| 81 | +- Use `mypy` for type checking |
| 82 | + |
| 83 | +### Naming Conventions |
| 84 | +- `snake_case` for functions and variables |
| 85 | +- `CamelCase` for classes |
| 86 | +- `UPPER_CASE` for constants |
| 87 | + |
| 88 | +### Error Handling |
| 89 | +- Use specific exceptions with meaningful error messages |
| 90 | +- Log errors with appropriate level (error, warning, info) |
| 91 | +- Handle exceptions at appropriate levels |
| 92 | + |
| 93 | +### Docstrings |
| 94 | +- Use Google-style docstrings with Args/Returns sections: |
| 95 | +```python |
| 96 | +def function(param1: str, param2: int) -> bool: |
| 97 | + """Short description. |
| 98 | + |
| 99 | + Longer description if needed. |
| 100 | + |
| 101 | + Args: |
| 102 | + param1: Description of first parameter |
| 103 | + param2: Description of second parameter |
| 104 | + |
| 105 | + Returns: |
| 106 | + Description of return value |
| 107 | + |
| 108 | + Raises: |
| 109 | + ExceptionType: When and why this exception is raised |
| 110 | + """ |
| 111 | +``` |
| 112 | + |
| 113 | +### Validation |
| 114 | +- Use Pydantic validators for input validation |
| 115 | +- Follow existing validation patterns |
| 116 | + |
| 117 | +### Security |
| 118 | +- Ensure all user inputs are properly validated and sanitized |
| 119 | +- Use security best practices for Docker container isolation |
| 120 | + |
| 121 | +### Testing |
| 122 | +- Write pytest tests for all new functionality |
| 123 | +- Aim for high test coverage, especially for security-critical code |
| 124 | +- Write both unit tests and integration tests where appropriate |
| 125 | + |
| 126 | +## Example Workflow |
| 127 | + |
| 128 | +1. Create and activate environment: |
| 129 | +```bash |
| 130 | +uv venv |
| 131 | +source .venv/bin/activate # or .venv\Scripts\activate on Windows |
| 132 | +``` |
| 133 | + |
| 134 | +2. Install dependencies with development extras: |
| 135 | +```bash |
| 136 | +uv sync --extra "dev docs" |
| 137 | +``` |
| 138 | + |
| 139 | +3. Run pre-commit to set up git hooks: |
| 140 | +```bash |
| 141 | +uv run pre-commit install |
| 142 | +``` |
| 143 | + |
| 144 | +4. Make your code changes |
| 145 | + |
| 146 | +5. Run tests to verify changes: |
| 147 | +```bash |
| 148 | +uv run -m pytest |
| 149 | +``` |
| 150 | + |
| 151 | +6. Check code quality: |
| 152 | +```bash |
| 153 | +uv run -m black . |
| 154 | +uv run -m isort . |
| 155 | +uv run -m flake8 |
| 156 | +uv run -m mypy . |
| 157 | +``` |
| 158 | + |
| 159 | +7. Run the server locally: |
| 160 | +```bash |
| 161 | +uv run -m codeboxai.main |
| 162 | +``` |
0 commit comments