Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ Thumbs.db
*.tmp
*.bak

# Markdown: only README.md is versioned
# Markdown: only README.md and CHANGELOG.md are versioned
*.md
!README.md
!CHANGELOG.md

# Frontend (React dashboard)
frontend/node_modules/
Expand Down
58 changes: 58 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Changelog

All notable changes to Sentinel are documented here.

## [0.2.0] - 2026-09-01

### Added

#### Frontend Features
- **Toast notifications** — success/error/info toasts with 4s auto-dismiss (`Toast.tsx`)
- **Keyboard shortcuts** — `1`/`2` switch tabs, `Escape` dismisses panels (`useKeyboardShortcuts.ts`)
- **History panel** — last 10 analyses stored in localStorage (`HistoryPanel.tsx`, `useHistory.ts`)
- **Share button** — copy analysis URL to clipboard (`ShareButton.tsx`)
- **Export** — download results as JSON or CSV (`ExportButton.tsx`)
- **Caching** — 5-minute client-side cache for repeated analyses (`api.ts`)
- **Performance tracking** — shows "Analyzed in X.Xs" (`usePerformance.ts`)
- **Analytics** — localStorage-based event tracking, max 50 events (`useAnalytics.ts`)
- **Responsive mobile cards** — improved violation cards with file count, line-clamp, component overflow (`ViolationsTab.tsx`)
- **Error boundary** — React class component with retry (`ErrorBoundary.tsx`)
- **Meta tags** — Open Graph + Twitter Card for social sharing (`index.html`)

#### Backend Improvements
- **Concurrency limiter** — `asyncio.Semaphore(3)` prevents resource exhaustion, returns 429 on limit
- **Input validation** — Pydantic validators for GitHub URL regex + branch sanitization
- **Git clone timeout** — 60s timeout on `git clone --depth=1`
- **FQN resolution** — Java and C# parsers return full FQN (`com.example.model.User` instead of `User`)

#### Infrastructure
- **CI pipeline** — GitHub Actions: lint (ruff), test matrix (Python 3.12 + 3.13, Ubuntu + Windows), frontend build
- **Pre-deploy script** — `scripts/deploy_check.py` validates lint, format, tests, build, security
- **Code splitting** — Manual Vite chunks: vendor (~182KB), motion (~133KB), index (~42KB)
- **Test isolation** — `afterEach(cleanup)` in test-setup.ts, `clearCache()` in api tests

