A modern, full-stack blog system built with Go and React, featuring JWT authentication, GORM database persistence, TypeScript safety, auto-generated API clients, and comprehensive APIFox integration.
- Full Blog System: Complete blogging platform with post creation and listing
- Database Persistence: GORM integration with SQLite/MySQL/PostgreSQL support
- Secure Authentication: JWT token-based authentication with bcrypt password hashing
- Blog Post Management: Create, view, and manage blog posts with user attribution
- TypeScript Integration: Full TypeScript support with auto-generated API clients
- Code Generation: OpenAPI Generator for automated frontend and backend models
- Modern UI: Responsive React interface with Ant Design components
- Real-time State Management: MobX for reactive state management
- Protected Routes: Client-side route protection with automatic redirects
- API Documentation: OpenAPI 3.0+ specification with APIFox integration
- CORS Support: Cross-origin resource sharing enabled
- Type Safety: Complete type safety from database to UI components
- Go 1.24+ - High-performance backend service
- Gin Framework v1.10+ - Fast HTTP web framework
- GORM v1.30+ - Go ORM with database abstraction
- SQLite/MySQL/PostgreSQL - Database support with auto-migration
- JWT - JSON Web Token for authentication
- bcrypt - Password hashing and verification
- React 19+ - Modern JavaScript UI library
- TypeScript 5.0+ - Static type checking and enhanced developer experience
- Ant Design 5+ - Enterprise-class UI components
- MobX 6+ & MobX-React-Lite - Simple, scalable state management
- React Router v7+ - Declarative routing
- Generated API Client - Auto-generated TypeScript client from OpenAPI spec
- pnpm - Fast, disk space efficient package manager
- Vite - Fast build tool and development server
- OpenAPI 3.0+ - API specification and documentation
- OpenAPI Generator - Automated TypeScript client and Go model generation
- APIFox - API design, testing, and code generation platform
- Make - Build automation
- Git - Version control
- TypeScript Compiler - Type checking and compilation
- Go 1.24 or higher
- Node.js 18.0 or higher
- pnpm package manager
- OpenAPI Generator CLI (automatically installed)
- SQLite (default), MySQL 8+, or PostgreSQL 16+ (optional)
git clone https://github.com/koriyoshi2041/Assignment2.git
cd Assignment2cd backend
go mod tidy
go run .The backend server will start on http://localhost:8080 with SQLite database
cd frontend
pnpm install
pnpm devThe frontend application will be available at http://localhost:5173
- Open your browser to
http://localhost:5173 - Use the test credentials:
- Admin:
admin/password123 - User:
user1/mypassword
- Admin:
- Create blog posts, view the blog feed, and test authentication
Assignment2/
βββ backend/ # Go backend service
β βββ main.go # Main application entry point
β βββ models/ # GORM database models
β β βββ user.go # User model with associations
β β βββ post.go # Post model with relationships
β βββ api_models/ # Auto-generated API models from OpenAPI
β βββ utils.go # Utility functions
β βββ gen_api.sh # API model generation script
β βββ go.mod # Go module dependencies
β βββ go.sum # Go module checksums
βββ frontend/ # React TypeScript frontend application
β βββ src/
β β βββ api/ # Auto-generated TypeScript API client
β β β βββ apis/ # API endpoint implementations
β β β βββ models/ # TypeScript type definitions
β β β βββ runtime.ts
β β βββ components/ # React TypeScript components
β β β βββ LoginPage.tsx
β β β βββ BlogPage.tsx
β β β βββ CreatePostForm.tsx
β β β βββ PostList.tsx
β β β βββ Header.tsx
β β β βββ ProtectedRoute.tsx
β β βββ stores/ # MobX stores with TypeScript
β β β βββ authStore.ts
β β β βββ blogStore.ts
β β β βββ index.ts
β β βββ App.tsx # Main application component
β β βββ main.tsx # Application entry point
β βββ gen_api.sh # API client generation script
β βββ openapitools.json # OpenAPI Generator configuration
β βββ package.json # Frontend dependencies
β βββ tsconfig.json # TypeScript configuration
β βββ vite.config.js # Vite configuration
βββ openapi.yml # OpenAPI specification
βββ Makefile # Build automation
βββ README.md # Project documentation
- POST
/user/login- User authentication- Request:
{"username": "string", "password": "string"} - Response:
{"token": "jwt_token"}
- Request:
- POST
/user/logout- User logout- Headers:
Authorization: Bearer <token> - Response:
{"message": "Logged out successfully"}
- Headers:
- GET
/user/info- Get current user information- Headers:
Authorization: Bearer <token> - Response:
{"nick_name": "string"}
- Headers:
- POST
/posts- Create a new blog post- Headers:
Authorization: Bearer <token> - Request:
{"content": "string"} - Response:
{"id": 1, "content": "string", "author_nickname": "string", "created_at": "2025-01-01T00:00:00Z"}
- Headers:
- GET
/posts- Get all blog posts- Response:
[{"id": 1, "content": "string", "author_nickname": "string", "created_at": "2025-01-01T00:00:00Z"}]
- Response:
make run-backend # Start backend server
make run-frontend # Start frontend development server
make build-backend # Build backend binary
make build-frontend # Build frontend for production
make clean # Clean build artifactsThe project uses OpenAPI Generator to automatically generate both frontend and backend code:
Frontend TypeScript API Client:
cd frontend
./gen_api.sh # Generate TypeScript API client from OpenAPI specBackend Go API Models:
cd backend
./gen_api.sh # Generate Go API models from OpenAPI specThis generates:
- Frontend:
AuthenticationApi,PostsApi,UserInformationApiwith TypeScript types - Backend: Go structs for requests/responses with proper JSON tags
- Type Definitions: Complete type safety across the entire stack
- Runtime: HTTP client with proper error handling
cd frontend
pnpm run build # Build with TypeScript compilation
npx tsc --noEmit # Type checking onlyThe application supports multiple database backends via environment variables:
SQLite (Default):
# No configuration needed - uses ./blog_system.db
go run .MySQL:
export DB_TYPE=mysql
export DB_HOST=localhost
export DB_PORT=3306
export DB_USER=root
export DB_PASSWORD=password
export DB_NAME=blog_system
go run .PostgreSQL:
export DB_TYPE=postgres
export DB_HOST=localhost
export DB_PORT=5432
export DB_USER=postgres
export DB_PASSWORD=password
export DB_NAME=blog_system
go run .- Start both backend and frontend servers
- Navigate to
http://localhost:5173 - Test login functionality with provided credentials
- Create and view blog posts
- Test logout functionality
- Verify protected route access and JWT token handling
- Verify database persistence by restarting servers
- Import the
openapi.ymlfile into APIFox - Configure environment variables
- Run the provided test cases
- Verify all endpoints return expected responses
This project demonstrates proper APIFox workflow:
- Import
openapi.ymlinto APIFox - Complete API specification with examples
- Auto-generated interactive documentation
- Export OpenAPI JSON from APIFox
- Use OpenAPI Generator CLI to generate TypeScript client
- Automated type-safe API integration
- APIFox mock services for parallel development
- Automated API testing and validation
- Team collaboration through shared specifications
APIFox Design β OpenAPI Export β OpenAPI Generator β TypeScript ClientThis replaces manual API coding with automated, type-safe client generation.
cd backend
go build -o server .
./servercd frontend
pnpm run build
# Deploy the dist/ folder to your static hosting service- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Gin Framework for the excellent Go web framework
- Ant Design for the beautiful React UI components
- APIFox for comprehensive API development tools
For questions or support, please open an issue in the GitHub repository.
Note: This is an educational project demonstrating modern full-stack web development practices with Go, React, TypeScript, GORM, and proper APIFox workflow with automated code generation for both frontend and backend.