Agent skill
pmtl-vn-architecture
architecture and implementation guide for the pmtl_vn stack using next.js 16, nestjs, postgres, caddy, docker compose, and session-based auth. use when creating, extending, reviewing, refactoring, or deploying this monorepo; when adding auth, roles, access control, search, docker/caddy setup, or domain features; and when the agent must preserve the repo's ai-friendly conventions, boundaries, and file placement rules.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/pmtl-vn-architecture
SKILL.md
PMTL_VN Architecture
Overview
Use this skill to keep work aligned with the real PMTL_VN architecture. It is for building new features, reviewing/refactoring code, evolving auth and access control, wiring search, and maintaining Docker/Caddy deployment without breaking monorepo boundaries or file conventions.
Use When
- Creating, extending, or refactoring PMTL features across app boundaries.
- Changing auth, access control, search, deployment, or runtime service ownership.
- Reviewing placement decisions when multiple layers could own the work.
Expected Output
- Code placed in the narrowest correct layer.
- Architecture changes documented in the same task when contracts move.
The current stack assumptions are:
apps/webis Next.js 16 App Routerapps/apiis NestJS backend authority (business logic, auth, OpenAPI)apps/adminis custom admin frontend- PostgreSQL is the primary database (source of truth)
- Phase 1: SQL/API search (tsvector/ILIKE); Phase 2+: Meilisearch
- Caddy terminates SSL and reverse proxies services
- Docker Compose is the operational boundary
- Phase 2+: Valkey, BullMQ workers, outbox_events — only when measured need
Core Rules
Follow these rules on every task:
- Preserve the monorepo split:
apps/web,apps/api,apps/admin,packages/*,infra/*,docs/* - Keep web feature-first
- Keep NestJS modules clean: module + controller + service + dto + entities
- Keep
packages/sharedframework-agnostic: types, enums, zod schemas, constants, validators, mappers, pure utils only - Do not move business logic into Next route/page files or admin configs
- Introduce Valkey, BullMQ, workers only when there is a concrete production need, and document the runtime contract
- In
apps/web, prefer Next.js 16cacheComponentswith"use cache"helper functions over route-levelrevalidateorunstable_cache - In
apps/web, request-boundary logic belongs insrc/proxy.tsfor Next.js 16; do not blindly migrate tomiddleware.ts - Prefer clear, maintainable code over clever abstractions
- When audit documents disagree, treat
AUDIT_VERIFIED_2026.mdas the checked baseline and older audits as hypotheses to validate - Update docs and env examples when architecture, contracts, or runtime requirements change
- If you change project rules or AI-coding conventions, update the corresponding docs and skill files in the same task
Repo Shape
Assume this structure unless the user explicitly changes it:
apps/web: Next.js 16 frontendapps/api: NestJS backend authorityapps/admin: Custom admin frontendpackages/ui: optional shared UIpackages/shared: pure shared domain codepackages/config: shared eslint/typescript/prettier configinfra/docker: compose files and env examplesinfra/caddy: Caddyfile and related filesinfra/scripts: deploy and backup scriptsdocs/architecture: decisions, domains, conventions, deploymentdocs/api: contractsdesign/: architecture design source of truth
Consult references/repo-conventions.md for placement and layering rules.
Task Routing
When working on web
Use apps/web and keep code feature-first.
Typical placement:
- pages/routes/layouts/loading/error/meta in
src/app - feature code in
src/features/<domain> - cross-feature web helpers in
src/lib - shared visual primitives in
src/components
For auth in web:
- prefer
features/auth/* - add route protection in
proxy.tsor the least invasive server-side guard that fits the existing setup - treat
apps/apias the auth authority
When working on api (NestJS)
Use apps/api and keep modules focused and clean.
Per module/domain, prefer:
{module-name}.module.ts: NestJS module declaration{module-name}.controller.ts: route handlers{module-name}.service.ts: business logicdto/: input/output DTOs with Zod validationentities/: Prisma entity typesguards/: route guards if module-specific
Platform modules go in apps/api/src/platform/:
- sessions, audit, feature flags, rate limit, storage, health, metrics
When working on shared domain code
Use packages/shared only for framework-agnostic code:
constantsenumsschemastypesvalidatorsmappers- pure
utils
Do not import Next.js internals, NestJS internals, or runtime-only server utilities here.
When working on infra or deployment
Use:
infra/dockerfor compose files and env examplesinfra/caddyfor reverse proxy and SSL configinfra/scriptsfor deployment and DB backup scripts- GitHub Actions for build/push/deploy automation
Prefer the production model:
- build images locally or in CI
- push to registry
- VPS only pulls and runs containers
Auth Strategy
NestJS (apps/api) is the auth authority using session-based auth with Argon2id password hashing.
Required assumptions:
- auth lives in
apps/api/src/modules/auth/ - web calls API for auth operations
- session strategy uses httpOnly cookies with refresh token rotation
- do not add Auth.js, Better Auth, or a second auth authority unless the user explicitly asks for it
Typical auth scope:
- register
- login
- logout / logout-all
- forgot password
- reset password
- current user / session
- role-based access
- protected routes
- user profile basics
Default roles:
super_adminadminmember
Consult design/01-identity/ for auth and identity design.
Search Strategy
Phase 1 (current): SQL/API search using PostgreSQL tsvector or ILIKE.
Phase 2+: Meilisearch is the preferred search engine when search.meilisearch.enabled feature flag is on.
Keep search concerns separated:
- search service in
apps/api/src/modules/search/ - search UI and query composition in web features
- shared search DTOs or schemas in
packages/shared
Do not expose Meilisearch publicly unless explicitly intended. Prefer internal network access behind API services.
Phase Model
Phase 1
Supported and preferred:
- Next.js 16 web
- NestJS backend authority (
apps/api) - PostgreSQL
- SQL/API search (tsvector/ILIKE)
- Caddy
- Docker Compose dev/prod
- Session-based auth via NestJS
- docs/conventions/contracts maintenance
Phase 2+ (Operational Expansion)
Add when the production runtime benefits clearly justify the added complexity:
- Meilisearch (search.meilisearch.enabled)
- Valkey (cache)
- BullMQ worker service
- outbox_events + dispatcher
- monitoring dashboards
- alerting
- log aggregation
- backup automation beyond simple scripts
Security Baseline
Always preserve these defaults:
- least privilege access control
- guest access only to public content
- protect admin/moderation areas by role
- keep secrets in env, not code
- keep Postgres and Valkey internal-only unless explicitly exposed
- keep Meilisearch internal-only unless explicitly exposed
- use Caddy for TLS termination and reverse proxy
- add limits and guardrails to sensitive routes when implementing auth, comments, abuse reporting, or search
Consult design/baseline/ for security and infrastructure design.
Documentation Duties
When you change behavior or architecture, update docs as part of the same task when appropriate:
README.mdfor run/build/deploy changesdesign/for architecture design changesdocs/architecture/for implementation conventionsdocs/api/for request/response or auth contract changes.env.exampleor env example files for runtime configuration changes
Verification
- Recheck the chosen file placement against
references/repo-conventions.md. - If service boundaries or public/private exposure changed, recheck the relevant security and deployment references.
- Pair with
pmtl-verify-quality-gateafter meaningful implementation changes.
Recommended Working Style
When given a task:
- Read the architecture docs the repo points to first.
- Identify the domain and the correct layer.
- Place new code in the narrowest correct location.
- Keep NestJS modules clean: thin controllers, business logic in services.
- Keep feature code grouped by domain in web.
- Preserve type safety without over-engineering.
- Explain file placement and architectural choices briefly when useful.
- Do not introduce broad refactors unless they are required.
Common Good Decisions
- Put auth UI and fetch helpers under
apps/web/src/features/auth - Put ownership/moderation logic in NestJS services, not only controller guards
- Put DTO validation in
packages/shared/src/schemas - Put search logic in
apps/api/src/modules/search/ - Put deploy and backup logic under
infra/scripts - Put Docker/Caddy changes under
infra/*and document them
Common Bad Decisions
- Mixing framework internals into
packages/shared - Putting all module logic inside a single controller file
- Adding Valkey/BullMQ without a concrete runtime use case or deployment plan
- Adding a second auth system without a clear reason
- Building production images directly on the VPS by default
- Exposing internal services publicly without an explicit need
References
- For repo layout and file placement, read
references/repo-conventions.md - For auth, access, and security defaults, read
references/auth-and-security.md - For Docker, Caddy, deployment, and service boundaries, read
references/deploy-and-ops.md - For architecture design source of truth, read
design/DECISIONS.md
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?