|
1 | | -This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app). |
| 1 | +# FastAPI Project - Frontend (Next.js) |
2 | 2 |
|
3 | | -## Getting Started |
| 3 | +The frontend is built with [Next.js 15](https://nextjs.org/), [React](https://reactjs.org/), [TypeScript](https://www.typescriptlang.org/), [TanStack Query](https://tanstack.com/query), [Tailwind CSS](https://tailwindcss.com/), and [shadcn/ui](https://ui.shadcn.com/). |
4 | 4 |
|
5 | | -First, run the development server: |
| 5 | +## Frontend development |
| 6 | + |
| 7 | +Before you begin, ensure that you have either the Node Version Manager (nvm) or Fast Node Manager (fnm) installed on your system. |
| 8 | + |
| 9 | +* To install fnm follow the [official fnm guide](https://github.com/Schniz/fnm#installation). If you prefer nvm, you can install it using the [official nvm guide](https://github.com/nvm-sh/nvm#installing-and-updating). |
| 10 | + |
| 11 | +* After installing either nvm or fnm, proceed to the `frontend-nextjs` directory: |
| 12 | + |
| 13 | +```bash |
| 14 | +cd frontend-nextjs |
| 15 | +``` |
| 16 | +* If the Node.js version specified in the `.nvmrc` file isn't installed on your system, you can install it using the appropriate command: |
| 17 | + |
| 18 | +```bash |
| 19 | +# If using fnm |
| 20 | +fnm install |
| 21 | + |
| 22 | +# If using nvm |
| 23 | +nvm install |
| 24 | +``` |
| 25 | + |
| 26 | +* Once the installation is complete, switch to the installed version: |
| 27 | + |
| 28 | +```bash |
| 29 | +# If using fnm |
| 30 | +fnm use |
| 31 | + |
| 32 | +# If using nvm |
| 33 | +nvm use |
| 34 | +``` |
| 35 | + |
| 36 | +* Within the `frontend-nextjs` directory, install the necessary NPM packages: |
| 37 | + |
| 38 | +```bash |
| 39 | +npm install |
| 40 | +``` |
| 41 | + |
| 42 | +* And start the live server with the following `npm` script: |
6 | 43 |
|
7 | 44 | ```bash |
8 | 45 | npm run dev |
9 | | -# or |
10 | | -yarn dev |
11 | | -# or |
12 | | -pnpm dev |
13 | | -# or |
14 | | -bun dev |
15 | 46 | ``` |
16 | 47 |
|
17 | | -Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. |
| 48 | +* Then open your browser at http://localhost:3000/. |
| 49 | + |
| 50 | +Notice that this live server is not running inside Docker, it's for local development, and that is the recommended workflow. Once you are happy with your frontend, you can build the frontend Docker image and start it, to test it in a production-like environment. But building the image at every change will not be as productive as running the local development server with live reload. |
| 51 | + |
| 52 | +Check the file `package.json` to see other available options. |
| 53 | + |
| 54 | +### Technology Stack |
| 55 | + |
| 56 | +This Next.js frontend uses: |
| 57 | + |
| 58 | +- **Next.js 15** with App Router for the React framework |
| 59 | +- **Tailwind CSS v4** for styling with modern CSS features |
| 60 | +- **shadcn/ui** for beautiful, accessible UI components |
| 61 | +- **Lucide React** for consistent iconography |
| 62 | +- **TanStack Query** for server state management |
| 63 | +- **TypeScript** for type safety |
| 64 | +- **Generated API Client** for backend integration |
| 65 | + |
| 66 | +### Removing the frontend |
| 67 | + |
| 68 | +If you are developing an API-only app and want to remove the frontend, you can do it easily: |
18 | 69 |
|
19 | | -You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. |
| 70 | +* Remove the `./frontend-nextjs` directory. |
20 | 71 |
|
21 | | -This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel. |
| 72 | +* In the `docker-compose.yml` file, remove the whole service / section `frontend-nextjs`. |
22 | 73 |
|
23 | | -## Learn More |
| 74 | +* In the `docker-compose.override.yml` file, remove the whole service / section `frontend-nextjs`. |
24 | 75 |
|
25 | | -To learn more about Next.js, take a look at the following resources: |
| 76 | +Done, you have a frontend-less (api-only) app. 🤓 |
26 | 77 |
|
27 | | -- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. |
28 | | -- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. |
| 78 | +--- |
29 | 79 |
|
30 | | -You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome! |
| 80 | +If you want, you can also remove the `FRONTEND` environment variables from: |
| 81 | + |
| 82 | +* `.env` |
| 83 | +* `./scripts/*.sh` |
| 84 | + |
| 85 | +But it would be only to clean them up, leaving them won't really have any effect either way. |
| 86 | + |
| 87 | +## Generate Client |
| 88 | + |
| 89 | +### Automatically |
| 90 | + |
| 91 | +* Activate the backend virtual environment. |
| 92 | +* From the top level project directory, run the script: |
| 93 | + |
| 94 | +```bash |
| 95 | +./scripts/generate-client.sh |
| 96 | +``` |
31 | 97 |
|
32 | | -## Deploy on Vercel |
| 98 | +* Commit the changes. |
33 | 99 |
|
34 | | -The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. |
| 100 | +### Manually |
| 101 | + |
| 102 | +* Start the Docker Compose stack. |
| 103 | + |
| 104 | +* Download the OpenAPI JSON file from `http://localhost/api/v1/openapi.json` and copy it to a new file `openapi.json` at the root of the `frontend-nextjs` directory. |
| 105 | + |
| 106 | +* To generate the frontend client, run: |
| 107 | + |
| 108 | +```bash |
| 109 | +npm run generate-client |
| 110 | +``` |
| 111 | + |
| 112 | +* Commit the changes. |
| 113 | + |
| 114 | +## Features |
| 115 | + |
| 116 | +This Next.js frontend includes: |
| 117 | + |
| 118 | +- **Authentication**: JWT-based authentication with login/logout functionality |
| 119 | +- **Dashboard**: Modern dashboard with sidebar navigation |
| 120 | +- **User Management**: User profile and settings management |
| 121 | +- **Responsive Design**: Mobile-first responsive design with dark mode support |
| 122 | +- **Type Safety**: Full TypeScript integration with generated API types |
| 123 | +- **Modern UI**: Beautiful components built with shadcn/ui and Tailwind CSS |
| 124 | + |
| 125 | +## Project Structure |
| 126 | + |
| 127 | +``` |
| 128 | +frontend-nextjs/ |
| 129 | +├── app/ # Next.js App Router pages |
| 130 | +├── components/ # Reusable React components |
| 131 | +│ └── ui/ # shadcn/ui components |
| 132 | +├── lib/ # Utility functions and configurations |
| 133 | +├── hooks/ # Custom React hooks |
| 134 | +├── client/ # Generated API client |
| 135 | +├── public/ # Static assets |
| 136 | +└── styles/ # Global styles and Tailwind config |
| 137 | +``` |
| 138 | + |
| 139 | +## Development |
| 140 | + |
| 141 | +### Adding New Components |
| 142 | + |
| 143 | +To add new shadcn/ui components: |
| 144 | + |
| 145 | +```bash |
| 146 | +npx shadcn@latest add [component-name] |
| 147 | +``` |
| 148 | + |
| 149 | +### Building for Production |
| 150 | + |
| 151 | +```bash |
| 152 | +npm run build |
| 153 | +``` |
| 154 | + |
| 155 | +### Running Tests |
| 156 | + |
| 157 | +```bash |
| 158 | +npm run test |
| 159 | +``` |
| 160 | + |
| 161 | +## Docker |
| 162 | + |
| 163 | +The frontend is containerized and can be run with Docker: |
| 164 | + |
| 165 | +```bash |
| 166 | +# Build the image |
| 167 | +docker build -t frontend-nextjs . |
| 168 | + |
| 169 | +# Run the container |
| 170 | +docker run -p 3000:3000 frontend-nextjs |
| 171 | +``` |
35 | 172 |
|
36 | | -Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. |
| 173 | +Or use the provided Docker Compose setup from the project root. |
0 commit comments