Skip to content

Commit d9a9850

Browse files
authored
Merge pull request #5 from emanuellcs/cloud-to-local
feat: migrate to on-premises LAN with robust CI/CD pipeline
2 parents d560205 + a8ae790 commit d9a9850

22 files changed

Lines changed: 6048 additions & 5556 deletions

.env.example

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
VITE_PUBLIC_SUPABASE_URL=your_supabase_url
2-
VITE_PUBLIC_SUPABASE_PUBLISHABLE_KEY=your_supabase_publishable_key
1+
# Base URL for accessing Supabase services from the LAN
2+
VITE_PUBLIC_SUPABASE_URL=http://<SERVER_LAN_IP>:8000
3+
# Anon/Public key obtained after self-hosted setup
4+
VITE_PUBLIC_SUPABASE_PUBLISHABLE_KEY=your_local_anon_key

.eslintrc.cjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
root: true,
3+
env: { browser: true, es2020: true },
4+
extends: [
5+
'eslint:recommended',
6+
'plugin:@typescript-eslint/recommended',
7+
'plugin:react-hooks/recommended',
8+
],
9+
ignorePatterns: ['dist', '.eslintrc.cjs'],
10+
parser: '@typescript-eslint/parser',
11+
plugins: ['react-refresh'],
12+
rules: {
13+
'react-refresh/only-export-components': 'off',
14+
'react-hooks/exhaustive-deps': 'off',
15+
'@typescript-eslint/no-explicit-any': 'off',
16+
'no-unused-vars': 'off',
17+
'@typescript-eslint/no-unused-vars': [
18+
'warn',
19+
{
20+
argsIgnorePattern: '^_',
21+
varsIgnorePattern: '^_',
22+
caughtErrorsIgnorePattern: '^_',
23+
},
24+
],
25+
},
26+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build-and-test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout Repository
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 20
23+
24+
- name: Setup pnpm
25+
uses: pnpm/action-setup@v4
26+
with:
27+
version: 10
28+
29+
- name: Install dependencies
30+
run: pnpm install --frozen-lockfile
31+
32+
- name: Type Check
33+
run: pnpm tsc --noEmit
34+
35+
- name: Lint
36+
run: pnpm lint
37+
38+
- name: Unit Tests
39+
run: pnpm test
40+
41+
- name: Dry Run Docker Build (Infrastructure Test)
42+
run: docker build -t segecs-frontend:test .

.github/workflows/keep-supabase-alive.yml

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

Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Stage 1: Build
2+
FROM node:20-alpine AS builder
3+
4+
# Install pnpm
5+
RUN corepack enable && corepack prepare pnpm@latest --activate
6+
7+
WORKDIR /app
8+
9+
# Copy lockfile and package.json
10+
COPY pnpm-lock.yaml package.json ./
11+
12+
# Install dependencies
13+
RUN pnpm install --frozen-lockfile
14+
15+
# Copy source
16+
COPY . .
17+
18+
# Build arguments for environment variables
19+
ARG VITE_PUBLIC_SUPABASE_URL
20+
ARG VITE_PUBLIC_SUPABASE_PUBLISHABLE_KEY
21+
22+
# Set environment variables for build
23+
ENV VITE_PUBLIC_SUPABASE_URL=$VITE_PUBLIC_SUPABASE_URL
24+
ENV VITE_PUBLIC_SUPABASE_PUBLISHABLE_KEY=$VITE_PUBLIC_SUPABASE_PUBLISHABLE_KEY
25+
26+
# Build the application
27+
RUN pnpm build
28+
29+
# Stage 2: Serve
30+
FROM nginx:alpine
31+
32+
# Copy custom nginx configuration
33+
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
34+
35+
# Copy build output from builder stage
36+
COPY --from=builder /app/dist /usr/share/nginx/html
37+
38+
EXPOSE 80
39+
40+
CMD ["nginx", "-g", "daemon off;"]

README.md

Lines changed: 77 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,111 +4,120 @@
44

