|
| 1 | +# Project Flow & Architecture |
| 2 | + |
| 3 | +## Request Lifecycle |
| 4 | +This diagram illustrates how a request travels through the application. |
| 5 | + |
| 6 | +```mermaid |
| 7 | +--- |
| 8 | +config: |
| 9 | + theme: mc |
| 10 | +--- |
| 11 | +graph TD |
| 12 | + Client[Client] -->|HTTP Request| Server[Server index.js] |
| 13 | + |
| 14 | + subgraph Middleware_Layer |
| 15 | + Server --> Security[Security Middleware] |
| 16 | + Security -->|Helmet, CORS, RateLimit, HPP, XSS| Parser[Body Parsers] |
| 17 | + Parser -->|JSON, Cookie| Logger[Logger] |
| 18 | + Logger --> Auth[Auth Middleware] |
| 19 | + end |
| 20 | + |
| 21 | + subgraph Routing_Layer |
| 22 | + Auth -->|Valid Request| Router{Router} |
| 23 | + Router -->|/api/v1/bootcamps| BCR[Bootcamps Route] |
| 24 | + Router -->|/api/v1/courses| CR[Courses Route] |
| 25 | + Router -->|/api/v1/auth| AR[Auth Route] |
| 26 | + Router -->|/api/v1/users| UR[Users Route] |
| 27 | + Router -->|/api/v1/reviews| RR[Reviews Route] |
| 28 | + end |
| 29 | + |
| 30 | + subgraph Controller_Layer |
| 31 | + BCR --> BCC[Bootcamps Controller] |
| 32 | + CR --> CC[Courses Controller] |
| 33 | + AR --> AC[Auth Controller] |
| 34 | + UR --> UC[Users Controller] |
| 35 | + RR --> RC[Reviews Controller] |
| 36 | + end |
| 37 | + |
| 38 | + subgraph Data_Layer |
| 39 | + BCC --> BCM[(Bootcamp Model)] |
| 40 | + CC --> CM[(Course Model)] |
| 41 | + AC --> UM[(User Model)] |
| 42 | + UC --> UM |
| 43 | + RC --> RM[(Review Model)] |
| 44 | + end |
| 45 | + |
| 46 | + Controller_Layer -->|JSON Response| Client |
| 47 | + Data_Layer -->|Data| Controller_Layer |
| 48 | + |
| 49 | + Server -->|Error| ErrorHandler[Error Handler Middleware] |
| 50 | + ErrorHandler -->|Error Response| Client |
| 51 | +``` |
| 52 | + |
| 53 | +## Data Models (ERD) |
| 54 | +Relationships between the main data entities. |
| 55 | + |
| 56 | +```mermaid |
| 57 | +erDiagram |
| 58 | + User ||--o{ Bootcamp : "publishes" |
| 59 | + User ||--o{ Review : "writes" |
| 60 | + Bootcamp ||--o{ Course : "offers" |
| 61 | + Bootcamp ||--o{ Review : "receives" |
| 62 | + |
| 63 | + User { |
| 64 | + string name |
| 65 | + string email |
| 66 | + string role "user|publisher" |
| 67 | + string password |
| 68 | + } |
| 69 | + |
| 70 | + Bootcamp { |
| 71 | + string name |
| 72 | + string description |
| 73 | + string website |
| 74 | + string phone |
| 75 | + string email |
| 76 | + string address |
| 77 | + string[] careers |
| 78 | + boolean housing |
| 79 | + boolean jobAssistance |
| 80 | + boolean jobGuarantee |
| 81 | + boolean acceptGi |
| 82 | + } |
| 83 | + |
| 84 | + Course { |
| 85 | + string title |
| 86 | + string description |
| 87 | + string weeks |
| 88 | + string tuition |
| 89 | + string minimumSkill |
| 90 | + boolean scholarshipAvailable |
| 91 | + } |
| 92 | + |
| 93 | + Review { |
| 94 | + string title |
| 95 | + string text |
| 96 | + number rating |
| 97 | + } |
| 98 | +``` |
| 99 | + |
| 100 | +## Key Components |
| 101 | + |
| 102 | +### Middleware |
| 103 | +- **Security**: `helmet`, `cors`, `express-rate-limit`, `hpp`, `xss-clean` protect the app. |
| 104 | +- **Auth**: `protect` verifies JWT tokens, `authorize` checks user roles. |
| 105 | +- **Advanced Results**: Handles pagination, filtering, and sorting for list endpoints. |
| 106 | +- **Error Handler**: Centralized error handling for consistent responses. |
| 107 | + |
| 108 | +### Controllers |
| 109 | +- **Auth**: Registration, login, logout, password management. |
| 110 | +- **Bootcamps**: CRUD operations for bootcamps, photo upload, geospatial search. |
| 111 | +- **Courses**: CRUD operations for courses, associated with bootcamps. |
| 112 | +- **Users**: Admin management of users. |
| 113 | +- **Reviews**: User reviews for bootcamps. |
| 114 | + |
| 115 | +### Models |
| 116 | +- **User**: Stores user information, authentication, and roles. |
| 117 | +- **Bootcamp**: Stores bootcamp details, location, and associated courses. |
| 118 | +- **Course**: Stores course details, associated with bootcamps. |
| 119 | +- **Review**: Stores user reviews for bootcamps. |
| 120 | + |
0 commit comments