|
1 | | -# Codebuilder Webapp |
| 1 | +# Codebuilder Frontend |
2 | 2 |
|
3 | 3 | [](https://github.com/codebuilderinc/codebuilder-frontend/actions/workflows/deploy-docker.yml) |
4 | 4 |
|
| 5 | +Next.js frontend for Codebuilder. |
5 | 6 |
|
6 | | -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). |
| 7 | +## Environment Files |
7 | 8 |
|
8 | | -## Getting Started |
| 9 | +- `pnpm dev` (Next.js dev server) loads environment variables in this order: |
| 10 | + - `.env.local` (preferred for local-only overrides) |
| 11 | + - `.env` |
| 12 | +- Docker Compose loads `.env` because `docker-compose.yml` explicitly uses `env_file: ./.env`. |
9 | 13 |
|
10 | | -First, setup your mysql database and edit the .env.example file. |
| 14 | +Important: inside Docker, Postgres must be reached via `db:5432` (service name + container port), not `localhost`. |
11 | 15 |
|
12 | | -```bash |
13 | | -cp .env.example .env.local |
| 16 | +## Commands |
| 17 | + |
| 18 | +Run any command as: |
| 19 | + |
| 20 | +```bash |
| 21 | +pnpm <command> |
14 | 22 | ``` |
15 | 23 |
|
16 | | -Run the development server: |
| 24 | +List all available commands: |
17 | 25 |
|
18 | 26 | ```bash |
19 | | -npm run dev |
20 | | -# or |
21 | | -yarn dev |
22 | | -# or |
23 | | -pnpm dev |
24 | | -# or |
25 | | -bun dev |
| 27 | +pnpm run |
26 | 28 | ``` |
27 | 29 |
|
28 | | -Build the production Docker container: |
| 30 | +### Core |
| 31 | + |
29 | 32 | ```bash |
30 | | -docker run -d --network host -p 3000:3000 --env-file .env --name codebuilder-webapp codebuilder-webapp:latest |
| 33 | +pnpm dev |
| 34 | +pnpm build |
| 35 | +pnpm build:static |
| 36 | +pnpm start |
| 37 | +pnpm lint |
31 | 38 | ``` |
32 | 39 |
|
33 | | -Note: The production website will automatically build & deploy through a GH action anytime a push is made to main. |
| 40 | +- `dev`: Start Next.js dev server (Turbopack). |
| 41 | +- `build`: Production build. |
| 42 | +- `build:static`: Static export build (only if export mode is supported). |
| 43 | +- `start`: Run production server from `.next` build output. |
| 44 | +- `lint`: Run linting. |
34 | 45 |
|
35 | | -Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. |
| 46 | +### Local DB (for development) |
36 | 47 |
|
37 | | -You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. |
| 48 | +```bash |
| 49 | +pnpm dev:db:start |
| 50 | +pnpm dev:db:stop |
| 51 | +pnpm dev:db:prepare |
| 52 | +``` |
| 53 | + |
| 54 | +- `dev:db:start`: Start the local Postgres container using `docker-compose.local.yml`. |
| 55 | +- `dev:db:stop`: Stop/remove the local Postgres container. |
| 56 | +- `dev:db:prepare`: Create the Prisma shadow database inside Postgres (safe to re-run). |
38 | 57 |
|
39 | | -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. |
| 58 | +### Prisma |
40 | 59 |
|
41 | | -## Learn More |
| 60 | +```bash |
| 61 | +pnpm prisma:migrate |
| 62 | +pnpm prisma:generate |
| 63 | +pnpm prisma:studio |
| 64 | +``` |
42 | 65 |
|
43 | | -To learn more about Next.js, take a look at the following resources: |
| 66 | +- `prisma:migrate`: Run Prisma migrations in development mode. |
| 67 | +- `prisma:generate`: Regenerate Prisma client. |
| 68 | +- `prisma:studio`: Launch Prisma Studio. |
44 | 69 |
|
45 | | -- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. |
46 | | -- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. |
| 70 | +### Docker (Production / Server) |
47 | 71 |
|
48 | | -You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome! |
| 72 | +```bash |
| 73 | +pnpm prod:up |
| 74 | +pnpm prod:down |
| 75 | +pnpm prod:logs |
| 76 | +pnpm prod:reset |
| 77 | +``` |
49 | 78 |
|
50 | | -## Deploy on Vercel |
| 79 | +- `prod:up`: Rebuild and redeploy the Docker Compose stack (frontend + db). This is the main manual deploy command. |
| 80 | +- `prod:down`: Stop/remove the stack containers and networks (does not delete external volumes unless `--volumes` is used). |
| 81 | +- `prod:logs`: Tail logs for the `frontend` service. |
| 82 | +- `prod:reset`: WARNING: brings the stack down with `--volumes` and starts fresh (will wipe DB data). |
51 | 83 |
|
52 | | -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. |
| 84 | +## CI / Deployment |
53 | 85 |
|
54 | | -Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. |
| 86 | +On push to `main`, the GitHub Actions workflow rebuilds and redeploys the Docker services on the self-hosted runner. |
55 | 87 |
|
56 | 88 | ## Activity |
57 | 89 |  |
0 commit comments