|
| 1 | +# Contributing to PRISM |
| 2 | + |
| 3 | +**Predictive Reliability & Intelligence for Smart Manufacturing** |
| 4 | + |
| 5 | +This guide covers everything you need to set up your local development environment, follow the project's code standards, and contribute effectively. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Table of Contents |
| 10 | + |
| 11 | +- [Prerequisites](#prerequisites) |
| 12 | +- [Local Setup](#local-setup) |
| 13 | +- [Development Tools](#development-tools) |
| 14 | +- [Pre-commit Hooks](#pre-commit-hooks) |
| 15 | +- [Running the Project](#running-the-project) |
| 16 | +- [Code Standards](#code-standards) |
| 17 | +- [Testing](#testing) |
| 18 | +- [Commit Message Convention](#commit-message-convention) |
| 19 | +- [Releasing](#releasing) |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## Prerequisites |
| 24 | + |
| 25 | +Make sure you have the following installed before starting: |
| 26 | + |
| 27 | +| Tool | Version | Purpose | |
| 28 | +|------|---------|---------| |
| 29 | +| Python | 3.10 or 3.11 | Backend runtime | |
| 30 | +| Node.js | 20+ | Frontend runtime | |
| 31 | +| Docker Desktop | Latest | Container builds | |
| 32 | +| Git | Any | Version control | |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## Local Setup |
| 37 | + |
| 38 | +### 1. Clone the repo |
| 39 | + |
| 40 | +```bash |
| 41 | +git clone https://github.com/arcoder181105/manufacturing-intelligence.git |
| 42 | +cd manufacturing-intelligence |
| 43 | +``` |
| 44 | + |
| 45 | +### 2. Set up Python environment |
| 46 | + |
| 47 | +```bash |
| 48 | +# Create a virtual environment |
| 49 | +python -m venv venv |
| 50 | + |
| 51 | +# Activate it |
| 52 | +# Windows: |
| 53 | +venv\Scripts\activate |
| 54 | +# Mac/Linux: |
| 55 | +source venv/bin/activate |
| 56 | + |
| 57 | +# Install app dependencies |
| 58 | +pip install -r requirements.txt |
| 59 | + |
| 60 | +# Install dev dependencies (linting, testing, pre-commit) |
| 61 | +pip install -r requirements-dev.txt |
| 62 | +``` |
| 63 | + |
| 64 | +### 3. Set up frontend |
| 65 | + |
| 66 | +```bash |
| 67 | +cd dashboard |
| 68 | +npm install |
| 69 | +cd .. |
| 70 | +``` |
| 71 | + |
| 72 | +### 4. Install pre-commit hooks |
| 73 | + |
| 74 | +```bash |
| 75 | +pre-commit install |
| 76 | +``` |
| 77 | + |
| 78 | +This installs git hooks that automatically run formatters before every commit — so CI never fails due to formatting issues. |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +## Development Tools |
| 83 | + |
| 84 | +All dev tools are listed in `requirements-dev.txt`. Here's what each one does: |
| 85 | + |
| 86 | +| Tool | Command | Purpose | |
| 87 | +|------|---------|---------| |
| 88 | +| `black` | `black src/ api/ tests/` | Auto-formats Python code | |
| 89 | +| `isort` | `isort src/ api/ tests/` | Sorts Python imports | |
| 90 | +| `flake8` | `flake8 src/ api/ tests/` | Lints for syntax errors | |
| 91 | +| `pytest` | `pytest tests/` | Runs the test suite | |
| 92 | +| `pre-commit` | runs automatically | Runs formatters before each commit | |
| 93 | + |
| 94 | +### Manually running formatters |
| 95 | + |
| 96 | +If you want to run them manually without committing: |
| 97 | + |
| 98 | +```bash |
| 99 | +# Fix import order |
| 100 | +isort src/ api/ tests/ |
| 101 | + |
| 102 | +# Fix code formatting |
| 103 | +black src/ api/ tests/ |
| 104 | + |
| 105 | +# Check for lint errors (does not auto-fix) |
| 106 | +flake8 src/ api/ tests/ --select=E9,F63,F7,F82 |
| 107 | +``` |
| 108 | + |
| 109 | +--- |
| 110 | + |
| 111 | +## Pre-commit Hooks |
| 112 | + |
| 113 | +Once installed via `pre-commit install`, the hooks run automatically on every `git commit`. You never need to think about formatting again. |
| 114 | + |
| 115 | +If a hook fixes a file, the commit will be blocked and you'll see which files were changed. Just `git add` the fixed files and commit again: |
| 116 | + |
| 117 | +```bash |
| 118 | +git commit -m "your message" |
| 119 | +# hook runs, fixes imports → commit blocked |
| 120 | +git add src/ |
| 121 | +git commit -m "your message" |
| 122 | +# passes ✅ |
| 123 | +``` |
| 124 | + |
| 125 | +To manually run hooks on all files without committing: |
| 126 | + |
| 127 | +```bash |
| 128 | +pre-commit run --all-files |
| 129 | +``` |
| 130 | + |
| 131 | +To temporarily skip hooks (use sparingly): |
| 132 | + |
| 133 | +```bash |
| 134 | +git commit --no-verify -m "your message" |
| 135 | +``` |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## Running the Project |
| 140 | + |
| 141 | +### Option A — Docker (recommended, matches production) |
| 142 | + |
| 143 | +```bash |
| 144 | +# Build and start both services |
| 145 | +docker-compose up -d --build |
| 146 | + |
| 147 | +# View logs |
| 148 | +docker-compose logs -f |
| 149 | + |
| 150 | +# Stop |
| 151 | +docker-compose down |
| 152 | +``` |
| 153 | + |
| 154 | +Services will be available at: |
| 155 | +- Frontend: http://localhost:3000 |
| 156 | +- Backend API: http://localhost:8000 |
| 157 | +- API Docs: http://localhost:8000/docs |
| 158 | + |
| 159 | +### Option B — Run locally without Docker |
| 160 | + |
| 161 | +**Backend:** |
| 162 | +```bash |
| 163 | +# Activate venv first |
| 164 | +uvicorn api.main:app --reload --port 8000 |
| 165 | +``` |
| 166 | + |
| 167 | +**Frontend:** |
| 168 | +```bash |
| 169 | +cd dashboard |
| 170 | +npm run dev |
| 171 | +``` |
| 172 | + |
| 173 | +--- |
| 174 | + |
| 175 | +## Code Standards |
| 176 | + |
| 177 | +### Python |
| 178 | + |
| 179 | +- **Formatter:** `black` (line length 88) |
| 180 | +- **Import sorter:** `isort` (compatible with black) |
| 181 | +- **Linter:** `flake8` (syntax errors only — formatting is handled by black) |
| 182 | +- **Style:** Follow existing patterns in `src/` and `api/` |
| 183 | + |
| 184 | +### TypeScript / React |
| 185 | + |
| 186 | +- **Formatter:** Prettier (via `npm run lint`) |
| 187 | +- **Framework:** Next.js 16 App Router |
| 188 | +- Keep components in `dashboard/src/components/` |
| 189 | +- Keep API calls in `dashboard/src/lib/` |
| 190 | + |
| 191 | +### General |
| 192 | + |
| 193 | +- Never commit `.env` files — use `.env.example` as a template |
| 194 | +- Never commit model files or large data files — these are mounted as Docker volumes |
| 195 | +- Keep `requirements.txt` for runtime dependencies only |
| 196 | +- Keep `requirements-dev.txt` for developer tools only |
| 197 | + |
| 198 | +--- |
| 199 | + |
| 200 | +## Testing |
| 201 | + |
| 202 | +```bash |
| 203 | +# Run all tests |
| 204 | +pytest tests/ -v |
| 205 | + |
| 206 | +# Run with coverage report |
| 207 | +pytest tests/ --cov=src --cov=api --cov-report=term-missing |
| 208 | + |
| 209 | +# Run a specific test file |
| 210 | +pytest tests/test_api.py -v |
| 211 | + |
| 212 | +# Run a specific test |
| 213 | +pytest tests/test_api.py::test_health_endpoint -v |
| 214 | +``` |
| 215 | + |
| 216 | +Tests must pass on both Python 3.10 and 3.11 — the CI pipeline tests both automatically. |
| 217 | + |
| 218 | +--- |
| 219 | + |
| 220 | +## Commit Message Convention |
| 221 | + |
| 222 | +We use a simple prefix convention so the release changelog is generated automatically: |
| 223 | + |
| 224 | +| Prefix | When to use | Example | |
| 225 | +|--------|-------------|---------| |
| 226 | +| `feat:` | New feature | `feat: add batch comparison endpoint` | |
| 227 | +| `fix:` | Bug fix | `fix: handle missing model gracefully` | |
| 228 | +| `perf:` | Performance improvement | `perf: cache SHAP values on startup` | |
| 229 | +| `ci:` | CI/CD changes | `ci: add Python 3.11 to test matrix` | |
| 230 | +| `docker:` | Docker changes | `docker: reduce backend image size` | |
| 231 | +| `docs:` | Documentation | `docs: update API endpoint reference` | |
| 232 | +| `test:` | Test changes | `test: add integration tests for predict endpoint` | |
| 233 | +| `refactor:` | Code cleanup | `refactor: extract prediction logic to service layer` | |
| 234 | + |
| 235 | +--- |
| 236 | + |
| 237 | +## Releasing |
| 238 | + |
| 239 | +Releases are fully automated — just tag and push: |
| 240 | + |
| 241 | +```bash |
| 242 | +# Stable release |
| 243 | +git tag v1.0.0 |
| 244 | +git push origin v1.0.0 |
| 245 | + |
| 246 | +# Pre-release |
| 247 | +git tag v1.0.0-beta.1 |
| 248 | +git push origin v1.0.0-beta.1 |
| 249 | +``` |
| 250 | + |
| 251 | +This triggers the release workflow which: |
| 252 | +- Validates the version format |
| 253 | +- Auto-generates a changelog from commits |
| 254 | +- Creates a GitHub Release with release notes |
| 255 | +- Builds and pushes versioned Docker images to GHCR |
| 256 | + |
| 257 | +See `RELEASES.md` for full details on the release process. |
| 258 | + |
| 259 | +--- |
| 260 | + |
| 261 | +## Questions? |
| 262 | + |
| 263 | +Open an issue on GitHub or check the existing issues before starting work on a new feature. |
0 commit comments