|
1 | | -# React + TypeScript + Vite |
| 1 | +# SetRsoft |
2 | 2 |
|
3 | | -This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. |
| 3 | +[](https://github.com/setrsoft/setrsoft_app/actions/workflows/ci.yml) |
| 4 | +[](https://discord.gg/BdyfNU9TpR) |
4 | 5 |
|
5 | | -Currently, two official plugins are available: |
| 6 | +## Environment variables |
6 | 7 |
|
7 | | -- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh |
8 | | -- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh |
| 8 | +All variables are listed in **`.env.example`** at the repository root. Before running Docker Compose, copy it once: |
9 | 9 |
|
10 | | -## React Compiler |
| 10 | +```bash |
| 11 | +cp .env.example .env |
| 12 | +``` |
| 13 | + |
| 14 | +Compose loads **`.env`** automatically for `${VAR}` substitution in the YAML files, and each service uses **`env_file: .env`** so containers receive the same values. Django reads the same **`.env`** from the repo root when you run `manage.py` locally (see `backend/setrsoft/settings.py`). |
11 | 15 |
|
12 | | -The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation). |
| 16 | +## Development (Docker) |
13 | 17 |
|
14 | | -## Expanding the ESLint configuration |
| 18 | +From the repository root (after `cp .env.example .env`): |
| 19 | + |
| 20 | +```bash |
| 21 | +docker compose up |
| 22 | +``` |
15 | 23 |
|
16 | | -If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules: |
| 24 | +This starts: |
17 | 25 |
|
18 | | -```js |
19 | | -export default defineConfig([ |
20 | | - globalIgnores(['dist']), |
21 | | - { |
22 | | - files: ['**/*.{ts,tsx}'], |
23 | | - extends: [ |
24 | | - // Other configs... |
| 26 | +| Service | Role | URL / port | |
| 27 | +| --------- | ---------------------------- | ----------------- | |
| 28 | +| `db` | PostgreSQL | `localhost:5432` | |
| 29 | +| `backend` | Django `runserver` (reload) | `http://localhost:8000` | |
| 30 | +| `frontend`| Vite dev server (`npm run dev` in container) | `http://localhost:5173` | |
25 | 31 |
|
26 | | - // Remove tseslint.configs.recommended and replace with this |
27 | | - tseslint.configs.recommendedTypeChecked, |
28 | | - // Alternatively, use this for stricter rules |
29 | | - tseslint.configs.strictTypeChecked, |
30 | | - // Optionally, add this for stylistic rules |
31 | | - tseslint.configs.stylisticTypeChecked, |
| 32 | +Open the app at **http://localhost:5173**. Set **`VITE_API_BASE=http://localhost:8000`** in `.env` so the browser calls the API on port 8000 when the SPA is not served from the same origin. |
32 | 33 |
|
33 | | - // Other configs... |
34 | | - ], |
35 | | - languageOptions: { |
36 | | - parserOptions: { |
37 | | - project: ['./tsconfig.node.json', './tsconfig.app.json'], |
38 | | - tsconfigRootDir: import.meta.dirname, |
39 | | - }, |
40 | | - // other options... |
41 | | - }, |
42 | | - }, |
43 | | -]) |
| 34 | +First-time backend setup (migrations, superuser) is usually run inside the backend container, for example: |
| 35 | + |
| 36 | +```bash |
| 37 | +docker compose exec backend python manage.py migrate |
| 38 | +docker compose exec backend python manage.py createsuperuser |
44 | 39 | ``` |
45 | 40 |
|
46 | | -You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules: |
47 | | - |
48 | | -```js |
49 | | -// eslint.config.js |
50 | | -import reactX from 'eslint-plugin-react-x' |
51 | | -import reactDom from 'eslint-plugin-react-dom' |
52 | | - |
53 | | -export default defineConfig([ |
54 | | - globalIgnores(['dist']), |
55 | | - { |
56 | | - files: ['**/*.{ts,tsx}'], |
57 | | - extends: [ |
58 | | - // Other configs... |
59 | | - // Enable lint rules for React |
60 | | - reactX.configs['recommended-typescript'], |
61 | | - // Enable lint rules for React DOM |
62 | | - reactDom.configs.recommended, |
63 | | - ], |
64 | | - languageOptions: { |
65 | | - parserOptions: { |
66 | | - project: ['./tsconfig.node.json', './tsconfig.app.json'], |
67 | | - tsconfigRootDir: import.meta.dirname, |
68 | | - }, |
69 | | - // other options... |
70 | | - }, |
71 | | - }, |
72 | | -]) |
| 41 | +## Production (Docker) |
| 42 | + |
| 43 | +Production uses **`docker-compose.prod.yml`**: Nginx serves the built SPA and proxies `/api/` and `/admin/` to Gunicorn. Only **port 80** is published; the database and Django are not exposed on the host. |
| 44 | + |
| 45 | +Required in **`.env`** at the repository root (or exported in your shell): |
| 46 | + |
| 47 | +- `POSTGRES_PASSWORD` |
| 48 | +- `SECRET_KEY` |
| 49 | + |
| 50 | +See **`.env.example`** for the full list. Optional values such as `POSTGRES_DB`, `POSTGRES_USER`, `DEBUG`, `ALLOWED_HOSTS`, `TRUST_PROXY`, and **`VITE_API_BASE`** (passed as a Docker **build arg** for the `web` image when you need an absolute API URL in the built SPA) are documented there. |
| 51 | + |
| 52 | +**Start production stack** (build images, run detached): |
| 53 | + |
| 54 | +```bash |
| 55 | +docker compose -f docker-compose.prod.yml up -d --build |
73 | 56 | ``` |
| 57 | + |
| 58 | +With inline env (example): |
| 59 | + |
| 60 | +```bash |
| 61 | +POSTGRES_PASSWORD=your-secure-password SECRET_KEY=your-django-secret-key docker compose -f docker-compose.prod.yml up -d --build |
| 62 | +``` |
| 63 | + |
| 64 | +Then open **http://localhost** (or your server’s hostname). Use **`ALLOWED_HOSTS`** (and HTTPS + `TRUST_PROXY` as already set in compose) when deploying under a real domain. |
| 65 | + |
| 66 | +**Stop:** |
| 67 | + |
| 68 | +```bash |
| 69 | +docker compose -f docker-compose.prod.yml down |
| 70 | +``` |
| 71 | + |
| 72 | +## Local frontend without Docker |
| 73 | + |
| 74 | +You can still run Vite on the host: |
| 75 | + |
| 76 | +```bash |
| 77 | +cd frontend && npm install && npm run dev |
| 78 | +``` |
| 79 | + |
| 80 | +Use this if you prefer not to use the `frontend` service from `docker compose up`. |
| 81 | + |
| 82 | +## Project layout |
| 83 | + |
| 84 | +- `.env.example` — template for all services (Django, PostgreSQL, Vite) |
| 85 | +- `backend/` — Django project (`setrsoft`), API under `/api/` |
| 86 | +- `frontend/` — Vite + React SPA; production image builds static assets and serves them with Nginx |
| 87 | +- `docker-compose.yml` — development |
| 88 | +- `docker-compose.prod.yml` — production |
0 commit comments