# Copilot Instructions for Exam Manager ## Architecture Overview - **Backend**: TypeScript (Node.js) located in [/backend](/backend). Uses `rjweb-server` for the web server and `mongodb` for the database. - **Frontend**: React (Vite) located in [/frontend](/frontend). Uses Tailwind CSS for styling and React Router for navigation. - **Database**: MongoDB. Database connection string is managed via `.env` file. - **Deployment**: Backend serves the frontend's built files from `/frontend/dist`. API routes are prefixed with `/api`. ## Core Patterns & Conventions ### Backend (Node.js/TypeScript) - **Server Framework**: `rjweb-server`. Routes are defined using `fileRouter.Path`. - **Database Access**: Use the exported `db` object from [backend/src/index.ts](backend/src/index.ts). - **Models & Types**: Defined in [backend/src/types.ts](backend/src/types.ts). - **Authentication**: Session-based using a cookie named `exams_session` or an `api-authentication` header. Use `authCheck` from [backend/src/lib/Auth.ts](backend/src/lib/Auth.ts) to protect routes. - **Static Files**: The backend serves the frontend's built files from `/frontend/dist`. API routes are prefixed with `/api`. ### Frontend (React) - **API Calls**: Axios-based. Authentication is handled automatically via cookies. API paths start with `/api/`. - **Types**: Always keep [frontend/src/types.ts](frontend/src/types.ts) in sync with backend types. - **Routing**: Managed in [frontend/src/App.tsx](frontend/src/App.tsx). Protected routes should verify authentication with the backend. - **Icons**: Use `lucide-react` for iconography. ## Developer Workflows - **Running with Docker**: Use `docker-compose up --build` to build both stacks and the DB. - **Local Backend Dev**: ```bash cd backend npm install npm run dev ``` - **Local Frontend Dev**: ```bash cd frontend npm install npm run dev ``` ## Important Files - [backend/src/index.ts](backend/src/index.ts): Entry point and server configuration. - [backend/src/routes/](backend/src/routes/): Directory containing all API endpoints. - [backend/src/types.ts](backend/src/types.ts): Shared TypeScript interfaces for models. - [frontend/src/App.tsx](frontend/src/App.tsx): Frontend routing and auth state. - [frontend/src/types.ts](frontend/src/types.ts): Type definitions for the frontend.