This project is a full-stack CRUD application with separate backend and frontend implementations. It features user and product management with authentication and authorization using JWT.
- Language: Go (Golang)
- Database: MongoDB (hosted on MongoDB Atlas)
- GraphQL:
gqlgen
for schema-based GraphQL API generation - Authentication: JSON Web Token (JWT)
- Framework: React.js (using create-vite, version 18.3.1)
- State Management: Redux Toolkit
- GraphQL Client: Apollo Client
- Styling: Tailwind CSS
The project uses the following .env
variables. Ensure these are correctly configured before running the application.
JWT_SECRET=your_jwt_secret
MONGO_USERNAME=your_mongo_username
MONGO_PASSWORD=your_mongo_password
MONGO_URI=your_mongo_connection_uri
MONGO_DB_NAME=your_database_name
- Node.js: Install Node.js (LTS recommended, this project using v22.13.0 and npm 10.9.2).
- Go: Install Go (version 1.23.4 or later).
- MongoDB Atlas Account: Ensure you have a MongoDB Atlas cluster set up.
-
Navigate to the backend directory:
cd backend
-
Install dependencies (if needed):
go mod tidy
-
Run the server:
go run server.go
-
Run the server with data seeding:
go run server.go -seed
-
Initialize
gqlgen
schema:go run github.com/99designs/gqlgen init
-
Modify
schema.graphqls
for new features. -
Regenerate
gqlgen
files:go run github.com/99designs/gqlgen generate
-
Update
schema.resolvers.go
for resolvers and repeat the generation process if further schema changes are needed.
-
Navigate to the frontend directory:
cd frontend
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
User Management:
- Create, update, delete, and fetch user details.
-
Product Management:
- Add, update, delete, and fetch product details.
-
Authentication:
- Secure login with JWT tokens.
-
Future Enhancements:
- JWT blacklisting.
- Refresh tokens for extended sessions.
- Role-based user management (e.g., admin, user).
-
Import Postman Files:
- Import
postman/local-andre-graphql.postman_environment.json
for environment variables - Import
postman/user-product-graphql.postman_collection.json
for API endpoints collection
- Import
-
Set Up Environment:
- Open Postman and select the imported environment "local-andre-graphql"
- Verify the environment variables are correctly set
-
Available Test Endpoints: The collection includes GraphQL queries and mutations for:
- User Management (Create, Read, Update, Delete)
- Product Management (Create, Read, Update, Delete)
- Authentication (Login, Token Validation)
-
Testing Flow:
- Start with the Login mutation to obtain a JWT token
- The token will be automatically set in the environment variables
- Other requests will use this token for authentication
- Test each endpoint in the collection to verify functionality
Ensure your MONGO_URI
is formatted correctly. Example:
mongodb+srv://<username>:<password>@cluster0.mongodb.net/<dbname>?retryWrites=true&w=majority
- Always keep the
schema.graphqls
updated for new API features. - Use the generation commands to ensure the resolvers and types are synced with the schema.
- Navigate to the project root directory:
cd user-product-crud
- Install dependencies for concurrent execution:
npm install
- Run both backend and frontend:
npm run dev