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.
- User registration with hashed passwords (bcrypt).
- Secure JWT-based authentication with token expiration.
- Create posts associated with authorized users.
- Retrieve posts with caching implemented using Redis.
- Proper error responses for unauthorized access (401) and missing parameters (403).
- API endpoints are documented and accessible via Swagger at
/api
.
- Fully containerized application using Docker Compose.
- Unit and integration tests for CRUD operations, authentication, and caching.
- Node.js: v20.17.0
- pnpm: v9.14.4
- Docker: Ensure Docker and Docker Compose are installed and running
-
Clone the repository:
git clone <repository-url> cd social-network
-
Install dependencies:
pnpm install
-
Set up environment variables: Create a
.env
file in the root directory with the following content:DB_HOST=db DB_PORT=5432 DB_USER=postgres DB_PASSWORD=admin DB_NAME=postgres JWT_SECRET=your_jwt_secret
-
Run the application using Docker Compose:
docker-compose up -d
Once the application is running, Swagger documentation is available at:
http://localhost:3000/api
POST /auth/get-token
: Authenticate a user and retrieve a JWT token.
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).
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).
Run the tests to ensure the application is functioning correctly:
pnpm test
- Unit tests for authentication and CRUD operations.
- Integration tests for major API flows.
src/
├── modules/
│ ├── auth/
│ ├── users/
│ ├── posts/
├── app.module.ts
├── main.ts
├── guards/
├── interceptors/
├── decorators/
- NestJS: Backend framework
- PostgreSQL: Database
- Redis: Caching
- Docker Compose: Container orchestration
- Swagger: API documentation
- Jest: Testing framework
- Add more robust role-based access control.
- Enhance test coverage with edge cases.
- Improve Redis caching strategies for specific user queries.