# PolyMPR - Claude Code Context ## πŸ“‹ Project Overview **PolyMPR** (Poly Management Platform for Resources) is a modular HR management system built with **Deno + Fresh** framework. It's designed to help organizations manage HR, student records, notes, mobility programs, and role-based administration. ### Stack - **Runtime**: Deno - **Framework**: Fresh (edge-ready web framework) - **Database**: PostgreSQL with Drizzle ORM - **Frontend**: Preact with signals - **Authentication**: JWT-based via cookies - **Testing**: Deno test framework with HappyDOM for DOM testing ### Current Status 🚧 **In Progress** - API layer largely complete, UI pages not yet built. The schema below is the **final/definitive schema** that guides all development. --- ## πŸ—οΈ Architecture ### Module Structure The application uses a **modulith architecture** with the following modules: ``` routes/(apps)/ β”œβ”€β”€ students/ - Student management & promotions β”œβ”€β”€ notes/ - Grade management & academic records β”œβ”€β”€ mobility/ - Mobility programs & exchanges └── admin/ - Role & permission management ``` ### Key Directories - `/routes` - Fresh routes and components - `/databases` - Database connection, schema, and migrations - `/defaults` - Interfaces and shared types - `/tests` - Unit, integration, and E2E tests - `/static` - Public assets ### Authentication Flow 1. User authenticates via CAS (Polytech) 2. JWT token stored in `sessionToken` cookie 3. Middleware validates token on each request 4. Public routes: `/`, `/login`, `/logout`, `/about`, `/contact` 5. All other routes require authentication --- ## πŸ“Š Database Schema (Final/Definitive) ```mermaid erDiagram USER { string id PK string nom string prenom int idRole FK } ROLE { int id PK string nom } PERMISSION { int id PK string nom } ROLE_PERMISSION { int idRole PK,FK int idPermission PK,FK } STUDENT { int numEtud PK string nom string prenom string idPromo FK } PROMOTION { string idPromo PK string annee } MODULE { string id PK string nom } ENSEIGNEMENT { string idProf PK,FK string idModule PK,FK string idPromo PK,FK } UE { int id PK string nom } UE_MODULE { string idModule PK,FK int idUE PK,FK string idPromo PK,FK float coeff } NOTE { int numEtud PK,FK string idModule PK,FK float note } AJUSTEMENT { int numEtud PK,FK int idUE PK,FK float valeur } USER }o--|| ROLE : "a" ROLE_PERMISSION }o--|| ROLE : "accorde" ROLE_PERMISSION }o--|| PERMISSION : "inclut" ENSEIGNEMENT }o--|| USER : "rΓ©alisΓ© par" ENSEIGNEMENT }o--|| MODULE : "porte sur" ENSEIGNEMENT }o--|| PROMOTION : "concerne" STUDENT }o--|| PROMOTION : "appartient Γ " UE_MODULE }o--|| MODULE : "associe" UE_MODULE }o--|| UE : "appartient Γ " UE_MODULE }o--|| PROMOTION : "pour" NOTE }o--|| STUDENT : "reΓ§oit" NOTE }o--|| MODULE : "dans" AJUSTEMENT }o--|| STUDENT : "concerne" AJUSTEMENT }o--|| UE : "dans" ``` ### Current Schema The Drizzle ORM schema in `/databases/schema.ts` implements all tables: `roles`, `permissions`, `rolePermissions`, `users`, `promotions`, `students`, `modules`, `enseignements`, `ues`, `ueModules`, `notes`, `ajustements`, `mobility`. --- ## 🎯 Open Issues (69 total) ### UI Pages **Catalog** - πŸ“‹ UI - Page Catalogue d'applications (#71) **Components** - 🎨 UI (composant) - Popup RΓ©sultats d'import (#75) **Students** - πŸ“‹ UI - Admin – Liste des Γ©lΓ¨ves (#79) - πŸ“‹ UI - Admin – Gestion des promotions (#80) - πŸ“‹ UI - Admin – Import xlsx Γ©lΓ¨ves (#81) - πŸ“‹ UI - Admin – Γ‰dition d'un Γ©lΓ¨ve (#82) **Notes** - πŸ“‹ UI - Page Γ‰lΓ¨ve – Mes Notes (#72) - πŸ“‹ UI - Admin – Consulter les notes (#73) - πŸ“‹ UI - Admin – Importer des notes (.xlsx) (#74) - πŸ“‹ UI - Admin – Γ‰dition notes d'un Γ©lΓ¨ve (#76) - πŸ“‹ UI - Admin – RΓ©cap notes Γ©lΓ¨ve / semestre (#77) - πŸ“‹ UI - Admin – Gestion des UEs (#78) **Administration** - πŸ“‹ UI - Gestion des utilisateurs (#83) - πŸ“‹ UI - Gestion des rΓ΄les (#84) - πŸ“‹ UI - Permissions d'un rΓ΄le (#85) - πŸ“‹ UI - Vue des permissions (#86) - πŸ“‹ UI - Gestion des modules (#87) - πŸ“‹ UI - Enseignements (Assignations) (#88) --- ### API Endpoints Legend: βœ… implemented & tested | πŸ“‹ not yet implemented **Students API** - βœ… GET `/students` (#7) - βœ… POST `/students` (#8) - βœ… POST `/students/import-csv` (#9) - βœ… GET `/students/{numEtud}` (#10) - βœ… PUT `/students/{numEtud}` (#11) - βœ… DELETE `/students/{numEtud}` (#12) - βœ… GET `/promotions` (#13) - βœ… POST `/promotions` (#14) - βœ… GET `/promotions/{idPromo}` (#15) - βœ… PUT `/promotions/{idPromo}` (#16) - βœ… DELETE `/promotions/{idPromo}` (#17) **Administration API - Modules & Enseignements** - βœ… GET `/modules` (#23) - βœ… POST `/modules` (#24) - βœ… GET `/modules/{idModule}` (#25) - βœ… PUT `/modules/{idModule}` (#26) - βœ… DELETE `/modules/{idModule}` (#27) - βœ… POST `/enseignements` (#29) - βœ… GET `/enseignements/{idProf}/{idModule}/{idPromo}` (#30) - βœ… DELETE `/enseignements/{idProf}/{idModule}/{idPromo}` (#31) **Notes API - UEs & UE-Modules** - βœ… GET `/ues` (#32) - βœ… POST `/ues` (#33) - βœ… GET `/ues/{idUE}` (#34) - βœ… PUT `/ues/{idUE}` (#35) - βœ… DELETE `/ues/{idUE}` (#36) - βœ… GET `/ue-modules` (#37) - βœ… POST `/ue-modules` (#38) - βœ… GET `/ue-modules/{idModule}/{idUE}/{idPromo}` (#39) - βœ… PUT `/ue-modules/{idModule}/{idUE}/{idPromo}` (#40) - βœ… DELETE `/ue-modules/{idModule}/{idUE}/{idPromo}` (#41) **Notes API - Notes & Ajustements** - βœ… GET `/notes` (#42) - βœ… POST `/notes` (#43) - πŸ“‹ POST `/notes/import-xlsx` (#44) - βœ… GET `/notes/{numEtud}/{idModule}` (#45) - βœ… PUT `/notes/{numEtud}/{idModule}` (#46) - βœ… DELETE `/notes/{numEtud}/{idModule}` (#47) - βœ… GET `/ajustements` (#48) - βœ… POST `/ajustements` (#49) - βœ… GET `/ajustements/{numEtud}/{idUE}` (#50) - βœ… PUT `/ajustements/{numEtud}/{idUE}` (#51) - βœ… DELETE `/ajustements/{numEtud}/{idUE}` (#52) **Administration API - Users, Roles & Permissions** - βœ… GET `/users` (#60) - βœ… POST `/users` (#61) - βœ… GET `/users/{id}` (#62) - βœ… PUT `/users/{id}` (#63) - βœ… DELETE `/users/{id}` (#64) - βœ… GET `/roles` (#65) - βœ… POST `/roles` (#66) - βœ… GET `/roles/{idRole}` (#67) - βœ… PUT `/roles/{idRole}` (#68) - βœ… DELETE `/roles/{idRole}` (#69) - βœ… GET `/permissions` (#70) --- ## 🎨 Design Reference **Figma Prototype**: https://www.figma.com/design/La79bsUsWnJCtMsrrt2zGd/Prototype?node-id=0-1 This is the **final design specification** for the UI. All UI implementations should follow this design. --- ## πŸš€ Development Guidelines ### Getting Started ```bash # Run tests deno task test # Start development server deno task start # Build for production deno task build # Format & lint deno task check ``` ### Git Workflow 1. Create branch: `git checkout -b PMPR-{ISSUE_ID}` 2. Implement changes 3. Run tests and linting 4. Submit PR ### Code Style - Format: Follow Deno defaults (enforced via `deno fmt`) - Linting: Fresh recommended rules - TypeScript strict mode enabled - Use Drizzle ORM for database operations ### Testing 3-level architecture β€” all 149 tests pass: - **Unit** (`tests/unit/`) β€” pure logic with mock DB + mock API, no real DB - **Integration** (`tests/integration/`) β€” Drizzle ORM direct on real DB - **E2E** (`tests/e2e/`) β€” Fresh handler + real DB (handler-level, not browser) Helpers in `tests/helpers/`: - `handler.ts` β€” builds fake Fresh contexts (`makeEmployeeContext`, `makeJsonRequest`…) - `db_integration.ts` β€” seed functions + `truncateAll()` for test isolation - `db_mock.ts` / `api_mock.ts` β€” in-memory mocks for unit tests ```bash deno task test # run all tests deno task test:coverage # coverage report (terminal) deno task test:coverage:html # coverage report (HTML β†’ coverage/html/index.html) nix run nixpkgs#act -- -j unit --no-cache-server # unit tests via GitHub Actions nix run nixpkgs#act -- -j integration --no-cache-server # integration + e2e via GitHub Actions ``` --- ## πŸ“¦ Key Dependencies - **fresh@1.7.3** - Web framework - **drizzle-orm@0.45.2** - ORM - **pg@8.20.0** - PostgreSQL driver - **@popov/jwt@1.0.1** - JWT utilities - **preact@10.22.0** - UI library - **happy-dom@16.0.0** - DOM testing --- ## πŸ”— Related Resources - **Repository**: https://git.polytech.djalim.fr/djalim/PolyMPR - **Issue Tracker**: Gitea (via `tea` CLI) - **Wiki**: Check CONTRIBUTING.md for dev setup - **Database**: PostgreSQL (configured in `.env`) --- ## πŸ’‘ Important Notes 1. **Only missing API**: `POST /notes/import-xlsx` (#44) β€” all other endpoints are implemented. 2. **Next priority**: UI pages (none built yet) β€” follow the Figma prototype. 3. **Module Pattern**: Each module should follow the same pattern: routes, API endpoints, components, and tests. 4. **Permissions**: All admin operations should respect the ROLE_PERMISSION system. 5. **Fresh Conventions**: Routes use Fresh's file-based routing convention (e.g., `routes/path/index.tsx`). 6. **Drizzle `.where()` pitfall**: Always wrap multiple conditions with `and()`. `.where(eq(a), eq(b))` silently ignores the second argument.