### Fixed
- **Desktop expand bug** — nested `<button>` violation (aria-expanded on parent), `sm:hidden` on expanded details
- **Manifest rule keys** — `VALID_RULE_KEYS` expanded from 2 to 9 identifiers (hyphen style matching actual rules)
- **Float thresholds** — `rule_threshold()` returns `int | float` instead of truncating to `int`
- **AnimatePresence jsdom** — removed from mobile expanded content (animations don't resolve in jsdom)
- **API test pollution** — cache clearing between tests prevents cross-test state leakage

### Removed
- **LoadingState.tsx** — dead code, replaced by skeleton components

## [0.1.0] - 2026-08-30

### Added
- Initial release
- 8 architecture detection rules (layer violation, circular dependency, god module, high coupling, low cohesion, boundary crossing, React component, database leakage)
- tree-sitter parsers for TypeScript, JavaScript, Python, Java, C#
- Architecture manifest YAML format
- Drift score computation
- Git blame integration for origin commits
- CLI with 6 commands: analyze, graph, trend, history, report, serve
- HTML report generator with Chart.js
- FastAPI stateless backend
- React dashboard with Tailwind CSS v4
- Vitest + testing-library frontend tests
- 126 Python backend tests
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Sentinel Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
138 changes: 104 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ reports violations, and tracks regression across git history.

[![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
[![Tests](https://img.shields.io/badge/tests-138%20passed-brightgreen.svg)]()
[![Tests](https://img.shields.io/badge/tests-141%20passed-brightgreen.svg)]()
[![Live Demo](https://img.shields.io/badge/demo-live-ff69b4.svg)](https://sentinel-zxr.pages.dev)

[**Try it live**](https://sentinel-zxr.pages.dev) — no installation required
Expand All @@ -33,7 +33,7 @@ Sentinel analyzes your repository's dependency graph and compares it against a d
| Low cohesion | Module with poor internal cohesion (LCOM heuristic) | warning |
| Boundary crossing | Non-layer code importing sentinel markers | warning |
| React component | Non-UI layer importing React components | warning |
| Drift score | Violations introduced or resolved between commits | info |
| Database leakage | Direct dependencies to data-layer modules | warning |

Every violation includes the **origin commit** — the last commit that touched the offending file.

Expand Down Expand Up @@ -91,13 +91,17 @@ Optional tuning:
rules:
god_module: { threshold: 12 } # total coupling (fan-in + fan-out)
high_coupling: { threshold: 5 } # fan-in (number of dependents)
low_cohesion: { threshold: 0.3 } # cohesion score (0.0-1.0)
boundary_crossing: { threshold: 3 }
react_component: { max_lines: 150, max_props: 8 }
database_leakage: { threshold: 2 }
```

**No manifest?** Sentinel still runs 6 of 8 rules (all except layer violation and database leakage).

## Supported Languages

TypeScript, JavaScript, Python, Java, and C#. Imports are resolved to files by matching module references against project file stems.
TypeScript, JavaScript, Python, Java, and C#. Imports are resolved to files by matching module references against project file stems. Full FQN resolution for Java (`com.example.model.User`) and C# (`Namespace.Class`).

## How It Works

Expand All @@ -122,6 +126,46 @@ Repository
| Cost | Free (SaaS + CLI) | Free tier limited, paid for teams |
| Languages | TS, JS, Python, Java, C# | 20+ via plugins |

## Deployment

Sentinel runs as a stateless SaaS:

- **Backend**: FastAPI on SnapDeploy (auto-sleep, Docker)
- **Frontend**: React on Cloudflare Pages (free tier)

The backend has no database or auth — a single `POST /api/analyze` endpoint clones the repo, runs analysis, and returns results.

## Frontend Features

- **Toast notifications** — success/error/info with auto-dismiss
- **Keyboard shortcuts** — `1`/`2` switch tabs, `Escape` dismisses
- **History panel** — last 10 analyses stored in localStorage
- **Share button** — copy analysis URL to clipboard
- **Export** — download results as JSON or CSV
- **Caching** — 5-minute client-side cache for repeated analyses
- **Performance tracking** — shows analysis duration
- **Responsive design** — mobile-optimized violation cards
- **Dark/Light mode** — toggle with localStorage persistence
- **Error boundary** — graceful recovery from rendering errors

## CI/CD

GitHub Actions runs on every push to `main` and every PR:

| Job | What it runs |
|-----|-------------|
| `lint` | `ruff check` + `ruff format --check` on backend |
| `test` | `pytest` on Python 3.12 + 3.13 (Ubuntu + Windows matrix) |
| `dashboard` | `npm run test` + `npm run build` on frontend |

Pre-deploy validation:

```bash
python scripts/deploy_check.py
```

Runs lint, format, tests, frontend build, and security checks before deployment.

## Development

```bash
Expand All @@ -145,54 +189,80 @@ Tests use synthetic repos of known architecture (`GOOD`, `BAD`, `EVOLVING`) so e

```
sentinel/
├── src/sentinel/ # Core library
│ ├── parsers/ # tree-sitter language parsers
│ ├── analyzers/ # coupling, cohesion analysis
│ ├── rules/ # 8 detection rules
│ ├── domain/ # Manifest, Violation types
│ ├── manifest/ # YAML loader
│ ├── persistence/ # SQLite run storage
│ ├── reports/ # HTML report generator
│ ├── violation_engine.py
│ ├── trend.py # Regression detection
│ ├── cli.py # Typer CLI
│ └── server.py # HTTP server
├── backend/ # SaaS API (FastAPI, stateless)
├── frontend/ # React dashboard
├── src/sentinel/ # Core library
│ ├── parsers/ # tree-sitter language parsers
│ │ ├── base.py # Parser ABC
│ │ ├── registry.py # Extension-to-parser mapping
│ │ ├── typescript.py # TS/JS parser
│ │ ├── python_lang.py # Python parser
│ │ ├── java.py # Java parser (full FQN)
│ │ └── csharp.py # C# parser (full FQN)
│ ├── analyzers/ # coupling, cohesion, drift analysis
│ ├── rules/ # 8 detection rules
│ ├── domain/ # Manifest, Violation, Graph types
│ ├── manifest/ # YAML loader + layer mapper
│ ├── persistence/ # SQLite run storage
│ ├── reports/ # HTML report generator
│ ├── violation_engine.py # Orchestrates analysis pipeline
│ ├── trend.py # Regression detection
│ ├── git_origin.py # Git blame integration
│ ├── cli.py # Typer CLI (6 commands)
│ └── server.py # stdlib HTTP server
├── backend/ # SaaS API (FastAPI, stateless)
│ ├── main.py # FastAPI app + CORS
│ ├── config.py # Pydantic settings
│ ├── routers/analyses.py # POST /api/analyze
│ └── services/analysis.py # Clone + analyze + cleanup
├── frontend/ # React dashboard
│ ├── src/
│ │ ├── components/ # UI components
│ │ ├── components/ # 16 UI components
│ │ │ ├── AnalyzeForm.tsx
│ │ │ ├── SummaryCards.tsx
│ │ │ ├── MetricsBar.tsx
│ │ │ ├── ErrorBoundary.tsx
│ │ │ ├── ExportButton.tsx
│ │ │ ├── HistoryPanel.tsx
│ │ │ ├── ShareButton.tsx
│ │ │ ├── Toast.tsx
│ │ │ ├── ViolationsTab.tsx
│ │ │ ├── RemediationTab.tsx
│ │ │ └── LoadingState.tsx
│ │ ├── __tests__/ # Vitest + testing-library
│ │ ├── api.ts # Backend client
│ │ ├── App.tsx # Root component
│ │ └── index.css # Tailwind v4 theme
│ │ │ └── ...
│ │ ├── hooks/ # 5 custom hooks
│ │ │ ├── useAnalytics.ts
│ │ │ ├── useHistory.ts
│ │ │ ├── useKeyboardShortcuts.ts
│ │ │ ├── usePerformance.ts
│ │ │ └── usePrefersReducedMotion.ts
│ │ ├── __tests__/ # Vitest + testing-library
│ │ ├── api.ts # Backend client + cache
│ │ └── App.tsx # Root component
│ └── package.json
├── tests/ # 126 Python tests
└── sentinel.yaml # Example manifest
├── tests/ # 126 Python tests
├── scripts/deploy_check.py # Pre-deploy validation
├── .github/workflows/ci.yml # CI pipeline
├── Dockerfile # Multi-stage build
├── fly.toml # Fly.io config
├── .env.example # Environment variables
└── pyproject.toml # Package config
```

### Frontend Stack

- **React 19** — UI framework
- **TypeScript 6.0** — type safety
- **Vite 8.2** — build tool with manual chunks
- **Tailwind CSS v4** — CSS-first config, no `tailwind.config.js`
- **Geist Sans + Mono** — typography
- **lucide-react** — icons
- **framer-motion** — animations (shimmer, blur-fade, number-ticker)
- **Vitest + testing-library** — 12 frontend tests
- **Dark/Light mode** — toggle with `localStorage` persistence
- **framer-motion** — animations
- **Vitest 4.1 + testing-library** — 15 frontend tests

## Contributing

1. Fork the repo
2. Create a feature branch (`git checkout -b feat/my-feature`)
3. Make changes with tests
4. Run `ruff check src tests && ruff format src tests && python -m pytest tests/`
5. Open a PR against `main`
4. Run backend checks: `ruff check src tests && ruff format src tests && python -m pytest tests/`
5. Run frontend checks: `cd frontend && npm run test && npm run build`
6. Open a PR against `main`

## License

MIT
[MIT](LICENSE)
Loading
Loading