This project is a full-stack application consisting of:
- User Service: A Node.js + TypeScript + Apollo GraphQL microservice connected to PostgreSQL.
- Client: A React frontend served with Nginx.
- Database: PostgreSQL database managed through Docker.
- User Management:
- Create, Read, Update, Delete (CRUD) operations on users via GraphQL.
- Load Balancing:
- User service runs with multiple replicas behind an Nginx reverse proxy.
- Frontend:
- React app served via Nginx to interact with the user service.
- Docker installed on your machine.
- Docker Compose installed.
├── client/ # React frontend
│ ├── src/ # React source code
│ ├── public/ # Static assets
│ ├── Dockerfile # Docker setup for the React app
│ └── nginx.conf # Nginx configuration for serving React
├── user/ # User service (Node.js + GraphQL)
│ ├── src/ # Source code for the Node.js service
│ ├── Dockerfile # Docker setup for the Node.js service
│ ├── .env # Environment variables for the user service
│ └── nginx/ # Nginx reverse proxy config
├── docker-compose.yml # Orchestrates the multi-service app
└── README.md # Project documentation
git clone <repository-url>
cd <repository-folder>
Inside the user/.env file, ensure the following variables are set:
# SERVICE ENV
DB_HOST=db
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_NAME=users_db
# USER DB ENV
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=users_db
Run the following command to build and launch all services:
docker-compose up --build && docker-compose up
This will:
-
Build the user service and client Docker images.
-
Start the PostgreSQL database container.
-
Start Nginx for load balancing and frontend serving.
-
Access the Application
Frontend: Open http://localhost:3000 to view the React app. GraphQL Playground: Open http://localhost:4000 to interact with the GraphQL API.
Fetch All Users
query {
users {
id
firstName
lastName
birthDate
city
}
}Mutations Create User
mutation CreateUser(
$firstName: String!
$lastName: String!
$birthDate: DateTime!
$city: String!
) {
createUser(
firstName: $firstName
lastName: $lastName
birthDate: $birthDate
city: $city
) {
id
firstName
lastName
}
}Update user
mutation UpdateUser(
$id: ID!
$firstName: String
$lastName: String
$birthDate: DateTime
$city: String
) {
updateUser(
id: $id
firstName: $firstName
lastName: $lastName
birthDate: $birthDate
city: $city
) {
id
firstName
lastName
}
}Delete User
mutation DeleteUser($id: ID!) {
deleteUser(id: $id)
}Ensure Docker Compose runs successfully without errors. Check logs using:
docker-compose logs-
Add authentication and authorization.
-
Integrate CI/CD pipelines for automated testing and deployment.
-
Add monitoring and logging for better observability.