Loading...
Loading...
Here I share what I've learned during my journey as a full-stack developer. This is my space to discuss real-world best practices, design patterns that actually work, project organization and everything I consider essential for writing high-quality code. My goal is to be practical and honest: bring solutions I use every day and that made a difference in my career. If you want to improve your skills and better understand the decisions behind good software development, you're in the right place.
Not every case needs a paid top-tier model. I built a chat assistant for my portfolio using only free models and the result was surprisingly good for real-world use.
For simple, well-bounded tasks — answering questions about known content, generating short text, classifying, extracting data — free models like the 'free' tier on OpenRouter deliver enough quality. The key is restricting scope, not using the model as a generalist black box.
In any AI integration, the most common mistake is exposing the API key in the frontend. In my assistant, the OpenRouter key lives only on the server (environment variable), and the client only talks to my own API route.
This applies to any provider: key on the server + your own proxy = you control cost, limits, logs and what the model is allowed to answer.
The flow is: the browser calls your API, your API validates the request, and only then talks to the AI provider. This way you decide what reaches the model and what comes back to the user.
A simple security layer is to allow requests only from known origins. In my case, I validate the Origin header against a configurable allowlist and, if it is not set (or the origin does not match), the route returns 403.
To keep history and identify users without login, I create an anonymous session via an HttpOnly cookie (SameSite=Lax). The cookie is not accessible to JavaScript, which reduces the risk of exfiltration via XSS.
For stable and predictable responses, I use a low temperature (0.0), a fixed seed for reproducibility, a maximum token limit and a well-defined context.
Instead of pinning a single model, I dynamically fetch the list of free text-enabled models ordered by relevance. When calling, I try each one in sequence: stop at the first that responds; if it fails, move to the next.
This makes the chat resilient to a specific provider being unavailable and removes manual model-list maintenance.
Much of an assistant's 'safety' lies in how you instruct the model. In my system prompt I use clear, verifiable guardrails:
Built by: Aureo Bueno - Full-stack web developer
03/09/2026
CSP (Content Security Policy) is a browser security layer that defines which origins the frontend can use to load scripts, styles, images, fonts, iframes and connections.
It is usually sent via the HTTP Content-Security-Policy header. When the browser receives the page, it applies the rules and blocks everything not allowed by the policy.
Content-Security-Policy: default-src 'self'; base-uri 'self'; script-src 'self'; style-src 'self'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' https://api.seu-dominio.com; frame-ancestors 'none'; object-src 'none'; upgrade-insecure-requests;
In apps with CSS-in-JS or inline scripts, you may need to adjust policy with nonce/hash. Avoid enabling 'unsafe-inline' and 'unsafe-eval' in production whenever possible.
In Next.js, a common approach is defining CSP in next.config.ts with headers().
// next.config.ts
const csp = [
"default-src 'self'",
"script-src 'self'",
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data: https:",
"connect-src 'self' https://api.github.com",
"frame-ancestors 'none'",
"object-src 'none'",
].join('; ');
export default {
async headers() {
return [
{
source: '/(.*)',
headers: [{ key: 'Content-Security-Policy', value: csp }],
},
];
},
};In Vite, the ideal approach is setting headers in the production server (Nginx/CDN). For development, you can add headers in vite.config.ts.
// vite.config.ts
import { defineConfig } from 'vite';
export default defineConfig({
server: {
headers: {
'Content-Security-Policy':
"default-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; connect-src 'self' ws: http: https:;",
},
},
});Note: in dev, HMR often requires ws: and in some cases 'unsafe-eval'. In production, tighten the policy.
In React/Vue/Svelte (SPA), best practice is to configure CSP at the web server, reverse proxy or CDN. Frontend code alone cannot guarantee protection if headers are not sent in the HTTP response.
# exemplo Netlify (_headers) /* Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data: https:;
server {
listen 443 ssl;
server_name app.seu-dominio.com;
root /usr/share/nginx/html;
index index.html;
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' https://api.seu-dominio.com; frame-ancestors 'none'; object-src 'none'; base-uri 'self';" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "DENY" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
location / {
try_files $uri /index.html;
}
}CSP does not replace input validation and sanitization, but it significantly reduces the impact of frontend XSS failures. The biggest gain comes from applying a minimal production policy and evolving it iteratively.
Built by: Aureo Bueno - Full-stack web developer
07/04/2026
All three emerged to solve the same problem: keep business rules protected from frameworks, databases, UI and technical details that change over time.
In practical terms, they apply Dependency Inversion so the domain remains stable and testable while external adapters can be replaced at lower cost.
[Driver Adapter: HTTP/CLI/Test]
|
[Input Port]
|
[Application + Domain]
|
[Output Port]
|
[Driven Adapter: DB/API/Queue/File]At the center is application + domain. Inputs and outputs happen through ports (interfaces). Adapters plug into these ports.

[Frameworks & Drivers]
[Interface Adapters]
[Use Cases]
[Entities]It is modeled in concentric circles. Main rule: dependencies always point inward. The more internal it is, the more stable it should be.

