|
1 |
| -<p align="center"> |
2 |
| - <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a> |
3 |
| -</p> |
4 |
| - |
5 |
| -[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 |
6 |
| -[circleci-url]: https://circleci.com/gh/nestjs/nest |
7 |
| - |
8 |
| - <p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p> |
9 |
| - <p align="center"> |
10 |
| -<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a> |
11 |
| -<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a> |
12 |
| -<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a> |
13 |
| -<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a> |
14 |
| -<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a> |
15 |
| -<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a> |
16 |
| -<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a> |
17 |
| -<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a> |
18 |
| - <a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a> |
19 |
| - <a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a> |
20 |
| - <a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a> |
21 |
| -</p> |
22 |
| - <!--[](https://opencollective.com/nest#backer) |
23 |
| - [](https://opencollective.com/nest#sponsor)--> |
24 |
| - |
25 |
| -## Description |
26 |
| - |
27 |
| -[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. |
28 |
| - |
29 |
| -## Project setup |
| 1 | +# Movie Management System |
30 | 2 |
|
| 3 | +A RESTful API for managing movies, built with NestJS and structured according to Domain-Driven Design principles. |
| 4 | + |
| 5 | +## Project Description |
| 6 | + |
| 7 | +This Movie Management System allows: |
| 8 | +- User registration and authentication (managers and customers) |
| 9 | +- Movie management with age restrictions and multiple sessions |
| 10 | +- Ticket purchasing |
| 11 | +- Movie watching (with valid tickets) |
| 12 | +- User watch history tracking |
| 13 | + |
| 14 | +## Architecture Overview |
| 15 | + |
| 16 | +This project follows a Hexagonal Architecture (Ports and Adapters) approach within the Domain-Driven Design methodology: |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +### Key Components: |
| 21 | + |
| 22 | +1. **Domain Layer (Core):** |
| 23 | + - Contains business entities, value objects, and domain events |
| 24 | + - Defines ports (interfaces) that the outside world must implement |
| 25 | + - Houses core business logic |
| 26 | + |
| 27 | +2. **Application Layer:** |
| 28 | + - Orchestrates use cases through application services |
| 29 | + - Implements command handlers to process user intents |
| 30 | + - Coordinates between domain and infrastructure |
| 31 | + |
| 32 | +3. **Adapters Layer:** |
| 33 | + - **Primary/Driving Adapters:** REST controllers, GraphQL resolvers, DTOs |
| 34 | + - **Secondary/Driven Adapters:** Database implementations, external service integrations |
| 35 | + |
| 36 | +## Technology Stack |
| 37 | + |
| 38 | +- **Framework:** NestJS 9.x |
| 39 | +- **Language:** TypeScript 4.x |
| 40 | +- **Database:** PostgreSQL (production), SQLite (testing) |
| 41 | +- **ORM:** TypeORM |
| 42 | +- **Authentication:** JWT, Passport |
| 43 | +- **Testing:** Jest |
| 44 | +- **Documentation:** Swagger/OpenAPI |
| 45 | +- **Architecture Patterns:** Domain-Driven Design, Hexagonal Architecture, CQRS |
| 46 | + |
| 47 | +## Getting Started |
| 48 | + |
| 49 | +### Prerequisites |
| 50 | + |
| 51 | +- Node.js 14.x or later |
| 52 | +- npm 7.x or later |
| 53 | +- PostgreSQL (for production) |
| 54 | + |
| 55 | +### Installation |
| 56 | + |
| 57 | +1. Clone the repository: |
| 58 | + ```bash |
| 59 | + git clone https://github.com/yourusername/movie-management-system.git |
| 60 | + cd movie-management-system |
| 61 | + ``` |
| 62 | + |
| 63 | +2. Install dependencies: |
| 64 | + ```bash |
| 65 | + npm install |
| 66 | + ``` |
| 67 | + |
| 68 | +3. Set up environment variables: |
| 69 | + ```bash |
| 70 | + cp .env.example .env |
| 71 | + # Edit .env with your configuration |
| 72 | + ``` |
| 73 | + |
| 74 | +4. Start the development server: |
| 75 | + ```bash |
| 76 | + npm run start:dev |
| 77 | + ``` |
| 78 | + |
| 79 | +### Testing |
| 80 | + |
| 81 | +Run unit tests: |
31 | 82 | ```bash
|
32 |
| -$ npm install |
| 83 | +npm test |
33 | 84 | ```
|
34 | 85 |
|
35 |
| -## Compile and run the project |
36 |
| - |
| 86 | +Run end-to-end tests: |
37 | 87 | ```bash
|
38 |
| -# development |
39 |
| -$ npm run start |
| 88 | +npm run test:e2e |
| 89 | +``` |
40 | 90 |
|
41 |
| -# watch mode |
42 |
| -$ npm run start:dev |
| 91 | +### API Documentation |
43 | 92 |
|
44 |
| -# production mode |
45 |
| -$ npm run start:prod |
| 93 | +Once the application is running, you can access the Swagger documentation at: |
| 94 | +``` |
| 95 | +http://localhost:3000/api |
46 | 96 | ```
|
47 | 97 |
|
48 |
| -## Run tests |
| 98 | +## Project Structure |
49 | 99 |
|
50 |
| -```bash |
51 |
| -# unit tests |
52 |
| -$ npm run test |
| 100 | +``` |
| 101 | +src/ |
| 102 | +├── modules/ # Feature modules (bounded contexts) |
| 103 | +│ ├── auth/ # Authentication bounded context |
| 104 | +│ │ ├── domain/ # Domain layer (hexagon core) |
| 105 | +│ │ │ ├── models/ # Entities, aggregates, value objects |
| 106 | +│ │ │ ├── events/ # Domain events |
| 107 | +│ │ │ ├── ports/ # Secondary ports (interfaces) |
| 108 | +│ │ │ └── services/ # Domain services |
| 109 | +│ │ ├── application/ # Application layer |
| 110 | +│ │ │ ├── services/ # Use case orchestration |
| 111 | +│ │ │ └── commands/ # CQRS commands |
| 112 | +│ │ ├── adapters/ # Adapters layer |
| 113 | +│ │ │ ├── primary/ # Driving adapters (controllers) |
| 114 | +│ │ │ └── secondary/ # Driven adapters (repositories) |
| 115 | +│ │ └── auth.module.ts # NestJS module configuration |
| 116 | +│ ├── movie/ # Movie management context |
| 117 | +│ └── ticket/ # Ticket management context |
| 118 | +├── common/ # Shared code |
| 119 | +│ ├── filters/ # Global exception filters |
| 120 | +│ ├── interceptors/ # Global interceptors |
| 121 | +│ └── decorators/ # Custom decorators |
| 122 | +└── main.ts # Application entry point |
| 123 | +``` |
53 | 124 |
|
54 |
| -# e2e tests |
55 |
| -$ npm run test:e2e |
| 125 | +## Implementation Approach |
56 | 126 |
|
57 |
| -# test coverage |
58 |
| -$ npm run test:cov |
59 |
| -``` |
| 127 | +### Domain-Driven Design |
60 | 128 |
|
61 |
| -## Deployment |
| 129 | +The application is structured around key business domains: |
| 130 | +1. **Authentication Domain:** User management, login, registration |
| 131 | +2. **Movie Domain:** Movie creation, updates, sessions |
| 132 | +3. **Ticket Domain:** Ticket purchases, validation |
62 | 133 |
|
63 |
| -When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information. |
| 134 | +Each domain follows Clean Architecture principles with clear separation of: |
| 135 | +- **Domain Models:** Pure business logic |
| 136 | +- **Application Services:** Use case orchestration |
| 137 | +- **Infrastructure:** Technical implementations (databases, external services) |
64 | 138 |
|
65 |
| -If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps: |
| 139 | +### Hexagonal Architecture |
66 | 140 |
|
67 |
| -```bash |
68 |
| -$ npm install -g mau |
69 |
| -$ mau deploy |
70 |
| -``` |
| 141 | +The hexagonal architecture (ports and adapters) allows us to: |
| 142 | +- Keep the domain layer free from infrastructure concerns |
| 143 | +- Easily replace implementation details (e.g., database, security providers) |
| 144 | +- Make the system more testable by mocking adapters |
| 145 | +- Maintain a clear boundary between business logic and technical implementations |
| 146 | + |
| 147 | +## Development Decisions |
| 148 | + |
| 149 | +1. **Authentication Strategy:** |
| 150 | + - JWT-based authentication for stateless API interactions |
| 151 | + - Role-based access control (RBAC) for authorization |
| 152 | + - Strong password hashing with bcrypt |
| 153 | + |
| 154 | +2. **Database Approach:** |
| 155 | + - Repository pattern for data access abstraction |
| 156 | + - TypeORM for database interactions with clear domain separation |
| 157 | + - Entities mapped properly to domain objects |
| 158 | + |
| 159 | +3. **Error Handling:** |
| 160 | + - Centralized exception handling |
| 161 | + - Domain-specific exceptions |
| 162 | + - Proper HTTP status codes and error messages |
71 | 163 |
|
72 |
| -With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure. |
| 164 | +4. **Performance Considerations:** |
| 165 | + - Optimized database queries |
| 166 | + - Proper indexing strategy |
| 167 | + - Request timeout handling |
73 | 168 |
|
74 |
| -## Resources |
| 169 | +## Challenges Faced |
75 | 170 |
|
76 |
| -Check out a few resources that may come in handy when working with NestJS: |
| 171 | +During development, several challenges were addressed: |
77 | 172 |
|
78 |
| -- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework. |
79 |
| -- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy). |
80 |
| -- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/). |
81 |
| -- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks. |
82 |
| -- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com). |
83 |
| -- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com). |
84 |
| -- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs). |
85 |
| -- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com). |
| 173 | +1. **Maintaining Clean Architecture:** |
| 174 | + - Ensuring domain models remain free of infrastructure concerns |
| 175 | + - Avoiding anemic domain models by placing business logic appropriately |
86 | 176 |
|
87 |
| -## Support |
| 177 | +2. **TypeORM Integration:** |
| 178 | + - Properly mapping between domain entities and ORM entities |
| 179 | + - Managing relations while respecting domain boundaries |
88 | 180 |
|
89 |
| -Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). |
| 181 | +3. **Testing Strategy:** |
| 182 | + - Creating effective unit tests for domain logic |
| 183 | + - Setting up integration tests with a test database |
| 184 | + - Mocking external dependencies appropriately |
90 | 185 |
|
91 |
| -## Stay in touch |
| 186 | +## Future Improvements |
92 | 187 |
|
93 |
| -- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec) |
94 |
| -- Website - [https://nestjs.com](https://nestjs.com/) |
95 |
| -- Twitter - [@nestframework](https://twitter.com/nestframework) |
| 188 | +1. **Caching Layer:** Implement Redis caching for frequently accessed data |
| 189 | +2. **Session Conflict Detection:** Advanced algorithm to prevent double-booking |
| 190 | +3. **Recommendation System:** Movie recommendations based on watch history |
| 191 | +4. **Reporting Module:** Advanced analytics for managers |
| 192 | +5. **Microservices Architecture:** Split into microservices for better scalability |
96 | 193 |
|
97 | 194 | ## License
|
98 | 195 |
|
99 |
| -Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE). |
| 196 | +This project is licensed under the MIT License - see the LICENSE file for details. |
0 commit comments