React + TypeScript web application for the microservices event management platform.
The Frontend Service is a single-page application (SPA) built with React and TypeScript that provides the user interface for:
- User authentication and registration
- Event creation and browsing
- Post creation and feed
- Friend management
- Interest-based content discovery
Frontend (React) β API Gateway β Composite Service β Atomic Services
- Framework: React 18 with TypeScript
- Build Tool: Create React App
- State Management: React Context API
- Routing: React Router
- Authentication: Firebase Authentication
- Deployment: Cloud Storage (Static Website Hosting)
- Node.js 16+
- npm or yarn
- Firebase project with Authentication enabled
-
Install dependencies
npm install # or yarn install -
Configure Firebase Create a
.envfile in the root directory:REACT_APP_API_URL=http://localhost:8000 REACT_APP_FIREBASE_API_KEY=your-api-key REACT_APP_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com REACT_APP_FIREBASE_PROJECT_ID=your-project-id REACT_APP_FIREBASE_STORAGE_BUCKET=your-project.appspot.com REACT_APP_FIREBASE_MESSAGING_SENDER_ID=your-sender-id REACT_APP_FIREBASE_APP_ID=your-app-id
-
Run development server
npm start # or yarn startThe app will open at
http://localhost:3000 -
Build for production
npm run build # or yarn buildThis creates an optimized production build in the
build/directory.
| Variable | Description | Default | Required |
|---|---|---|---|
REACT_APP_API_URL |
API Gateway URL | http://localhost:8000 |
Yes |
REACT_APP_FIREBASE_API_KEY |
Firebase API key | - | Yes |
REACT_APP_FIREBASE_AUTH_DOMAIN |
Firebase auth domain | - | Yes |
REACT_APP_FIREBASE_PROJECT_ID |
Firebase project ID | - | Yes |
REACT_APP_FIREBASE_STORAGE_BUCKET |
Firebase storage bucket | - | Yes |
REACT_APP_FIREBASE_MESSAGING_SENDER_ID |
Firebase messaging sender ID | - | Yes |
REACT_APP_FIREBASE_APP_ID |
Firebase app ID | - | Yes |
frontend-service/
βββ public/ # Static files
β βββ index.html # HTML template
β βββ ...
βββ src/
β βββ components/ # React components
β β βββ Auth/ # Authentication components
β β βββ Events/ # Event-related components
β β βββ Posts/ # Post-related components
β β βββ ...
β βββ contexts/ # React Context providers
β β βββ AuthContext.tsx
β βββ services/ # API service functions
β β βββ api.ts
β βββ types/ # TypeScript type definitions
β βββ utils/ # Utility functions
β βββ App.tsx # Main App component
β βββ index.tsx # Entry point
βββ package.json
βββ tsconfig.json
βββ README.md
- Email/password registration and login
- Firebase Authentication integration
- Protected routes
- Automatic token refresh
- Logout functionality
- Create, view, edit, and delete events
- Event search and filtering
- Interest-based event discovery
- Event details with location and time
- Create, view, edit, and delete posts
- Feed with pagination
- Like/unlike posts
- Interest-based post discovery
- User profile viewing and editing
- Profile picture upload
- Interest management
- User search
- Send and accept friend requests
- View friends list
- Remove friends
- User registers/logs in via Firebase Authentication
- Firebase returns ID token
- Frontend stores token in localStorage
- All API requests include token in
Authorization: Bearer <token>header - API Gateway validates token and forwards request with
x-firebase-uidheader
The frontend communicates with the backend through the API Gateway:
// Example API call
const response = await fetch(`${API_URL}/api/users/me`, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});All API calls are centralized in src/services/api.ts.
docker build -t frontend-service .docker run -p 3000:80 \
-e REACT_APP_API_URL=https://api-gateway.run.app \
frontend-serviceThe frontend is deployed as static files to Cloud Storage:
-
Build the application
npm run build
-
Create Cloud Storage bucket
gsutil mb gs://your-bucket-name
-
Upload build files
gsutil -m cp -r build/* gs://your-bucket-name/ -
Configure for static website hosting
gsutil web set -m index.html -e index.html gs://your-bucket-name gsutil iam ch allUsers:objectViewer gs://your-bucket-name -
Access the website
https://storage.googleapis.com/your-bucket-name/index.html
See ../GCP_DEPLOYMENT_GUIDE.md for automated deployment.
npm test
# or
yarn testnpm run build
npm install -g serve
serve -s buildnpm start- Start development servernpm run build- Build for productionnpm test- Run testsnpm run eject- Eject from Create React App (irreversible)
The frontend includes error handling for:
- Network errors (API unavailable)
- Authentication errors (token expired)
- Validation errors (form inputs)
- 404 errors (page not found)
Error messages are displayed to users via toast notifications or inline form errors.
- Type Safety: All components and functions use TypeScript
- Component Reusability: Shared components in
components/directory - State Management: Context API for global state (auth, user)
- API Abstraction: Centralized API calls in
services/api.ts - Error Boundaries: React error boundaries for graceful error handling
- Loading States: Loading indicators for async operations
- The frontend is a SPA, so all routes are handled client-side
- Firebase Authentication handles password reset, email verification, etc.
- Images are stored in Firebase Storage or Cloud Storage
- The app uses React Router for navigation
When adding new features:
- Create components in appropriate directories
- Add TypeScript types in
types/directory - Add API calls to
services/api.ts - Update routing in
App.tsx - Test with different screen sizes (responsive design)