55
**SEGECS** is a high-performance academic governance solution, specifically designed to centralize, automate, and monitor the complete lifecycle of the Supervised Curricular Internship. The platform acts as an intelligent bridge between educational institutions, partner companies, and students, eliminating manual bureaucracies and ensuring full compliance with **Brazilian Law No. 11,788/2008**.
66

7-
Unlike generic systems, SEGECS offers a **multi-training** architecture, allowing coordinators to simultaneously manage various technical and professional courses (such as Nursing, Administration, Networking, Building Construction, among others). Each course has its own workload and competency settings, allowing the institution to scale its internship operations without losing individualized control over each contract.
7+
## 🏛️ System Architecture (On-Premises / Local LAN)
88

9-
With a modern, data-driven interface, the system transforms pedagogical monitoring, previously scattered across papers and spreadsheets, into real-time strategic indicators, providing legal security through automated document generation and technical integrity through rigorous data protection policies.
10-
11-
## 🏛️ System Architecture
12-
13-
SEGECS uses a modern architecture based on **SPA (Single Page Application)** with a **Serverless** infrastructure, ensuring scalability, security, and high performance.
9+
This version of SEGECS is optimized for **100% on-premises deployment**, designed to function flawlessly in localized LAN environments with zero external internet connectivity.
1410

1511
### 🏗️ Tech Stack
1612

