https://github.com/zlarkisz/social-network
https://github.com/zlarkisz/social-network
api backend docker jwt nestjs postgresql redis swagger unit-tests
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/zlarkisz/social-network
- Owner: zlarkisz
- Created: 2024-11-23T14:22:29.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-11T17:34:45.000Z (over 1 year ago)
- Last Synced: 2025-01-05T22:09:37.751Z (over 1 year ago)
- Language: TypeScript
- Size: 536 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ Social Network API
## ๐ Description
The Social Network API is a backend application built with NestJS, designed to support user registration, post creation, and interactions between users. It leverages PostgreSQL for data storage, Redis for caching, and Docker for containerization. Swagger documentation is integrated to ensure easy API exploration.
---
## โจ Features
### ๐ฅ User Management
- User registration with hashed passwords (bcrypt).
- Secure JWT-based authentication with token expiration.
### ๐ Post Management
- Create posts associated with authorized users.
- Retrieve posts with caching implemented using Redis.
### โ ๏ธ Error Handling
- Proper error responses for unauthorized access (401) and missing parameters (403).
### ๐ Swagger Documentation
- API endpoints are documented and accessible via Swagger at `/api`.
### ๐ณ Containerized Deployment
- Fully containerized application using Docker Compose.
### ๐งช Testing
- Unit and integration tests for CRUD operations, authentication, and caching.
---
## ๐ง Prerequisites
- **Node.js**: v20.17.0
- **pnpm**: v9.14.4
- **Docker**: Ensure Docker and Docker Compose are installed and running
---
## ๐ฆ Installation
1. Clone the repository:
```bash
git clone
cd social-network
```
2. Install dependencies:
```bash
pnpm install
```
3. Set up environment variables:
Create a `.env` file in the root directory with the following content:
```env
DB_HOST=db
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=admin
DB_NAME=postgres
JWT_SECRET=your_jwt_secret
```
4. Run the application using Docker Compose:
```bash
docker-compose up -d
```
---
## ๐ API Documentation
Once the application is running, Swagger documentation is available at:
```
http://localhost:3000/api
```
### ๐ Endpoints
#### ๐ Authentication
- `POST /auth/get-token`: Authenticate a user and retrieve a JWT token.
#### ๐ค Users
- `POST /users`: Register a new user.
- `GET /users`: Retrieve a list of all users (protected).
- `GET /users/:id`: Retrieve details of a specific user (protected).
#### ๐ Posts
- `POST /posts`: Create a new post (protected).
- `GET /posts`: Retrieve all posts with caching (protected).
- `GET /posts/user/:userId`: Retrieve posts by a specific user ID (protected).
---
## ๐งช Testing
Run the tests to ensure the application is functioning correctly:
```bash
pnpm test
```
### ๐งช Tests include:
- Unit tests for authentication and CRUD operations.
- Integration tests for major API flows.
---
## ๐ Project Structure
```
src/
โโโ modules/
โ โโโ auth/
โ โโโ users/
โ โโโ posts/
โโโ app.module.ts
โโโ main.ts
โโโ guards/
โโโ interceptors/
โโโ decorators/
```
---
## ๐ ๏ธ Key Technologies
- **NestJS**: Backend framework
- **PostgreSQL**: Database
- **Redis**: Caching
- **Docker Compose**: Container orchestration
- **Swagger**: API documentation
- **Jest**: Testing framework
---
## ๐ Future Improvements
- Add more robust role-based access control.
- Enhance test coverage with edge cases.
- Improve Redis caching strategies for specific user queries.