Skip to content

Commit b2d770b

Browse files
Merge pull request #2 from setrsoft/import-1
Import 1
2 parents b9d1b78 + 09fcec5 commit b2d770b

33 files changed

Lines changed: 888 additions & 131 deletions

‎.context/architecture.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SetRsoft Architecture Overview
2+
3+
This document provides a concise overview of the SetRsoft project's core architecture. It is intended to help AI agents quickly understand the technology stack and repository structure.
4+
5+
## 1. Technology Stack
6+
7+
### Frontend
8+
- **Framework:** React 19 built with Vite.
9+
- **Language:** TypeScript.
10+
- **Styling:** Tailwind CSS v4 (configured via `@theme` in `src/index.css`). Design follows the "Stitch" UI charter ("The Kinetic Monolith").
11+
- **Routing:** React Router v7.
12+
- **State/Data Fetching:** React Query (TanStack Query v5).
13+
- **Internationalization (i18n):** `react-i18next` supporting multiple languages (EN, FR, DE, RU, CN).
14+
15+
### Backend
16+
- **Framework:** Django (Python).
17+
- **Database:** PostgreSQL 16.
18+
19+
### Infrastructure & Deployment
20+
- **Containerization:** Docker & Docker Compose.
21+
- **Services:** `db` (Postgres), `backend` (Django runserver), `frontend` (Vite dev server).
22+
23+
## 2. Directory Structure
24+
25+
- `/frontend/` - Contains the React single-page application.
26+
- `src/app/` - App-wide layout (`Root.tsx`), global routing, and main entry providers.
27+
- `src/features/` - Domain-specific modules (e.g., `showcase`, `gym`, `editor`).
28+
- `src/shared/` - Shared UI components (e.g., `Footer`, `LanguageSwitcher`), hooks, and utilities.
29+
- `src/locales/` - JSON files for i18n translations.
30+
- `/backend/` - Contains the Django server, API definitions, and models.
31+
- `/docker-compose.yml` - Defines the local development environment using containerized services.

‎.env.example‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copy to ".env" at the repository root (Docker Compose and local tooling load it from here).
2+
# Django also loads this file via backend/setrsoft/settings.py (repo root).
3+
4+
# --- Django ---
5+
# Required in production. Use a long random string.
6+
SECRET_KEY=your-secret-key
7+
8+
# Development: True. Production: False.
9+
DEBUG=True
10+
11+
# Comma-separated hostnames Django may serve (no spaces). Include your domain in production.
12+
ALLOWED_HOSTS=localhost,127.0.0.1
13+
14+
# Set to 1/true/yes when Django sits behind a reverse proxy (Nginx, load balancer) so
15+
# USE_X_FORWARDED_HOST and X-Forwarded-Proto are honored. Typical in production.
16+
TRUST_PROXY=
17+
18+
# --- PostgreSQL (Django DATABASES + Docker "db" service) ---
19+
POSTGRES_DB=setrsoft
20+
POSTGRES_USER=setrsoft
21+
POSTGRES_PASSWORD=changeme
22+
23+
# Host running PostgreSQL: use "localhost" for Django on the host; Docker Compose overrides
24+
# to "db" for the backend container.
25+
POSTGRES_HOST=localhost
26+
POSTGRES_PORT=5432
27+
28+
# --- Frontend (Vite) ---
29+
# Base URL for API requests from the browser. Leave empty when the SPA and API share the
30+
# same origin (e.g. production Nginx serves / and proxies /api/ to Django).
31+
# For local Vite (e.g. :5173) talking to Django on :8000, set e.g. http://localhost:8000
32+
VITE_API_BASE=

‎.github/workflows/ci.yml‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
backend-test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.11'
20+
- name: Install dependencies
21+
run: |
22+
cd backend
23+
python -m pip install --upgrade pip
24+
pip install -r requirements.txt
25+
- name: Run Django Tests
26+
run: |
27+
cd backend
28+
python manage.py test
29+
30+
frontend-test:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v4
34+
- name: Set up Node.js
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version: '20'
38+
- name: Install dependencies
39+
run: |
40+
cd frontend
41+
npm install
42+
- name: Run Linter
43+
run: |
44+
cd frontend
45+
npm run lint
46+
- name: Run Build
47+
run: |
48+
cd frontend
49+
npm run build