1713
- **Frontend:** [React 18](https://react.dev/) with [Vite](https://vitejs.dev/) and [TypeScript](https://www.typescriptlang.org/).
18-
- **Styling:** [TailwindCSS](https://tailwindcss.com/) and [Framer Motion](https://www.framer.com/motion/) for fluid animations.
19-
- **Backend-as-a-Service:** [Supabase](https://supabase.com/) (PostgreSQL, Auth, RLS, and Realtime).
20-
- **State Management:** [React Query (TanStack)](https://tanstack.com/query/latest) for caching and data synchronization.
21-
- **Forms:** [React Hook Form](https://react-hook-form.com/) integrated with [Zod](https://zod.dev/) for rigorous validation.
22-
- **Documentation:** [@react-pdf/renderer](https://react-pdf.org/) for dynamic PDF generation on the client side.
23-
- **Localization:** [i18next](https://www.i18next.com/) for multi-language support (Portuguese and English).
24-
25-
### 🛡️ Security Layer
26-
27-
- **Supabase Auth:** Secure authentication with configurable session persistence ("Remember me").
28-
- **Row Level Security (RLS):** Access policies directly in the database ensuring students see only their data, while coordinators access the management view.
29-
- **Snapshot Logic:** Workloads are copied to contracts at the time of creation, protecting historical records against future changes in the curriculum.
14+
- **Styling:** [TailwindCSS](https://tailwindcss.com/) and [Framer Motion](https://www.framer.com/motion/).
15+
- **Database & Backend:** Self-hosted [Supabase](https://supabase.com/docs/guides/self-hosting) (PostgreSQL, Auth, PostgREST, and Realtime) running in Docker.
16+
- **Containerization:** [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/).
17+
- **Web Server:** [Nginx](https://nginx.org/) (Alpine-based) serving the frontend SPA.
3018

3119
## 🚀 Key Features
3220

33-
### 📋 Administrative Management (Multi-Course)
34-
35-
- **Customizable Courses:** Registration of any training with specific mandatory workload definition.
36-
- **Partner Management:** Control of companies with monitoring of agreement validity.
37-
- **Talent Bank:** Detailed registration of students, advisors, and field supervisors.
38-
39-
### ⚙️ Allocation and Vacancy Flow
40-
41-
- **Vacancy Management:** Publication and control of opportunities by course and company.
42-
- **Intelligent Allocation:** Automatic link between student, vacancy, advisor, and supervisor.
43-
- **Auto-fill:** The system detects the course workload and suggests contract terms instantly.
44-
45-
### 📈 Monitoring and Control (Compliance)
21+
- **Administrative Management:** Multi-course support with customizable technical training definitions.
22+
- **Allocation & Vacancy Flow:** Intelligent link between students, companies, advisors, and supervisors.
23+
- **Compliance Monitoring:** Frequency logs, technical visits, and pedagogical evaluations.
24+
- **Automatic Documentation:** Instant generation of TCE (Commitment Term), Activity Plans, and TRE (Realization Term) as PDFs.
25+
- **Data Resilience:** Automated local database backups and persistent Docker volumes.
4626

47-
- **Frequency Log:** Daily entry of activities with time validation.
48-
- **Technical Visits:** Full module for recording in-person or remote monitoring.
49-
- **Pedagogical Evaluations:** Grading and feedback system by period.
50-
- **Intelligence Dashboard:** Distribution charts, expiring contract alerts, and evaluation pending items.
51-
52-
### 🎓 Automatic Documentation (PDF)
53-
54-
- **TCE (Commitment Term):** Instant generation according to current legislation.
55-
- **Activity Plan:** Detailing technical competencies in development.
56-
- **TRE (Realization Term):** Final completion document with workload summary.
57-
- **SICE Export:** Preparation of structured CSV data for the SEDUC-CE system.
58-
59-
## 🚦 Getting Started
27+
## 🚦 Getting Started (Development)
6028

6129
### 📋 Prerequisites
6230

6331
- **Node.js** (v18+)
64-
- **npm** or **pnpm**
65-
- **Supabase** Instance
32+
- **pnpm** (preferred)
33+
- **Docker & Docker Compose**
6634

67-
### ⚙️ Installation and Configuration
35+
### ⚙️ Development Setup
6836

6937
1. **Clone and Install:**
7038

7139
```bash
7240
git clone https://github.com/prof-raimundo/segecs.git
7341
cd segecs
74-
npm install
42+
pnpm install
7543
```
7644

77-
2. **Configure Environment Variables:**
78-
Create a `.env` file in the root:
45+
2. **Configure Environment:**
46+
Create a `.env` file based on `.env.example`:
7947

8048
```env
81-
VITE_PUBLIC_SUPABASE_URL=your_supabase_url
82-
VITE_PUBLIC_SUPABASE_PUBLISHABLE_KEY=your_anon_key
49+
VITE_PUBLIC_SUPABASE_URL=http://localhost:8000
50+
VITE_PUBLIC_SUPABASE_PUBLISHABLE_KEY=your_local_anon_key
8351
```
8452

85-
3. **Configure Database:**
86-
- Run the script in `database/supabase_schema.sql` in the Supabase SQL editor.
87-
- (Optional) Run `database/seed.sql` to populate the system with test data (70 users, 15 visits, frequencies, etc.).
88-
89-
4. **Run:**
53+
3. **Run Dev Server:**
9054
```bash
91-
npm run dev
55+
pnpm dev
9256
```
9357

58+
---
59+
60+
## 📦 On-Premises Deployment (Production)
61+
62+
To deploy SEGECS on a local server for LAN access, follow these steps:
63+
64+
### 1. Initialize Supabase Self-Hosted Stack
65+
66+
Run the automated setup script to fetch and configure the official Supabase Docker repository:
67+
68+
```bash
69+
chmod +x scripts/setup_supabase.sh
70+
./scripts/setup_supabase.sh
71+
```
72+
73+
**Configuration steps inside `supabase-project/`:**
74+
75+
- Run `sh ./utils/generate-keys.sh` to secure your JWT and API keys.
76+
- Edit `supabase-project/.env` and update `SITE_URL`, `SUPABASE_PUBLIC_URL`, and `API_EXTERNAL_URL` with your **Server's LAN IP** (e.g., `http://192.168.1.100:8000`).
77+
- Change default passwords for `POSTGRES_PASSWORD` and `DASHBOARD_PASSWORD`.
78+
- Start the backend: `docker compose up -d`.
79+
80+
### 2. Deploy Frontend Container
81+
82+
Configure your local `.env` with the same LAN IP and the `ANON_KEY` generated in the previous step, then build and start the frontend:
83+
84+
```bash
85+
# Update .env with your LAN IP
86+
docker compose up -d --build
87+
```
88+
89+
The application will be accessible to all devices on the LAN at `http://<SERVER_LAN_IP>`.
90+
91+
### 3. Database Resilience (Backups)
92+
93+
A backup script is provided in `scripts/backup_db.sh`. It is recommended to schedule this via `cron` on the host machine:
94+
95+
```bash
96+
# Example: Daily backup at 2 AM
97+
0 2 * * * /path/to/segecs/scripts/backup_db.sh
98+
```
99+
94100
## 📂 Folder Structure
95101

96102
```text
97-
src/
98-
├── app/ # Global configurations, routes, and providers
99-
├── components/ # Reusable UI components (Pagination, Loading, etc.)
100-
├── features/ # Business modules (students, internships, visits, etc.)
101-
│ └── [feature]/ # Specific components, pages, and services
102-
├── hooks/ # Custom hooks (usePagination, useAuth, useSupabaseCrud)
103-
├── i18n/ # Localization configuration and translation files
104-
├── lib/ # Library configurations (supabase client, utils)
105-
└── types/ # TypeScript type definitions and database types
103+
segecs/
104+
├── database/ # SQL schema and seed files
105+
├── nginx/ # Nginx production configuration
106+
├── scripts/ # Setup and backup automation scripts
107+
├── src/
108+
│ ├── app/ # Global configurations and routes
109+
│ ├── components/ # Reusable UI components
110+
│ ├── features/ # Business modules (students, internships, etc.)
111+
│ ├── hooks/ # Custom React hooks
112+
│ └── lib/ # Supabase client and utilities
113+
├── Dockerfile # Multi-stage production build
114+
└── docker-compose.yml # Frontend orchestration
106115
```
107116

108117
## 📄 License
109118

110119
Distributed under the MIT License. See `LICENSE` for more information.
111120

112121
<p align="center">
113-
Developed with ❤️ to transform technical education.
122+
Developed with ❤️ to transform technical education in localized environments.
114123
</p>

deploy-production.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# ==============================================================================
5+
# SEGECS - School On-Premises Deployment Script
6+
# ==============================================================================
7+
# WARNING: This script should ONLY be executed after the GitHub Action (CI Pipeline)
8+
# turns green, validating the types, linting, tests, and the docker build.
9+
#
10+
# This script simulates the IT administrator's job on the local server.
11+
# It pulls the latest code, safely tears down the old container, rebuilds,
12+
# and restarts the frontend attached to the local Supabase network.
13+
# ==============================================================================
14+
15+
echo "Starting Deployment Process..."
16+
17+
# 1. Pull the latest code from the main branch
18+
echo "[1/4] Pulling latest code from main branch..."
19+
git fetch origin main
20+
git checkout main
21+
git pull origin main
22+
23+
# 2. Tear down the old frontend container safely
24+
echo "[2/4] Tearing down the old frontend container..."
25+
docker compose stop frontend || true
26+
docker compose rm -f frontend || true
27+
28+
# 3. Rebuild the Docker container using the latest code
29+
echo "[3/4] Rebuilding the frontend Docker image..."
30+
# We assume the .env file is already present on the server with VITE_PUBLIC_SUPABASE_URL
31+
docker compose build frontend
32+
33+
# 4. Restart the container attached to the Supabase network
34+
echo "[4/4] Starting the newly built frontend container..."
35+
docker compose up -d frontend
36+
37+
# Note: Database migrations for Supabase are handled by the Supabase CLI.
38+
# If migrations exist, they can be run via:
39+
# supabase db push --db-url "postgresql://postgres:[PASSWORD]@localhost:5432/postgres"
40+
# Or through Supavisor on port 6543 if exposed.
41+
# For now, it's skipped unless explicitly configured.
42+
43+
echo "Deployment complete! The application is now running."

docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
services:
2+
frontend:
3+
build:
4+
context: .
5+
args:
6+
VITE_PUBLIC_SUPABASE_URL: ${VITE_PUBLIC_SUPABASE_URL}
7+
VITE_PUBLIC_SUPABASE_PUBLISHABLE_KEY: ${VITE_PUBLIC_SUPABASE_PUBLISHABLE_KEY}
8+
image: segecs-frontend:latest
9+
ports:
10+
- "80:80"
11+
restart: always
12+
networks:
13+
- supabase-network
14+
15+
networks:
16+
supabase-network:
17+
external: true
18+
name: supabase-project_default

0 commit comments

Comments
 (0)