A full-stack blog application with a Node.js/TypeScript API backend and React/TypeScript frontend. This application allows users to create an account, publish blog posts with images, and interact with other users' content.
- User authentication (signup, login, profile)
- Create, read, update, and delete blog posts
- Image upload functionality using AWS S3
- Protected routes for authenticated users only
- unprotected routes where user can see blogs
blog-assignment/
├── api/ # Backend API
│ ├── prisma/ # Database schema and migrations
│ ├── src/ # Backend source code
│ │ ├── middleware/ # Authentication middleware
│ │ ├── routes/ # API routes
│ │ ├── storage/ # S3 storage configuration
│ │ └── swagger/ # API documentation
│ └── Dockerfile # Docker configuration for API
├── frontend/ # Frontend React application
│ ├── src/ # Frontend source code
│ │ ├── components/ # Reusable UI components
│ │ ├── context/ # React context providers
│ │ ├── pages/ # Application pages
│ │ ├── services/ # API service integrations
│ │ └── types/ # TypeScript type definitions
│ └── vite.config.ts # Vite configuration
└── docker-compose.yaml # Docker Compose configuration
- Node.js (v18 or later)
- NPM or Yarn
- PostgreSQL database
- AWS Account (for S3 image storage)
- Git
- Docker
- Docker Compose (usually included with Docker Desktop)
You can set up this project either manually or using Docker.
-
Navigate to the API directory:
cd api -
Install dependencies:
npm install
-
Create a
.envfile based on the.env.examplefile:cp .env.example .env
-
Update the
.envfile with your PostgreSQL database URL, secure secret key, and AWS credentials:DATABASE_URL="postgresql://username:password@localhost:5432/blog-assignment?schema=public" SECRET_KEY="your_secure_secret_key" AWS_ACCESS_KEY_ID="your_aws_access_key" AWS_SECRET_ACCESS_KEY="your_aws_secret_key" AWS_REGION="your_aws_region" AWS_S3_BUCKET="your_s3_bucket_name" PORT=3002 -
Apply the database migrations:
npx prisma migrate dev --name the migration comment
-
Generate Prisma client:
npx prisma generate
-
Start the development server:
npm run dev
The API server will be running at http://localhost:3002
-
Access Swagger API documentation at:
http://localhost:3002/docs
-
Navigate to the frontend directory:
cd frontend -
Install dependencies:
npm install
-
Start the development server:
npm run dev
The frontend development server will typically run at http://localhost:5173
This project includes Docker configuration for easy setup and deployment.
-
Make sure Docker and Docker Compose are installed on your machine.
-
Create a
.envfile in the backend directory with necessary environment variables. -
From the root directory of the project, run:
docker-compose up -d
This will start the API server in detached mode.
-
To view logs from the containers:
docker-compose logs -f
-
Access the API at http://localhost:3002 and Swagger documentation at http://localhost:3002/docs
-
To stop the containers:
docker-compose down
If you make changes to the Dockerfile or need to rebuild the containers:
docker-compose up -d --buildThe API comes with comprehensive Swagger documentation that allows you to explore and test all available endpoints.
- Start the API server as described in the setup instructions.
- Open your browser and navigate to http://localhost:3002/docs
-
Exploring Endpoints: All available endpoints are grouped by tags (auth, posts).
-
Authentication:
- First, create an account using the
/auth/signupendpoint - Then, obtain a JWT token by logging in with the
/auth/loginendpoint - Copy the token from the response
- Click the "Authorize" button at the top of the page
- Enter the token in the format:
Bearer your-token-here - Now you can access protected endpoints
- First, create an account using the
-
Testing Endpoints:
- Click on an endpoint to expand it
- Click "Try it out"
- Fill in the required parameters
- Click "Execute"
- View the response below
POST /auth/signup- Register a new userPOST /auth/login- Login a userGET /auth/profile- Get current user profile (requires authentication)
GET /posts- Get all postsGET /posts/:id- Get a specific postGET /posts/my-posts- Get current user's posts (requires authentication)POST /posts- Create a new post (requires authentication)PUT /posts/:id- Update a post (requires authentication)DELETE /posts/:id- Delete a post (requires authentication)
- Node.js - JavaScript runtime
- Express - Web framework
- TypeScript - Programming language
- Prisma - Next-generation ORM for Node.js
- PostgreSQL - Relational database
- JSON Web Token (JWT) - Authentication mechanism
- bcrypt - Password hashing
- AWS SDK - S3 integration for image uploads
- Multer - File upload middleware
- Zod - Schema validation library
- Swagger - API documentation
- React - UI library
- TypeScript - Programming language
- ViteJS - Build tool and development server
- React Router - Client-side routing
- React Hook Form - Form handling
- AxiosJS - HTTP client
- TailwindCSS - Utility-first CSS framework
- Lucide-React - Icon library
- React-Toastify - Toast notifications
- Date-fns - Date utility library
ISC