‎AGENTS.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# AI Agents Directives
2+
3+
This document provides foundational rules and context for any AI agent interacting with the SetRsoft repository.
4+
5+
## Global Rules
6+
1. **Language:** All code, comments, documentation, and commit messages MUST be written in English. Wait for explicit user override to write in another language.
7+
2. **Context First:** Always review `.context/architecture.md` before making architectural decisions or proposing new libraries.
8+
3. **No Destructive Operations:** Do not delete databases or wipe configuration files without explicit user approval.
9+
10+
## Frontend Development Guidelines
11+
- **Styling:** The application uses Tailwind CSS v4. Do NOT use `tailwind.config.js` for themes; instead, rely on the `@theme` directive in `src/index.css`.
12+
- **Design Charter:** The UI strictly follows the "Stitch" charter ("The Kinetic Monolith"). Use named tokens (`surface-low`, `mint`, `on-surface-variant`). Avoid traditional 1px borders in favor of background color shifts (`bg-surface-high` vs `bg-surface-low`).
13+
- **Translations:** Any user-facing string must use the `useTranslation()` hook from `react-i18next` mapped to the JSON files in `src/locales/`.
14+
15+
## Backend Development Guidelines
16+
- Standard Django conventions apply.
17+
- Ensure database migrations are generated and applied properly if changes are made to models.
18+
- The PostgreSQL database is named `setrsoft` by default.
File renamed without changes.

‎README.md‎

Lines changed: 75 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,88 @@
1-
# React + TypeScript + Vite
1+
# SetRsoft
22

3-
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
3+
[![CI Status](https://github.com/setrsoft/setrsoft_app/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/setrsoft/setrsoft_app/actions/workflows/ci.yml)
4+
[![Discord](https://img.shields.io/badge/Discord-Join-7289da?logo=discord&logoColor=white)](https://discord.gg/BdyfNU9TpR)
45

5-
Currently, two official plugins are available:
6+
## Environment variables
67

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:
99

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`).
1115

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)
1317

14-
## Expanding the ESLint configuration
18+
From the repository root (after `cp .env.example .env`):
19+
20+
```bash
21+
docker compose up
22+
```
1523

16-
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
24+
This starts:
1725

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` |
2531

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.
3233

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
4439
```
4540

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
7356
```
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

‎backend/.env.example‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎backend/Dockerfile‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ COPY requirements.txt .
1010
RUN pip install --no-cache-dir -r requirements.txt
1111

1212
COPY . .
13+
14+
# Collect admin and app static files for WhiteNoise (no DB connection required).
15+
ENV SECRET_KEY=collectstatic-build-placeholder
16+
RUN python manage.py collectstatic --noinput
17+
1318
EXPOSE 8000
1419

1520
CMD ["gunicorn", "setrsoft.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "2"]

‎backend/README.md‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,14 @@ pip install -r requirements.txt
2020

2121
## Environment variables
2222

23-
Copy the example file and set your values:
23+
Use the **repository root** template and file:
2424

2525
```bash
26+
# From the repository root (not inside backend/)
2627
cp .env.example .env
2728
```
2829

29-
| Variable | Description |
30-
|----------|-------------|
31-
| `SECRET_KEY` | Django secret key (required in production). |
32-
| `DEBUG` | Set to `True` for development, `False` in production. |
33-
| `ALLOWED_HOSTS` | Comma-separated list of allowed hosts (e.g. `localhost,127.0.0.1`). |
34-
| `POSTGRES_DB` | PostgreSQL database name. |
35-
| `POSTGRES_USER` | PostgreSQL user. |
36-
| `POSTGRES_PASSWORD` | PostgreSQL password. |
37-
| `POSTGRES_HOST` | PostgreSQL host (`localhost` when running locally, `db` when using Docker). |
38-
| `POSTGRES_PORT` | PostgreSQL port (default `5432`). |
30+
Variable names and descriptions live in **`/.env.example`**. Django loads **`/.env`** via `setrsoft/settings.py` (`REPO_ROOT / '.env'`).
3931

4032
## Database
4133

@@ -57,7 +49,7 @@ The API will be available at `http://localhost:8000/`. Health check: `http://loc
5749

5850
## Docker (optional)
5951

60-
From the repository root, ensure `backend/.env` exists (copy from `backend/.env.example` and set `POSTGRES_HOST=db` for the backend service, or use the defaults which point to the `db` service).
52+
From the repository root, ensure **`.env`** exists (copy from `.env.example`). Docker Compose sets `POSTGRES_HOST=db` inside the backend container; keep `POSTGRES_HOST=localhost` in `.env` for running Django on the host against a local PostgreSQL instance.
6153

6254
Start both the database and the backend:
6355

‎backend/api/tests.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.test import TestCase
2+
3+
class HealthCheckTest(TestCase):
4+
def test_health_endpoint(self):
5+
response = self.client.get('/api/health/')
6+
self.assertEqual(response.status_code, 200)
7+
self.assertEqual(response.json(), {'status': 'ok'})

0 commit comments

Comments
 (0)