Skip to content

Commit 5659119

Browse files
committed
Updated readme
1 parent 4e5ec1f commit 5659119

File tree

2 files changed

+101
-11
lines changed

2 files changed

+101
-11
lines changed

README.md

+91-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# CarRental
1+
# Car Rental
2+
3+
This project is a vehicle rental application that allows users to add, edit, remove, and view vehicles. It also allows users to add client email and client address information if the vehicle is rented to someone. The application is built using Angular for the frontend, NestJS for the backend, and MySQL for the database. The development environment is managed using Docker Compose.
4+
5+
26
## Docker Compose Setup
37

48
This project uses Docker Compose to manage the development environment. The setup includes three services: `db`, `backend`, and `frontend`.
@@ -7,6 +11,17 @@ This project uses Docker Compose to manage the development environment. The setu
711

812
#### Database (`db`)
913

14+
##### Description
15+
16+
The database service uses MySQL to store all the data related to the car rental application. When you run the `db` service for the first time, it will execute all SQL scripts located in the `scripts` directory to set up the database schema and seed initial data. The scripts currently included are:
17+
- `0_create_database.sql`
18+
- `1_create_vehicle_brands_table.sql`
19+
- `2_create_addresses_table.sql`
20+
- `3_create_vehicles_table.sql`
21+
- `4_seed_data.sql`
22+
23+
##### Docker compose structure
24+
1025
- **Image**: `mysql:8.0`
1126
- **Ports**: `3306:3306`
1227
- **Container Name**: `car_rental_db`
@@ -22,6 +37,12 @@ This project uses Docker Compose to manage the development environment. The setu
2237

2338
#### Backend (`backend`)
2439

40+
##### Description
41+
42+
The backend service is a Node.js application built with NestJS. It provides the API endpoints for the frontend to interact with the database. The backend service depends on the `db` service to be running.
43+
44+
##### Docker compose structure
45+
2546
- **Build Context**: `./apps/car-rental-backend`
2647
- **Dockerfile**: `./apps/car-rental-backend/Dockerfile`
2748
- **Command**: `npm run serve:car-rental-backend`
@@ -41,6 +62,12 @@ This project uses Docker Compose to manage the development environment. The setu
4162

4263
#### Frontend (`frontend`)
4364

65+
##### Description
66+
67+
The frontend service is an Angular application that provides the user interface for the car rental application. It depends on the `backend` service to be running to fetch and display data.
68+
69+
##### Docker compose structure
70+
4471
- **Build Context**: `./apps/car-rental`
4572
- **Dockerfile**: `./apps/car-rental/Dockerfile`
4673
- **Command**: `npm run serve:car-rental -- --host 0.0.0.0`
@@ -71,3 +98,66 @@ docker-compose down
7198
```
7299

73100
For more information on Docker Compose, refer to the [official documentation](https://docs.docker.com/compose/).
101+
102+
### Running Locally
103+
104+
To run the application locally, you need to uncomment the lines in `app.module.ts` that configure the database connection for local development:
105+
106+
```ts
107+
import { ConfigModule, ConfigService } from '@nestjs/config';
108+
import { TypeOrmModule } from '@nestjs/typeorm';
109+
import { VehiclesModule } from '../resources/vehicles/vehicles.module';
110+
import { Vehicle } from '../resources/vehicles/entities/vehicle.entity';
111+
import { VehicleBrand } from '../resources/vehicle-brands/entities/vehicle-brand.entity';
112+
import { Address } from '../resources/addresses/entities/address.entity';
113+
114+
@Module({
115+
imports: [
116+
ConfigModule.forRoot({ isGlobal: true }),
117+
TypeOrmModule.forRootAsync({
118+
imports: [ConfigModule],
119+
useFactory: (configService: ConfigService) => ({
120+
type: 'mysql',
121+
// Use it when you run the app in Docker
122+
host: configService.get<string>('DATABASE_HOST'),
123+
port: configService.get<number>('DATABASE_PORT'),
124+
username: configService.get<string>('DATABASE_USER'),
125+
password: configService.get<string>('DATABASE_PASSWORD'),
126+
database: configService.get<string>('DATABASE_NAME'),
127+
// Use it when you run the app locally
128+
// host: 'localhost',
129+
// port: 3306,
130+
// username: 'root',
131+
// password: 'root',
132+
// database: 'car_rental',
133+
entities: [Vehicle, VehicleBrand, Address],
134+
synchronize: true,
135+
}),
136+
inject: [ConfigService],
137+
}),
138+
VehiclesModule,
139+
],
140+
})
141+
export class AppModule {}
142+
```
143+
144+
To run the frontend locally, use the following command:
145+
```sh
146+
npx nx run car-rental:serve
147+
```
148+
149+
To run the backend locally, use the following command:
150+
```sh
151+
npx nx run car-rental-backend:serve
152+
```
153+
Before you run backend service, do not forget to run db service.
154+
155+
### Running Tests
156+
157+
To run tests for all projects, use the following command:
158+
```sh
159+
npx nx run-many --targets=test
160+
```
161+
162+
### VS Code Run Settings
163+
The project includes ```./vscode``` run settings to facilitate running the application locally. Make sure to check the ```.vscode``` folder for predefined configurations.

apps/car-rental-backend/src/app/app.module.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ import { Address } from '../resources/addresses/entities/address.entity';
1414
useFactory: (configService: ConfigService) => ({
1515
type: 'mysql',
1616
// Use it when you run the app in Docker
17-
// host: configService.get<string>('DATABASE_HOST'),
18-
// port: configService.get<number>('DATABASE_PORT'),
19-
// username: configService.get<string>('DATABASE_USER'),
20-
// password: configService.get<string>('DATABASE_PASSWORD'),
21-
// database: configService.get<string>('DATABASE_NAME'),
17+
host: configService.get<string>('DATABASE_HOST'),
18+
port: configService.get<number>('DATABASE_PORT'),
19+
username: configService.get<string>('DATABASE_USER'),
20+
password: configService.get<string>('DATABASE_PASSWORD'),
21+
database: configService.get<string>('DATABASE_NAME'),
2222
// Use it when you run the app locally
23-
host: 'localhost',
24-
port: 3306,
25-
username: 'root',
26-
password: 'root',
27-
database: 'car_rental',
23+
// host: 'localhost',
24+
// port: 3306,
25+
// username: 'root',
26+
// password: 'root',
27+
// database: 'car_rental',
2828
entities: [Vehicle, VehicleBrand, Address],
2929
synchronize: true,
3030
}),

0 commit comments

Comments
 (0)