[UI / Infra / DB / Integrations]
[Application Services]
[Domain Services]
[Entities + Value Objects]Also uses concentric rings. The domain stays in the core and everything around depends on it. Infrastructure is the outermost ring.

Hexagonal, Clean and Onion belong to the same architectural family: they differ more in how layers are organized and communicated than in core principles.
When choosing between them, the real gain comes from consistency: clear boundaries, clear contracts and infrastructure isolated from business rules.
Built by: Aureo Bueno - Full-stack web developer
28/03/2026
Scalable architecture for Next.js 15 with App Router
src/ ├── app/ # App Router - Routing principal │ ├── layout.tsx # Layout raiz │ ├── page.tsx # Home page │ ├── (auth)/ # Route group (não afeta URL) │ │ ├── login/page.tsx │ │ └── register/page.tsx │ ├── dashboard/ │ │ ├── layout.tsx │ │ ├── page.tsx │ │ └── [id]/page.tsx # Dynamic routes │ └── api/ # API Routes │ └── users/route.ts ├── components/ │ ├── ui/ # Componentes reutilizáveis │ │ ├── Button/ │ │ │ ├── Button.tsx │ │ │ ├── Button.test.tsx │ │ │ └── index.ts │ │ ├── Card/ │ │ ├── Modal/ │ │ └── index.ts # Barrel exports │ ├── layout/ # Componentes de layout │ │ ├── Header/ │ │ ├── Footer/ │ │ └── Sidebar/ │ └── features/ # Componentes específicos de features │ ├── Auth/ │ └── Dashboard/ ├── lib/ # Lógica complexa e integrações │ ├── db.ts # Database connection │ ├── auth.ts # Auth service │ └── api-client.ts ├── server/ # Server-side logic │ ├── actions/ # Server actions │ │ └── user.actions.ts │ └── services/ │ ├── user.service.ts │ └── email.service.ts ├── hooks/ # Custom React hooks │ ├── useAuth.ts │ ├── useFetch.ts │ └── index.ts ├── utils/ # Utility functions │ ├── formatters.ts │ ├── validators.ts │ └── helpers.ts ├── types/ # TypeScript types │ ├── index.ts │ ├── user.ts │ └── api.ts ├── styles/ # Global styles │ ├── theme.ts # Styled-components theme │ ├── globals.css │ └── variables.css ├── public/ # Static assets │ ├── images/ │ ├── icons/ │ └── fonts/ └── env.example
Contains the entire App Router routing structure. Each folder = one route. Special files: layout.tsx, page.tsx, loading.tsx, error.tsx.
Reusable components (Button, Card, Modal). Can be used by multiple features.
Feature-specific components (Auth, Dashboard). Used only by their own features.
Configuration and complex services (DB, Auth, API client). Reusable across the app.
Server-side logic, Server Actions and backend services. Isolated from client code.
Reusable custom hooks. Encapsulate state and side effects.
Pure utility functions (formatting, validation). No external dependencies.
Centralized TypeScript definitions. Shared interfaces and types.
Use route groups () to organize routes without affecting URLs.
Default to Server Components and use 'use client' only when needed.
Use Server Actions for data mutations (better than API routes in many cases).
Keep lib/ for configuration and server/ for business logic.
Use index files (index.ts) for barrel exports and better structure.
UI components should be context-agnostic.
Centralized TypeScript types reduce duplication.
| Feature | Next.js | React |
|---|---|---|
| Routing | Built-in App Router (file-based) | React Router or TanStack Router |
| Server/Client | Server Components by default | Everything is Client-side by default |
| API | Built-in API Routes | External backend calls |
| Deploy | Vercel or any Node host | Any static web server |
| Best for | Full-stack apps with integrated backend | SPAs, PWAs, frontend-only |
Use path aliases in tsconfig.json: "@/*", "@/features/*", "@/shared/*"
Always export from index.ts to simplify imports. Example: import { Card } from "@/shared/card"
Features should stay independent. Reuse common UI and helpers through shared/.
Enable strict mode in tsconfig.json for maximum type safety
Built by: Aureo Bueno - Full-stack web developer
26/11/2025
Code Review is an essential practice where other developers review the code to ensure quality, avoid mistakes and strengthen maintainability.
Built by: Aureo Bueno - Full-stack web developer
25/11/2025
Higher-Order Components are an advanced pattern that wraps a component to add extra features such as layouts, logging or access control, without modifying the original component. They are a powerful way to reuse logic declaratively while keeping components simple.
function withLog<P>(Component: React.ComponentType<P>) {
return (props: P) => {
useEffect(() => console.log(`Componente ${Component.name} montado`), []);
return <Component {...props} />;
};
}Custom hooks are functions that encapsulate state and effect logic, improving reuse and code organization. For example, a hook that fetches API data handles loading, response and error state, keeping the consuming component cleaner and more focused on UI.
function useFetchData(url: string) {
const [data, setData] = useState(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
useEffect(() => {
setLoading(true);
fetch(url)
.then(res => {
if (!res.ok) throw new Error("Erro na requisição");
return res.json();
})
.then(json => setData(json))
.catch(err => setError(err.message))
.finally(() => setLoading(false))
}, [url]);
return { data, loading, error };
}Compound Components is a pattern for building flexible composed components that share internal state, allowing subcomponents to communicate and provide a declarative, intuitive API for consumers. A common example is a dropdown where the button controls the menu in an encapsulated way.
function Dropdown({ children }) {
const [isOpen, setIsOpen] = useState(false);
const toggle = () => setIsOpen(!isOpen);
return <div>{children({ isOpen, toggle })}</div>;
}
function DropdownButton({ toggle, label }) {
return <button onClick={toggle}>{label} ▼</button>;
}
function DropdownMenu({ isOpen, children }) {
if (!isOpen) return null;
return <ul>{children}</ul>;
}Built by: Aureo Bueno - Full-stack web developer
25/11/2025
MCP (Model Context Protocol) is the protocol an application uses to expose tools, resources, and prompts to a model. An MCP gateway sits in front of several MCP servers and presents them to the client as if they were a single server, with one HTTP endpoint.
To the client the gateway looks like one server; to each real server it acts as an MCP client, keeps the session open, and merges everything into one catalog. Each server name becomes a prefix for its tools (github__create_issue), which avoids collisions between different upstreams.
The code below simplifies the chain of responsibility that runs on every tools/call: authenticate, limit, authorize, ask for approval, call the upstream, and audit the already-redacted result.
async function callTool(request, apiKey) {
const user = await auth.resolve(apiKey);
await rateLimiter.consume(user.id);
const server = registry.byPrefix(request.params.name);
if (!server || !profileAllows(user.profile, request.params.name)) {
throw rpcError(-32003, 'ferramenta indisponível');
}
if (approvalRules.match(request.params.name)) {
await approvals.waitForDecision(user, request);
}
const result = await server.callTool(
removePrefix(request.params.name),
request.params.arguments
);
await audit.record({ user, request, result: redactSecrets(result) });
return redactSecrets(result);
}Built by: Aureo Bueno - Full-stack web developer
17/11/2026
Nginx is a high-performance web server created by Igor Sysoev. It was born to solve the concurrency problem (C10K): instead of one process or thread per request, it uses an asynchronous, event-driven model that can keep thousands of connections with low memory usage.
In practice it is rarely just a file server. It sits at the application entrance doing reverse proxying, load balancing, TLS termination, caching, and API routing. The client talks to Nginx; the real services are behind it.
The simplest lab: a server block listening on port 80 and serving an HTML file from /usr/share/nginx/html. try_files tries the exact file, then the directory, and only then returns 404.
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
}Here Nginx is the single entry point: /api/users/ goes to one service and /api/orders/ to another. The client does not know, and does not need to know, where each service lives.
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html;
}
location /api/users/ {
proxy_pass http://service-users/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /api/orders/ {
proxy_pass http://service-orders/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}The most confusing detail is the trailing slash in proxy_pass: with the slash, the /api/users prefix is removed; without it, the full path is forwarded.
proxy_pass http://service-users/; # /api/users/profile -> /profile proxy_pass http://service-users; # /api/users/profile -> /api/users/profile
The same pair of backends is used in every strategy in the lab. The choice only changes the directive inside the upstream block — the rest of the configuration stays the same.
upstream backend_servers {
server backend-1:80;
server backend-2:80;
}
upstream least_conn_servers {
least_conn;
server backend-1:80;
server backend-2:80;
}
upstream sticky_by_ip {
ip_hash;
server backend-1:80;
server backend-2:80;
}
upstream cache_affinity {
hash $uri consistent;
server backend-1:80;
server backend-2:80;
}Built by: Aureo Bueno - Full-stack web developer
17/11/2026
Instead of storing only the current row of a table, the event store stores the facts that changed that state: AccountCreated, PointsEarned, PointsSpent. They are immutable events, written in order and never edited.
Today's state is the result of replaying, or folding, that sequence from the beginning. An event usually carries the aggregate id, version, timestamp, and data about what happened, always written in the past tense.
Think of a balance aggregate. There is no row saying balance equals 70. There are two facts: PointsEarned 100 and PointsSpent 30. Replaying the sequence brings the read model to 70. Changing the projection rule does not erase history — just rebuild it.
Event sourcing does not require a specific product. The event store is the source of truth; the broker only distributes the facts. In a monolith it can be an in-memory bus; in separate services, a queue or topic such as Kafka, RabbitMQ, Redis Streams, or NATS. What matters is the contract: reliable publishing, idempotent consumers, and ordering when the domain requires it.
Writing to the event store and publishing to the broker are two different systems. Doing both in sequence opens the dual write window: the event is saved, publishing fails, and nobody notices. The outbox solves this by writing the event and the publishing record in the same transaction; a separate relay publishes it later and marks it as sent.
This repository applies these concepts to a teams-and-matches domain: aggregates, event store, projections, outbox, and idempotent consumers. The code is worth a look to see the model running end to end.
View futsal-api on GitHubBuilt by: Aureo Bueno - Full-stack web developer
17/11/2026